Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Anyone interested in readng Domino's sculptie source code with me?

Raz Welles
Registered User
Join date: 18 Jun 2007
Posts: 49
05-06-2009 12:28
Up until now I've used the code blindly, but I began to get curious, and started looking under the hood. Currently I'm reading render_sculptie.py and trying to figure out what makes it tick.

Some parts have got me completely stumped :P and I don't want to bother Domino with too much typing until his carpel tunnel subsides. Plus, it might not be a bad idea for more people to understand the code to be able to detect bugs or add features.

So I'm proposing a small study network, feel free to contact me inworld, PM, or reply here if you're interested in checking out what makes one of the hottest sculptie renderers tick ^^
Gaia Clary
mesh weaver
Join date: 30 May 2007
Posts: 884
05-06-2009 12:46
i got a fair idea of what happens in the code, although some parts still puzzle me a lot. But i have done some documentation in the RC-4 scripts. Maybe that can help for better understanding ? Otherwise, how exactly would you want to "read the code together with others ?" I am curious ;-)
Raz Welles
Registered User
Join date: 18 Jun 2007
Posts: 49
05-06-2009 13:08
The heart of the rendering script, as I understand it, is in drawTri(), drawHLine(), and drawVLine(). I have to admit, I looked in those functions and although I can follow it a little, I'm still lost. For example, I have no idea what the following code does:

From: someone
n = verts[0] + (( verts[2] - verts[0] ) * (( verts[1].x - verts[0].x ) / ( verts[2].x - verts[0].x )))

http://www.machinimatrix.org/svn/sl/trunk/blender/dominodesign/rc/render_sculptie.py

It looks like it has to do with a triangle, but I'm not familiar with the formula, even after I write it out:
From: someone

...............................( V2.x - V1.x )
V1 + (( V3 - V1 )[ --------------------- ])
...............................( V3.x - V1.x )


I think we could take the RC scripts and start documenting and commenting things. So there would be the clean trunk, and then the heavily commented and documented code. When I began coding, I learned an important commenting philosophy early on, that is, to document why I do a line of code as opposed to just saying what that line does. Personally, I could use an essay on how the drawTri function works line for line :P I'd also like to know how the vertex grid is generated when importing a sculpt.
Domino Marama
Domino Designs
Join date: 22 Sep 2006
Posts: 1,126
05-06-2009 13:39
From: Raz Welles
For example, I have no idea what the following code does:

n = verts[0] + (( verts[2] - verts[0] ) * (( verts[1].x - verts[0].x ) / ( verts[2].x - verts[0].x )))


What this code does is find the point where you draw a line through a triangle to split it into two grid aligned ones. It's hard to explain without pictures.. Draw a load of triangles on gridded paper to represent the UV map :)

Imagine all the variations of triangles that could be on the UV map, right angled or not, rotated or aligned with grid etc. This is part of the code that splits each triangle into grid aligned segments. This lets the segments be converted into two lines (the third edge implicit in the grid alignment) so that by either converging or expanding the start and end points on each subsequent line, the triangle can be drawn. So eventually you get a pixel range and a starting pixel and ending pixel in the other direction for each end of the range.

http://www.geocities.com/wronski12/3d_tutor/tri_fillers.html might help :)
Raz Welles
Registered User
Join date: 18 Jun 2007
Posts: 49
05-06-2009 14:17
Domino to the rescue XD!

I gridded out and crunched some numbers, but I think I'll look through that link you gave me first, thanks >_>;

So are all those if statements preceding that statement just to make sure that no verts are directly on top of each other, causing the equation to break?

http://pastebin.com/f663e38d9 Lines 318-228
Domino Marama
Domino Designs
Join date: 22 Sep 2006
Posts: 1,126
05-06-2009 14:22
From: Raz Welles
So are all those if statements preceding that statement just to make sure that no verts are directly on top of each other, causing the equation to break?


They catch the easy ones where the triangle is already grid aligned so doesn't need splitting into two.
Raz Welles
Registered User
Join date: 18 Jun 2007
Posts: 49
05-06-2009 14:48
Ahh, thanks so much! I was completely stuck and had no idea how to proceed.. I finally have some footing now. I hope more people get interested in reading this code. :)
Raz Welles
Registered User
Join date: 18 Jun 2007
Posts: 49
05-08-2009 20:01
168-171: I'm not quite sure I understand the purpose of the -0.5. Any hints? ^^;

From: someone

f.verts[ vi ].co = Blender.Mathutils.Vector(( p[0] - 0.5), (p[1] - 0.5), (p[2] - 0.5))


http://pastebin.com/f534dedc1
Domino Marama
Domino Designs
Join date: 22 Sep 2006
Posts: 1,126
05-09-2009 01:39
From: Raz Welles
168-171: I'm not quite sure I understand the purpose of the -0.5. Any hints? ^^;

http://pastebin.com/f534dedc1


It converts the float colour (0.0 o 1.0, 0.0 to 1.0, 0.0 to 1.0) to sculptie co-ords (-0.5 to 0.5, -0.5 to 0.5, -0.5 to 0.5 )
Raz Welles
Registered User
Join date: 18 Jun 2007
Posts: 49
05-09-2009 02:17
Ooh, now it makes sense, thanks! :D
Poenald Palen
Registered User
Join date: 30 May 2008
Posts: 35
05-09-2009 18:59
OH, cool. The commenting will help people to figure out blender plugins. It is surprising how many people get into 3D, scripting/programming after they start making things in SL I bet! I can't help at all as I don't know much math for 3D or python. Just a bump and a hope to be able to maybe learn something from this code.