Why not just use Object.ray_cast <https://www.blender.org/api/blender_python_api_2_77a_release/bpy.types.Object.html?highlight=ray_cast#bpy.types.Object.ray_cast> or Scene.ray_cast <https://www.blender.org/api/blender_python_api_2_77a_release/bpy.types.Scene.html?highlight=ray_cast#bpy.types.Scene.ray_cast> ?
On Sat, Aug 20, 2016 at 10:20 AM, Bastien Montagne <[email protected]> wrote: > Hi Todd, > > You should rather use <your_mesh_object>.to_mesh() [1], use that temp > mesh to get what you want, and the remove() it from data.meshes. > Obviously, if you call your func several time at the same frame, cache the > temp mesh, no need to re-create it every time. > > Incidentally, you never remove your temp empty object in your code, which > is bad, since you keep adding one on every call... ;) > > Cheers, > Bastien > > [1] > *https://www.blender.org/api/blender_python_api_2_77_0/bpy.types.Object.html#bpy.types.Object.to_mesh > <https://www.blender.org/api/blender_python_api_2_77_0/bpy.types.Object.html#bpy.types.Object.to_mesh>* > Le 20/08/2016 à 08:36, Todd McIntosh a écrit : > > 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 > [email protected]https://lists.blender.org/mailman/listinfo/bf-python > > > > _______________________________________________ > Bf-python mailing list > [email protected] > https://lists.blender.org/mailman/listinfo/bf-python > >
_______________________________________________ Bf-python mailing list [email protected] https://lists.blender.org/mailman/listinfo/bf-python
