I was able to get 3d wireframe file import from Blender working!
http://scratch.mit.edu/projects/AddZero/347789
http://scratch.mit.edu/projects/AddZero/347252
Here's how.
1. Create a wireframe object in Blender. I'll just use the default cube for this tutorial.
(to preview the wireframe Press "Z".)
a. Select the object if it's not already. (right mouse click)
b. Delete all faces from the object. "Tab" to go to edit mode, hit "a" until all vertices are yelow/selected. Hit the "Delete" key and click "Only Face". Exit edit mode with "Tab".
2. Export as a "Wavefront (.obj) file. (Click File -> Export) and save it somewhere where you can find it later, like in your Scratch projects folder. I saved mine as "cube.obj", and use the default settings.
Here's what the file looks like:
# Blender3D v245 OBJ File: <memory> # www.blender3d.org mtllib cube.mtl o Cube v 1.000000 -1.000000 -1.000000 v 1.000000 -1.000000 1.000000 v -1.000000 -1.000000 1.000000 v -1.000000 -1.000000 -1.000000 v 1.000000 1.000000 -1.000000 v 0.999999 1.000000 1.000001 v -1.000000 1.000000 1.000000 v -1.000000 1.000000 -1.000000 f 1 2 f 1 4 f 1 5 f 2 3 f 2 6 f 3 4 f 3 7 f 4 8 f 5 6 f 5 8 f 6 7 f 7 8
(If we didn't remove the faces the f's would have 3 or 4 numbers defining faces. my setup Scratch can't handle that. It would be slower, I'm just interested in the lines for now.)
3. Split obj file into two text files. One for vertices. One for lines. All of the numbers need to be on their own line.
vertices.txt
1.000000 -1.000000 -1.000000 1.000000 -1.000000 1.000000 -1.000000 -1.000000 1.000000 -1.000000 -1.000000 -1.000000 1.000000 1.000000 -1.000000 0.999999 1.000000 1.000001 -1.000000 1.000000 1.000000 -1.000000 1.000000 -1.000000
lines.txt
1 2 1 4 1 5 2 3 2 6 3 4 3 7 4 8 5 6 5 8 6 7 7 8
I used a couple linux command lines to do it:
cat cube.obj |grep 'v '|sed -e 's/v //g'|sed -e 's/ /\n/g' >vertex-list.txt cat cube.obj |grep 'f '|sed -e 's/f //g'|sed -e 's/ /\n/g' >lines-list.txt
You could probably do the same with a windows command line. or in a text editor. (Please share if you figure out another way to do this.) See Paddle2See's python version
Here's what it's doing.
Open cube.obj
Remove all the lines except for ones that have 'v '
Search for 'v ' and replace with nothing.
Search for spaces ' ' and replace with returns.
Save it to vertex-list.txt
Open cube.obj
Remove all the lines except for ones that have 'f '
Search for 'f ' and replace with nothing.
Search for spaces ' ' and replace with returns.
Save it to line-list.txt
4. Open "3d wireframe suzanne" in Scratch.
5. Replace the 'vertices' and 'lines' with the two files we just made.
a. Go to variables and click the check boxes next to the 'lines' and 'verticies' lists.
b. change the "delete 1 of ___" box on the left to say. "delete all of lines" and double click to clear the list.
c. Right click the 'vertices' box that poped up on the stage and find/select import and choose 'vertex-list.txt'
d. go up to 'b.' and do the same for 'lines'
6. Done!
How this works.
for every pair of number in the lines list, it grabs the respective x y z variables and draws a line using 3d projection. (This tutorial helped me.)
It rotates the vertices according to the CamRotX and CamRotY.
I reused parts of my Lathe 3d modeler - Light Bulb
Taking this farther:
I've wanted to make a 3d modeler in Scratch for some time. Now that we have lists, it can be much more powerful.
- Separate into objects with material settings, so that lines can be different colors. (using the .mtl files.)
- Allow dynamic creating/removing/editing of objects in Scratch.
This is now possible using a tree data structure for lists! http://scratch.mit.edu/projects/AddZero/346118
- Allow different types of objects. Mesh, (like above) and procedural: Lathe, Extrude, Primitives: cube, cone, cylinder, sphere...
Paddle2see suggested using a line removal routine. That would be cool!
And Wow, that's a tricky problem:
I think data would probably have to be stored as polygons,
Perhaps z-buffer scanline or ray tracing?
or somehow trim the lines to the z-buffer rendered?
or determine occlusion by comparing the intersecting polygons somehow.
Polygons would probably have to be saved to a buffer and sorted first.
I think this would be very slow.
But if we're going to do this, might as well make a full scanline or ray tracer too.
Feel free to use these ideas/remix etc...
Let me know if I need to clarify this.
Last edited by AddZero (2008-12-17 14:04:45)
Offline
Wonderful! Python could probably do the pre-processing of the input files pretty easily, for people that don't have access to the Linux text utilities. If I get some time in the next couple of days, I'll try and make a Python parser.
I was kinda joking about the hidden line routine...but i'm sure it's possible, if you're willing to wait long enough!
Offline
The tutorials on that site actually have a full section on backface culling (with ActionScript code).
http://www.kirupa.com/developer/actionscript/backface_culling.htm
Last edited by S65 (2008-12-14 20:00:50)
Offline
Paddle2See, Thanks!
Yeah, A python parser would be cool.
S65, Good point. That would keep the the backs of objects from being rendered, if data was stored in faces. Right now I just have lines stored. That would be something to try.
Last edited by AddZero (2008-12-15 14:16:31)
Offline
nvm i just made a cuuuuuuuuuuuuuuuuuuuube its really cooooooooool
do you think thers a way to speed it up so its like realtime? there is.
I wonder if you can insert JavaScript into your post, like
<HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- function cow(textstring){ alert(textstring)} --> </SCRIPT> </HEAD> <BODY> <FORM> <INPUT NAME="mouse" TYPE="Text"> <INPUT NAME="view" TYPE="Button" VALUE="View text in an alert message?" onClick="MsgBox(form.mouse.value)"> </FORM> </BODY> </HTML>
meh.
this makes a little text box,(cute innit) and a button. its self explanatory.
i dunno
this topic helped a lot
Last edited by cds56 (2008-12-15 16:07:11)
Offline
cds56: You made it work? cool!
This won't be realtime unless it's very simple objects.
Or you render the 3d file into a set of images, put them in a sprite, and change costumes as needed.
It would be a good idea, to have the .obj to scratch list converter as javascript (or php, python...) on a website so that it would be very easy to convert files for this. but we can't run javascript here. I may do that on my server.
Last edited by AddZero (2008-12-15 21:05:36)
Offline
@pip: make what work? real-time? the actual thing work? or...
could you help me with blender, i cant do anything on it. except follow addzero's instuctions.
@addzero: lol you spelt run wrong =P
Im in the process of making my own web server, but my router wont let it get past the firewall, even with everything in that port(or whatever its called) disabled.
i will be posting a new set of wire frame models... i think. the first will b a cube
Offline
What?
Never mind.
Blender really I have no way to teach you about it, because I do not have a place to tell you on the web. I can tell you it takes YEARS to learn.
I have been working on it for about a year 1/2, and still do not know how to use it extremely well. I do know the basics but every once in a while I'll think, Hmm... How Odd. Sooo... The only advice I can give you is read/watch online tutorials, and keep trying. Maybe sometime I can find some way to make a website to put tutorials on. I wonder.
Last edited by pip (2008-12-16 11:53:30)
Offline
As promised, here is a script in Python that will parse vertex and line files from your blender files. I'm a bit of a newbie in Python so don't make fun of it...there's probably a way to do it in two lines, if you know what you're doing. But, it should work and that's what counts. Adjust the file paths to fit your environment.
# Define file paths Infile = "c:\users\owner\desktop\Blender Data File.txt" Outfile1 ="c:\users\owner\desktop\Vertices.txt" Outfile2 ="c:\users\owner\desktop\Lines.txt" # Open files vertices = open(Outfile1,'w') lines = open(Outfile2,'w') inp = open(Infile,'r') # Process the input file, one line at a time for input_line in inp: field = input_line.split() # Split line into fields on whitespace if field[0].startswith('v'): # Lines that start with "v" vertices.write(field[1]+'\r\n') # Adding Return and Newline chars vertices.write(field[2]+'\r\n') vertices.write(field[3]+'\r\n') if field[0].startswith('f'): # Lines that start with "f" lines.write(field[1]+'\r\n') lines.write(field[2]+'\r\n') # Close all the files vertices.close() lines.close() inp.close()
Offline
Hi AddZero,
what version of blender do you use and where did you download it?
Btw: i have no ide how to use teh python code? (the only programming code i can is scratch^^)
Offline
This should work on any version of Blender from within the last few years. It's available from http://blender.org
you can get python from here: http://www.python.org/download/
Pick the windows installer.
It still may be a little tricky getting Paddle2See's code to work.
but it will work something like this.
Select and copy his code text to the clipboard. (edit, copy)
go into the notepad text editor (start, programs, accessories, notepad) (or even better, use python's text editor if it has one in windows.)
paste the text,
change the paths to point to places on your computer.
save as converter.py on your desktop,
close the text editor
doubleclick converter.py on your desktop
Paddle2See, would that work?
Offline
AddZero wrote:
This should work on any version of Blender from within the last few years. It's available from http://blender.org
you can get python from here: http://www.python.org/download/
Pick the windows installer.
It still may be a little tricky getting Paddle2See's code to work.
but it will work something like this.
Select and copy his code text to the clipboard. (edit, copy)
go into the notepad text editor (start, programs, accessories, notepad) (or even better, use python's text editor if it has one in windows.)
paste the text,
change the paths to point to places on your computer.
save as converter.py on your desktop,
close the text editor
doubleclick converter.py on your desktop
Paddle2See, would that work?
That would probably work...however I would recommend using IDLE to create and run the file as you could then read any error messages, get context help and all that good stuff. IDLE is the integrated development environment that comes free with Python. So, you would start up IDLE, then go to File-New Window which will open up a new input file window. You would then cut and paste my script into it, adjust the file paths as needed, and then use the Run option to run it.
Offline
hmm..I'll try it but I can't seem to get things like speak to work...
anyways, where is the project that can be remixed to utalize this?
Offline
right here http://scratch.mit.edu/projects/AddZero/347252 a 3d wireframe monkey.
I tried to make a sphere, but it turned out i forgot to delete the shading and stuff so it was still a 3d shaded circle
Offline
Offline
I mode a mod to the rotations controlls, after that I tried to export a cube from blender then use those umbers, it didn't work right. I looked again at your code and realized that I didn't input the right nubers in the lines list, so I copied your lines and vertecies...It still didn't work. It came out as a line extending to infinity...or as far I I could see......
Offline
Paddle2See wrote:
As promised, here is a script in Python that will parse vertex and line files from your blender files. I'm a bit of a newbie in Python so don't make fun of it...there's probably a way to do it in two lines, if you know what you're doing. But, it should work and that's what counts. Adjust the file paths to fit your environment.
Code:
# Define file paths Infile = "c:\users\owner\desktop\Blender Data File.txt" Outfile1 ="c:\users\owner\desktop\Vertices.txt" Outfile2 ="c:\users\owner\desktop\Lines.txt" # Open files vertices = open(Outfile1,'w') lines = open(Outfile2,'w') inp = open(Infile,'r') # Process the input file, one line at a time for input_line in inp: field = input_line.split() # Split line into fields on whitespace if field[0].startswith('v'): # Lines that start with "v" vertices.write(field[1]+'\r\n') # Adding Return and Newline chars vertices.write(field[2]+'\r\n') vertices.write(field[3]+'\r\n') if field[0].startswith('f'): # Lines that start with "f" lines.write(field[1]+'\r\n') lines.write(field[2]+'\r\n') # Close all the files vertices.close() lines.close() inp.close()
an good ideas where I can get a tutorial to use nodes and things like this in blender? thx
Offline
AddZero wrote:
Paddle2See, Thanks!
Yeah, A python parser would be cool.
S65, Good point. That would keep the the backs of objects from being rendered, if data was stored in faces. Right now I just have lines stored. That would be something to try.
you could probably also make one in MS office word or exell.
Offline
I cannot get mine to work is remix of wireframe suzzane but with luger help?
wireframe luger
Offline
Cool, I'm glad you're trying this out.
Strange, the scratch file wouldn't open in scratch for me. "bad header"
Could you post 10 or so lines from both lists that you imported into scratch?
Let's compare yours to mine.
Perhaps your lists are not in the right format. That's really easy to get wrong.
one lists is the x,y,z location of all the points in the object.
0 (point 1 x)
0 (point 1 y)
0 (point 1 z)
1 (point 2 x)
-1 (point 2 y)
1 (point 2 z)
1 (point 1 x)
2 (point 1 y)
2 (point 1 z)
Every three lines of text here make make the location of one point, the x,y,z location. so that list says there's three points at these locations: 0,0,0 and 1,-1,1 and 1,2,2
For the lines list, every 2 lines of text make a line:
1 (line 1 start)
2 (line 1 end)
2 (line 2 start)
3 (line 2 end)
3 (line 3 start)
1 (line 3 end)
It says to draw a line from 'point 1' (0,0,0) to 'point 2' (1,-1,1)
The second line is from the 'point 2' to 'point 3'
The third line is two draw from 'point 3' to 'point 1'
Or maybe your object is too small. I could probably tell you if you paste parts of your lists. Good luck!
Offline