[Bf-python] Find Z location on surface of displaced mesh

Todd McIntosh todd at resonancemedia.ca
Sat Aug 20 08:36:15 CEST 2016


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: todd at resonancemedia.ca
Skype: toddmcintosh
<http://www.getpostbox.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20160820/2a1a0b86/attachment.html>


More information about the Bf-python mailing list