plane = video texture of camera 2 and also is distorted using kd tree to find points in radius
Camera 2 =aimed at main scene
when ‘Exposion’ happens in main scene, get screen position, use screen position to get screen vect in main camera, use to cast rays at plane, to use kd tree to put points on effect list, as well as set position.
Points are added to list [‘FX’] and is used with property ‘Run’ to run the script until all vertex are back to normal position.
I am afk at the moment but I think scaling the plane to -1 on z will be a quick fix,
I will try and write it to do both later, and maybe a ripple wave,
edit: negative scale on screen +flip normals seems good. (have not checked to make sure orientations are correct) I will try and get to tinkering tonight*
for mesh in object.meshes:
diff = ray.hitPoint-own.worldPosition
localpoint = own.worldOrientation.inverted()*diff
selectList =[]
for m_index in range(len(mesh.materials)):
for v_index in range(mesh.getVertexArrayLength(m_index)):
vertex = mesh.getVertex(m_index, v_index)
diffVect = vertex.XYZ-localpoint
distance = diffVect.magnitude
if distance < radius:
selectList.append([vertex,v_index])
this is much slower than calling the kdtree that you build on frame zero, and then checking using that
(itterating using C, and also using an algorithm that does not traverse the whole point list*)
so it’s much faster, the more data there is to sort through that pertains to 3d space.
you can use a ‘worldKDTRee’ for LOD and physics LOD and Lamp LOD etc.
so long as the points are static that you are operating on (no need to rebalance the tree*)
in this example I build the tree with
#build kd tree
if 'KD' not in own:
own['FX']=[]
VLIST =[]
for mesh in own.meshes:
for m_index in range(len(mesh.materials)):
for v_index in range(mesh.getVertexArrayLength(m_index)):
vertex = mesh.getVertex(m_index, v_index)
VLIST.append([vertex,vertex.XYZ])
size = len(VLIST)
kd = mathutils.kdtree.KDTree(size)
index =0
for Vert in VLIST:
kd.insert(VLIST[index][1], index)
index+=1
kd.balance()
own['KD']=kd
own['VLIST']=VLIST
later any object can call that tree with target[‘KD’]
(so a vector can than be used with all these commands to access the data)
@BluePrintRandom
That’s very good use of the kdtree with the texture module, thanks
btw since you already know the object only have 1 mesh and 1 material you can extract the vertex faster by avoiding expensive function calls or attribute look up from inside the nested loops and better yet the loops
eg.
mesh = own.meshes[0]
mat_index = 0
vert_len = mesh.getVertexArrayLength(mat_index)
VLIST = [mesh.getVertex(mat_index, v_index) for v_index in range(vert_len)]