geometry/architecture/plant

hi, dear blender friends!
i would like to ask you to help me with follow problem:

  1. imagine there is a triangle put in space, with normal pointing upward and there is a light also.
  2. in next step/frame choose the most lit face/triangle and make 4th point which lies on this face’s normal, so these 4 points contruct a tetrahedron. so now we have 4 triangles/faces. the light can be animated.
  3. repeat the 2nd step
    so, why blender? because it is very tight bound with python which is wonderful language and i need little coding here (and 3d), i think. so my question is: how do i find out how much is certain face lit? it would be great to consider radiosity too (some sort of texture baking?) but it is not necessary. and of course i’ll be very thankful for any idea (on workflow, concept, …).
    ok, any help is appreciate or thanks anyway.
    have a nice day
    peter

did an evil gremlin remove the middle of your post?

please try to explain it again.

(attempting from what I understand)
radiosity is stored in vertex colors, they are accesable via the object’s mesh
standard lighting is per pixel, not stored in the object, and if you feel like it you can approximate it, look up the math of a phong shader, vertex normals, and the material settings in blender. (no fun)

if that is what you want, why?

first thank you for so fast answer…
simply, i want geometry/faces/whatever to grow according to amount of light.
some sort of lindermayer’s context-based system, you know trees/fractal geometry that grow according to some conditions.
and this with radiosity… i only wanted to use radiosity because it is more accurate.
so i need to know from python how much is certain face lit so i can controll next growth.
hope this time i didn’t confuse you.
and sorry about this double posting i am new here and if it’s bad practice i’ll not make it anymore.

I don’t know if double posting between forums is a bad idea, it was just odd seeing your post again, later in the day, somewhere else, and without my reply.

if you wish you can approximate lighting using I guess the dot product of the vertex normal and the unit vector from the vertex to the lamp.

the value will be 1 if the normal is pointing directly at the lamp, 0 if orthagonal to the vector to the lamp, and -1 if pointing directly away from the lamp. Technically the value would be the cos of the angle formed

but what if one face is hidden behind other faces? the normal can point towards light but the face should not be lit. but you said that i can do it in similar way (vertex colors) with radiosity, could you be more specific please? maybe small pseudocode or vey simple python script will help me.

i thought like this: on frame N i will compute the light of whole scene (with build-in radiosity for accurate result, or with build-in raytracing for shadows, or?), then i find out how much are the faces lit, then i choose e.g. the most lit, move to frame N+1, grow little bit the whole thing by adding some faces from this most lit face, compute the light conditions, etc…
i do not want to code e.g. radiosity solver once again, as it is in blender. just use blender’s possibilities.

well, thank you for you help and time…

peter

I am just going to post an export script of mine, it exports triangles and vertex colors

# export.py
# website (currently) http://www.geocities.com/z3r0_d/
# my e-mail is avaliable on my website
#
# description
# export .. into my! format
#
# to run:
# select object you wish to run this script on (it will only run
# on the active object), and in the script window containing this script
# press [alt] + [p]
#
# if the script window turns red, and errors are printed on the console
# the script was unable to find a proper order
#
# for more information (such as why it may not find a proper order)
# look at my website mentioned above
#
############# LEGAL STUFF #############
# This script is provided with NO WARRANTY for fitness towards any particular
# purpose.  It MIGHT be helpful, but I am not responsible if it isn't,
# nor if it causes harm to your system
#
# If you distribute changes to this script do not remove my copyright notice
# and please note the chages you made
# ... it would also be nice if you told me, because I would like to know.  
#
# one more thing:
# DO NOT port this script to another platform/program/language without my permission
# which can be obtained by e-mail

import Blender
from Blender.NMesh import *
from math import sqrt

def vec_dot(u, v):
	return u[0]*v[0] + u[1]*v[1] + u[2]*v[2]
