tcepsa: (I'll fix it!)
[personal profile] tcepsa
It turns out that Blender works pretty well as a 3D Graphing utility ~grin~

Date: 2008-02-11 09:19 pm (UTC)

Date: 2008-02-11 10:41 pm (UTC)
From: [identity profile] tcepsa.livejournal.com
Hmm, given Blender's obtuseness, I'll issue a blanket "Ping me on any of this for more details on how to get there if you don't already know how to" statement ^_^ That having been said...

I may have slightly overstated my case. There's a lot of stuff missing (like a legend, or really a scale, or anything like that) that could probably be added but it would likely be a fairly significant effort. The built in grid lines worked well enough for me as a scale, but that's because I was the one who wrote the program. In other words, it was great as quick and dirty solution to visualize something in a way that let me twirl it around and get a good look at it quickly from whatever direction I wanted. However, I'd say that what I've done with it so far currently falls into the realm of "quick hack" versus "elegant solution" ~grin~

I was doing some number crunching that relied on two independent variables and produced one dependent variable, so I wanted to create a 3D graph and see how it all looked together. Blender has a Python scripting interface that, with a little bit of studying, made it really easy to create a basic mesh and add the data points as vertices. Most of the studying was learning the details of Python's syntax; if you're not already familiar with object-oriented programming it'll be a sharper learning curve, but I seem to recall you saying elsewhere that you were also learning Python. If so you've got good odds of picking this up quickly.

Blender has as one of its default Scenes a screen laid out for scripting (about half the view is 3D view, the other half is a text editor), so you can see the results of running a script pretty much instantaneously. You import the Blender library (or whatever they're called in Python) and it exposes a bunch (if not all) of Blender's functionality to you programmatically. Then it's a pretty straightforward matter to create a mesh object, create and add vertex objects to it (with the coordinates that you want your graph to display), and then have Blender render it. Things get a little trickier if you want it to actually connect the dots, since you have to manually create the faces by saying "okay, give me a new face object, now add these vertices to it, now add it to the faces array of the mesh" (at least, that's the way I learned; there may be more elegant/quick ways to do it...). It was tricky because I was dealing with an essentially linear dataset. I had done the number crunching and stored the results in three columns of a database table, so it took a little bit of twiddling to tell it which points were supposed to be part of a given face. I ended up doing a double-query ("pick all of the distinct x values and loop through them, now pick all of the y values and results for each x value, and when you add those vertices to the mesh, also store a reference to them in the appropriate row and column 2D array.") And then some array index mojo ("Once you've gotten all the vertices populated, loop through the array (except the last column and row) and add the current vertex, the vertex in the next column in this row, the vertex in the next column and the next row, and the vertex in this column in the next row to a new face and then add that face to the mesh.")

Given that the my last reply was so wordy...

Date: 2008-02-11 10:56 pm (UTC)
From: [identity profile] tcepsa.livejournal.com
And because I'm feeling show-offy (look what my rendering program can do!) Here's a way to create a basic plane in Blender.

Go to the scripting window (use Ctrl-right two or three times until you get to a layout where the right half of the screen is a text editor. Or pick it from the dropdown menu at the top of the screen--I'm pretty sure it's the Scene menu.)

Edit the name in the field at the bottom of the text (should read something like "Tx: Text"). Change it to yourScriptNameGoesHere.py, as that'll be the name that it saves it as.

Alt-S is the save quick-key for the script.
Alt-P will run it.

Type (or paste) the following code into the script window:
import Blender
from Blender import NMesh

# Create new, raw mesh
myMesh = NMesh.GetRaw()

# Create vertices and add them to the mesh
vertices = []
vertices.append( NMesh.Vert(1.0, 1.0, 0.0) )
myMesh.verts.append( vertices[0] )

vertices.append( NMesh.Vert(1.0, -1.0, 0.0) )
myMesh.verts.append( vertices[1] )

vertices.append( NMesh.Vert(-1.0, -1.0, 0.0) )
myMesh.verts.append( vertices[2] )

vertices.append( NMesh.Vert(-1.0, 1.0, 0.0) )
myMesh.verts.append( vertices[3] )

# Create new face and add vertices to it
f = NMesh.Face()
for vertex in vertices:
   f.v.append(vertex)

# Add face to mesh
myMesh.faces.append(f)

# Add mesh to Blender scene, name it "plane", and recalculate normals
Blender.PutRaw(myMesh, "plane", 1)

# Make sure it gets drawn
Blender.Redraw()

(I haven't actually tested that specific chunk of code, so if it doesn't work it could very well be because of a typo on my part... Have fun! ^_^)

Profile

tcepsa: (Default)
tcepsa

April 2015

S M T W T F S
   12 34
567891011
12131415161718
19202122232425
2627282930  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 31st, 2026 05:28 pm
Powered by Dreamwidth Studios