During the past days, I have been working on an extension to integrate my stl2png script in mediawiki. I found very little documentation and comments in their source code. It looks like the only documentation they have is how end-users should use it, but nothing for developers. Every function has about two lines of documentation on what it actually does. A little longer description would have been useful. Because of the lack of documentation, it was hard to use their classes and I had to find some workarounds and hacks to make my code work, as an extension is not allowed to change their files. I just made my script change the $_FILES and $_POST arrays. I know that's not smart to do, but its the only way I managed to tell the wiki it should use an other file as source, and not the uploaded zip.
The extension works, but is still in alpha version. The form for uploading the zip still needs work, and the newly uploaded files don't receive a description for some unknown reason. I have temporarily placed a demo of the extension on my pc at home. You can find it on http://tman.webhop.net:8765/wiki. This won't stay there forever and my pc isn't always online, so its very possible that it won't be accessible. Hopefully it will be used on the reprap-wiki by then. The source code can be found on http://www.reprap.org/wiki/File:Upload3D.zip
I'll stop working on this for a while now. With the demo online, it should give people a clear idea of what is possible with mediawiki. Even with the bad documentation, I still managed to make this in a few days. I hope they won't exchange the wiki for an other type of documentation-system. There is a reason that wikipedia is so big, so it would be stupid to change to an other system if you ask me.
Showing posts with label upload button. Show all posts
Showing posts with label upload button. Show all posts
Tuesday, September 14, 2010
Friday, September 10, 2010
A big upload button
As the delivery of the hardware has been delayed, I decided to search for something else that I could do. I found a page on the wiki mentioning that there was a need for a big upload button. After asking, it seemed that they might drop the whole wiki, so maybe the button wouldn't be needed. I don't really understand why they would replace the wiki with something else, as a wiki keeps a history of both documentation and files, so it sounds like a stupid idea to replace it with something else to me.
Anyway, even if they do change the method of keeping the information, it will still require something similar to the upload button. For that reason I decided to make a script in php that would take a zip as input and give stl-files and the matching renders as png-files. I won't create something to integrate everything in mediawiki yet, until I know for sure that they will keep using it.
First of all, I had to re-install a linux os on one of my pcs. I downloaded kubuntu server edition, set up a lamp server in VMWare and added phpmyadmin on the server. The easyest part was already done. Now I had to install povray and stl2pov. I had no problems installing povray, as it was in multiverse of ubuntu (here).
The problems started happening when I had to build stl2pov myself. It seemed I needed gcc, so I installed that one and uncommented the line in the makefile to make it use gcc. The installation instructions now said that everything should work when I used the make command. But it just gave me an ugly error:
Makefile:9: *** missing separator. Stop.
As that line was an include command, I just opened version.inc, copied everything in there and pasted that over the include command. So the first error was solved.
There was still a second error however. The program didn't recognize .if !defined(NOPORTDOCS), I thought "this is a new installation, I bet it won't be defined for me" and removed the if-test. The compilation did work now. Once that was done, "sudo make install" installed everything just as expected.
Now that the software was installed, I searched for how to run it. Stl2pov was very straightforward and didn't need any parameters or settings files. It just converted the file. I was happy it didn't cause me more troubles. Povray however did require settings and parameters. The parameters were well documented on their site and I quickly found that -i is for the input file, -o is for the output file, +W is for the width of the image and +H for the height. I added 2 more options to the command: +GA for giving all errors in the terminal and -D for not showing the picture while rendering. So that makes the whole command for rendering an image:
povray -i\"render.pov\" +W600 +H600 -o\"$output\" +GA -D
Now I needed to find how to add settings to tell the program how to render the objects. After looking a little around the internet, I tried some different settings and these seemed to work. I found a basic script on a site, but didn't save the url. Sorry, if it yours let me know and I'll add a link to give you credit. I changed the colors, rotation, light source and camera location a little, but didn't touch the things I didn't know what they were for like the global settings or sky sphere. It works and that's good enough for me.
The file requires an include-file that describes the object that has to be drawn. It expects the object to be called MODELNAME. So in my script I had to replace the name stl2pov was giving it. A few simple lines of code later, my php script could rename the model. As the rendering is the most intensive part of the script, I didn't think about efficiency while replacing the name and just wrote something that is quick to code instead of quick to execute. My script was now able to render any given stl-file into a png. I uploaded it to the wiki.
After dinner I still had some free time and quickly added the extra feature of unzipping the contents of a given zip, looking for stl-files and matching png-images and rendering them if they were not found. That was basically just extracting files, looping over them and deleting unnecessary files, so I won't go into detail about that.
You can now find the script I just created in the wiki as stl2png. I added a few lines of comments in there, but really not that much. If anything isn't clear about how it works, feel free to ask me.
Anyway, even if they do change the method of keeping the information, it will still require something similar to the upload button. For that reason I decided to make a script in php that would take a zip as input and give stl-files and the matching renders as png-files. I won't create something to integrate everything in mediawiki yet, until I know for sure that they will keep using it.
First of all, I had to re-install a linux os on one of my pcs. I downloaded kubuntu server edition, set up a lamp server in VMWare and added phpmyadmin on the server. The easyest part was already done. Now I had to install povray and stl2pov. I had no problems installing povray, as it was in multiverse of ubuntu (here).
The problems started happening when I had to build stl2pov myself. It seemed I needed gcc, so I installed that one and uncommented the line in the makefile to make it use gcc. The installation instructions now said that everything should work when I used the make command. But it just gave me an ugly error:
Makefile:9: *** missing separator. Stop.
As that line was an include command, I just opened version.inc, copied everything in there and pasted that over the include command. So the first error was solved.
There was still a second error however. The program didn't recognize .if !defined(NOPORTDOCS), I thought "this is a new installation, I bet it won't be defined for me" and removed the if-test. The compilation did work now. Once that was done, "sudo make install" installed everything just as expected.
Now that the software was installed, I searched for how to run it. Stl2pov was very straightforward and didn't need any parameters or settings files. It just converted the file. I was happy it didn't cause me more troubles. Povray however did require settings and parameters. The parameters were well documented on their site and I quickly found that -i is for the input file, -o is for the output file, +W is for the width of the image and +H for the height. I added 2 more options to the command: +GA for giving all errors in the terminal and -D for not showing the picture while rendering. So that makes the whole command for rendering an image:
povray -i\"render.pov\" +W600 +H600 -o\"$output\" +GA -D
Now I needed to find how to add settings to tell the program how to render the objects. After looking a little around the internet, I tried some different settings and these seemed to work. I found a basic script on a site, but didn't save the url. Sorry, if it yours let me know and I'll add a link to give you credit. I changed the colors, rotation, light source and camera location a little, but didn't touch the things I didn't know what they were for like the global settings or sky sphere. It works and that's good enough for me.
The file requires an include-file that describes the object that has to be drawn. It expects the object to be called MODELNAME. So in my script I had to replace the name stl2pov was giving it. A few simple lines of code later, my php script could rename the model. As the rendering is the most intensive part of the script, I didn't think about efficiency while replacing the name and just wrote something that is quick to code instead of quick to execute. My script was now able to render any given stl-file into a png. I uploaded it to the wiki.
After dinner I still had some free time and quickly added the extra feature of unzipping the contents of a given zip, looking for stl-files and matching png-images and rendering them if they were not found. That was basically just extracting files, looping over them and deleting unnecessary files, so I won't go into detail about that.
You can now find the script I just created in the wiki as stl2png. I added a few lines of comments in there, but really not that much. If anything isn't clear about how it works, feel free to ask me.
Labels:
php,
rendering,
upload button
Subscribe to:
Posts (Atom)