def vec_cross(u, v):
	#	|	i	j	k	|
	#	|	u0	u1	u2	|
	#	|	v0	v1	v2	|
	# (u1*v2-u2*v1)i - (u0*v2-u2*v0)j + (u0*v1-u1*v0)k
	# (u1*v2-u2*v1)i + (u2*v0-u0*v2)j + (u0*v1-u1*v0)k
	return [u[1]*v[2]-u[2]*v[1], u[2]*v[0]-u[0]*v[2], u[0]*v[1]-u[1]*v[0]]
def vec_mag(u):
	return sqrt(u[0]*u[0] + u[1]*u[1] + u[2]*u[2])
def vec_norm(u):
	n = vec_mag(u)
	return [u[0]/n, u[1]/n, u[2]/n]
def vec_between_points(u, v):
	# returns the vector from point u to point v
	return [v[0]-u[0], v[1]-u[1], v[2]-u[2]]
def colToList(col):
	# return a list containing the rgb color of NMColType col
	return [col.r, col.g, col.b]
def vecToList(vec):
	# converts a VectorType to a list
	return [vec[0], vec[1], vec[2]]
def textWinRed():
	from Blender.BGL import *
	Blender.Redraw()
	glClearColor(1.0, 0.0, 0.0, 1.0)
	glClear(GL_COLOR_BUFFER_BIT)
	Blender.Redraw()

print "

--------------The Script has Begun--------------"

selectedObjs = Blender.Object.GetSelected()
if (len(selectedObjs)==0):
	print "I NEED ONE SELECTED MESH!"
thisMesh = Blender.NMesh.GetRawFromObject(selectedObjs[0].name)

print "Object",selectedObjs[0].name
print "Mesh",thisMesh.name
print "Object Contains ",len(thisMesh.faces)," Faces"

print "opening file",thisMesh.name+".trx", "for writing"
f = open(Blender.Get('filename')+'/../objects/'+	thisMesh.name+".trx", 'w')

# the format is:
# name, value
# some things may have more than one value

f.write("numfaces "+str(len(thisMesh.faces))+"
")

# for each face
i = 0
numFaces = len(thisMesh.faces)
while i < numFaces:
	#print "face number", i
	print "*"*(79*i/numFaces)+"\r",
	aFace = thisMesh.faces[i]
	if len(aFace.v)==3:
		#f.write("FLAGS" + aFace.
		norm = vec_norm(vec_cross(vec_between_points(aFace.v[0], aFace.v[1]), vec_between_points(aFace.v[1], aFace.v[2])))
		# are the faces oriented the same way as the vertex normal?
		if (vec_dot(norm, aFace.v[0].no)<0.0):
			# the normal is (likely) opposite the direction the 
			# orientation of the faces would suggest
			print "BAADDD!", i
			# flip the normal
			#norm = [-norm[0],-norm[1], -norm[2]]
			# ...? it works without it?
		f.write("NORM " + str(norm) + "
" )
		j = 0
		while j < 3:
			f.write("COLOR " + str(colToList(aFace.col[j])) + "
" )
			f.write("COORD " + str(vecToList(aFace.v[j].co))+ "
" )
			j+=1
		pass
	else:
		print "A face has not 3 verticies
quitting..."
		textWinRed()
		break
	i+=1
f.write("
")
f.close()
print "
--------------The Script has Finished--------------"

the important part is aFace.v[j].co which is the color of that vertex
aFace came from an NMesh, and v[j] is a vertex

radiosity stores it’s colors in vertex colors, so this script can export the radiosity result (once you convert to triangles, I was too lazy to make it flexible). I also am too lazy to give you just the code you need

wow, thank you! sorry i didn’t reply i was busy… i have (hopefully) last question. i have an animation i.e. on every frame i add some faces. so i need to update the radiosity solution, right? but how? and it have to be from python because there are ~1000 frames and i can’t do it by hand.
or is there different solution? please.

I don’t think updating the radiosity solution would be as easy as using usual spot lights (with shadows) in combination with a static radiosity solution.

(but a couple of months have passed, you may have figured that out)