Hi everyone,

Quick question. I've put together a little function to find the matrix_world Z location of a point on a displaced mesh (plane with ocean mod) given the X and Y coordinates. I'm using an empty with a shrinkwrap modifier to achieve this.

I was wondering if there is a faster or more direct way in python to do this.

Here's what I have so far.

*****************************************

import bpy

def getZLocation(xLoc, yLoc, targetMeshName):
    o = bpy.ops.object
    d = bpy.data.objects
    targetMesh = d[targetMeshName]
    o.add(type='EMPTY', location=(xLoc, yLoc, 0))
    empOb = bpy.context.active_object
    empOb.name = 'empLocate'
    o.constraint_add(type='SHRINKWRAP')
    empOb.constraints['Shrinkwrap'].shrinkwrap_type='NEAREST_SURFACE'
    empOb.constraints['Shrinkwrap'].target = targetMesh
    o.select_all(action='DESELECT')
    return empOb.matrix_world.to_translation()[2]

print(getZLocation(xLoc=2.2, yLoc=4.1, targetMeshName='Ocean'))

*****************************************


Also, it seems to take a few seconds to actually compute this value, so something faster would also be great.



Thanks,


Todd McIntosh
Resonance Media + Design
Phone: +1 (905) 471-5048
Email: [email protected]
Skype: toddmcintosh
<http://www.getpostbox.com>
_______________________________________________
Bf-python mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-python

Reply via email to