Snapping to mesh vertices in Software Implementation pdf417 2d barcode in Software Snapping to mesh vertices

Snapping to mesh vertices generate, create pdf417 none in software projects GTIN-13 [ 129 ]. Pydrivers and Constraints The way around this obs Software PDF 417 tacle is the idprop argument that is passed to doConstraint(). Before doConstraint() is called, Blender first calls doTarget() for each target object. This function is passed as a reference to the target object and to the properties of the constraint.

This allows us to insert a reference to the target object in these properties and because these properties are passed to doConstraint(), this provides us with a means to pass the necessary information to doConstraint() to get at the Mesh data. There is a minor point to consider here though: Blender properties can only be numbers or strings so we cannot actually store a reference to an object but have to settle for its name. Because a name is unique and Blender"s Object.

Get() provides a way to retrieve an object by name, this is not a problem. The code for doConstraint() and doTarget() will look like this (the full code is provided as

def doConstraint(obmatr ix, targetmatrices, idprop): obloc = obmatrix.translationPart().resize3D() obrot = obmatrix.

toEuler() obsca = obmatrix.scalePart() # get the target mesh to = Blender.Object.

Get(idprop["target_object"]) me = to.getData(mesh=1) # get the location of the target object tloc = targetmatrices[0].translationPart().

resize3D() # find the nearest vertex in the target object smallest = 1000000.0 delta_ob=tloc-obloc for v in me.verts: d = (v.

co+delta_ob).length if d < smallest: smallest=d sv=v obloc = + tloc # reconstruct the object matrix mtxrot = obrot.

toMatrix().resize4x4() mtxloc = Mathutils.TranslationMatrix(obloc) mtxsca = Mathutils.

Matrix([obsca[0],0,0,0], [0,obsca[1],0,0], [0,0,obsca[2],0], [0,0,0,1]) outputmatrix = mtxsca * mtxrot * mtxloc return outputmatrix def doTarget(target_object, subtarget_bone, target_matrix, id_properties_of_constraint): id_properties_of_constraint["target_object"] return target_matrix [ 130 ]. 4 . The highlighted lines s how how we pass the name of the target object to doConstraint(). In doConstraint() we first retrieve the target mesh. This may throw an exception, for example, if the target object is not a mesh, but this will be caught by Blender itself.

The constraint will not be affected then and an error is shown on the console, but Blender will proceed happily. Once we have the mesh data of the target object we retrieve the object location of the target object. We need this because all vertex coordinates are relative to this.

Next we compare the location of the constrained object to all the vertex locations of the target mesh and remember the closest one to calculate the object location of the constrained object. Finally, we reconstruct the transformation matrix of the constrained object by combining various transformation components as before..

Aligning along a vertex normal Now that we can constra in an object to the closest vertex on a target mesh we can see that something is missing: the object is not oriented in a meaningful way. This might not always be a problem, for example, trees will normally point upward, but in many situations it would be nice if we could orient the constrained object perpendicular to the surface. This is the same for all practical purposes, as orienting the constrained object along the vertex normal of the vertex it has been snapped to.

Therefore, after finding the closest vertex we determine the angle between the vertex normal and the z-axis (that is, we arbitrarily define the z direction as "up") and then rotate the constrained object by the same amount around the axis perpendicular to both the vertex normal and the z-axis. This will orient the constrained object along that vertex normal. If the constrained object was rotated manually before adding the constraint these previous rotations would be lost.

If that is not what we want, we can apply any rotations permanently before adding the constraint. To implement this alignment feature, our code will change ( contains these changes already): doConstraint() will have to calculate the rotation part of the transformation matrix.

We have to calculate the rotation angle, the rotation axis, and then the new rotation matrix. The highlighted part of the following code shows that the essential tools for these calculations are already provided by the Mathutils module:. vnormal = if idpr PDF-417 2d barcode for None op["NormalAlign"] : zunit=Mathutils.Vector(0,0,1) a=Mathutils.

AngleBetweenVecs(vnormal,zunit) rotaxis=zunit.cross(vnormal) rotmatrix=Mathutils.RotationMatrix(a,4,"r",rotaxis) mtxrot = rotmatrix else: mtxrot = obrot.

toMatrix().resize4x4() [ 131 ].
Copyright © . All rights reserved.