def setArrow(self, direction: Vector): self.flipArrow() # No need to rotate an arrow if the rotator is disabled if not self._rotator.isEnabled(): return # Rotate the arrow to the desired direction angle = angleBetweenVectors(self.activeArrow.direction, direction) # Check to make sure we will rotate the arrow corectly axes_angle = angleBetweenVectors( self._rotator.rotation_axis, direction.cross(self.activeArrow.direction)) angle = -angle if abs(axes_angle) < 1.e-3 else angle self.rotateArrow(angle)
def __imul__(self, other): if type(other) is Quaternion: v1 = Vector(other.x, other.y, other.z) v2 = Vector(self.x, self.y, self.z) w = other.w * self.w - v1.dot(v2) v = v2 * other.w + v1 * self.w + v2.cross(v1) self._data[0] = v.x self._data[1] = v.y self._data[2] = v.z self._data[3] = w elif type(other) is float or type(other) is int: self._data *= other else: raise NotImplementedError() return self
def _alignToolsToCenterAxis(self, position: Vector, axis: Vector, angle: float): matrix = Quaternion.fromAngleAxis(angle, axis) self.inactiveArrow.setEnabled(True) self.activeArrow.rotate(matrix, SceneNode.TransformSpace.Parent) self.inactiveArrow.rotate(matrix, SceneNode.TransformSpace.Parent) self._rotator.rotate(matrix, SceneNode.TransformSpace.Parent) self.activeArrow.direction = matrix.rotate(self.activeArrow.direction) self.inactiveArrow.direction = matrix.rotate( self.inactiveArrow.direction) if axis.cross(self._rotator.rotation_axis).length() > 1.e-3: self._rotator.rotation_axis = matrix.rotate( self._rotator.rotation_axis) else: self._rotator.rotation_axis = axis self.activeArrow.setPosition(position) self.inactiveArrow.setPosition(position) self._rotator.setPosition(position) self.inactiveArrow.setEnabled(False)
def _createCustom(self, size, maxs, pos1 , pos2, dep, ztop): mesh = MeshBuilder() # Init point Pt1 = Vector(pos1.x,pos1.z,pos1.y) Pt2 = Vector(pos2.x,pos2.z,pos2.y) V_Dir = Pt2 - Pt1 # Calcul vecteur s = size / 2 sm = maxs / 2 l_a = pos1.y s_infa=math.tan(math.radians(dep))*l_a+s l_b = pos2.y s_infb=math.tan(math.radians(dep))*l_b+s if sm>s and dep!=0: l_max_a=(sm-s) / math.tan(math.radians(dep)) l_max_b=(sm-s) / math.tan(math.radians(dep)) else : l_max_a=l_a l_max_b=l_b Vtop = Vector(0,0,ztop) VZ = Vector(0,0,s) VZa = Vector(0,0,-l_a) VZb = Vector(0,0,-l_b) Norm=Vector.cross(V_Dir,VZ).normalized() Dec = Vector(Norm.x*s,Norm.y*s,Norm.z*s) if l_max_a<l_a and l_max_b<l_b and l_max_a>0 and l_max_b>0: nbv=40 Deca = Vector(Norm.x*sm,Norm.y*sm,Norm.z*sm) Decb = Vector(Norm.x*sm,Norm.y*sm,Norm.z*sm) VZam = Vector(0,0,-l_max_a) VZbm = Vector(0,0,-l_max_b) # X Z Y P_1t = Vtop+Dec P_2t = Vtop-Dec P_3t = V_Dir+Vtop+Dec P_4t = V_Dir+Vtop-Dec P_1m = VZam+Deca P_2m = VZam-Deca P_3m = VZbm+V_Dir+Decb P_4m = VZbm+V_Dir-Decb P_1i = VZa+Deca P_2i = VZa-Deca P_3i = VZb+V_Dir+Decb P_4i = VZb+V_Dir-Decb """ 1) Top 2) Front 3) Left 4) Right 5) Back 6) Front inf 7) Left inf 8) Right inf 9) Back inf 10) Bottom """ verts = [ # 10 faces with 4 corners each [P_1t.x, P_1t.z, P_1t.y], [P_2t.x, P_2t.z, P_2t.y], [P_4t.x, P_4t.z, P_4t.y], [P_3t.x, P_3t.z, P_3t.y], [P_1t.x, P_1t.z, P_1t.y], [P_3t.x, P_3t.z, P_3t.y], [P_3m.x, P_3m.z, P_3m.y], [P_1m.x, P_1m.z, P_1m.y], [P_2t.x, P_2t.z, P_2t.y], [P_1t.x, P_1t.z, P_1t.y], [P_1m.x, P_1m.z, P_1m.y], [P_2m.x, P_2m.z, P_2m.y], [P_3t.x, P_3t.z, P_3t.y], [P_4t.x, P_4t.z, P_4t.y], [P_4m.x, P_4m.z, P_4m.y], [P_3m.x, P_3m.z, P_3m.y], [P_4t.x, P_4t.z, P_4t.y], [P_2t.x, P_2t.z, P_2t.y], [P_2m.x, P_2m.z, P_2m.y], [P_4m.x, P_4m.z, P_4m.y], [P_1m.x, P_1m.z, P_1m.y], [P_3m.x, P_3m.z, P_3m.y], [P_3i.x, P_3i.z, P_3i.y], [P_1i.x, P_1i.z, P_1i.y], [P_2m.x, P_2m.z, P_2m.y], [P_1m.x, P_1m.z, P_1m.y], [P_1i.x, P_1i.z, P_1i.y], [P_2i.x, P_2i.z, P_2i.y], [P_3m.x, P_3m.z, P_3m.y], [P_4m.x, P_4m.z, P_4m.y], [P_4i.x, P_4i.z, P_4i.y], [P_3i.x, P_3i.z, P_3i.y], [P_4m.x, P_4m.z, P_4m.y], [P_2m.x, P_2m.z, P_2m.y], [P_2i.x, P_2i.z, P_2i.y], [P_4i.x, P_4i.z, P_4i.y], [P_1i.x, P_1i.z, P_1i.y], [P_2i.x, P_2i.z, P_2i.y], [P_4i.x, P_4i.z, P_4i.y], [P_3i.x, P_3i.z, P_3i.y] ] else: nbv=24 Deca = Vector(Norm.x*s_infa,Norm.y*s_infa,Norm.z*s_infa) Decb = Vector(Norm.x*s_infb,Norm.y*s_infb,Norm.z*s_infb) # X Z Y P_1t = Vtop+Dec P_2t = Vtop-Dec P_3t = V_Dir+Vtop+Dec P_4t = V_Dir+Vtop-Dec P_1i = VZa+Deca P_2i = VZa-Deca P_3i = VZb+V_Dir+Decb P_4i = VZb+V_Dir-Decb """ 1) Top 2) Front 3) Left 4) Right 5) Back 6) Bottom """ verts = [ # 6 faces with 4 corners each [P_1t.x, P_1t.z, P_1t.y], [P_2t.x, P_2t.z, P_2t.y], [P_4t.x, P_4t.z, P_4t.y], [P_3t.x, P_3t.z, P_3t.y], [P_1t.x, P_1t.z, P_1t.y], [P_3t.x, P_3t.z, P_3t.y], [P_3i.x, P_3i.z, P_3i.y], [P_1i.x, P_1i.z, P_1i.y], [P_2t.x, P_2t.z, P_2t.y], [P_1t.x, P_1t.z, P_1t.y], [P_1i.x, P_1i.z, P_1i.y], [P_2i.x, P_2i.z, P_2i.y], [P_3t.x, P_3t.z, P_3t.y], [P_4t.x, P_4t.z, P_4t.y], [P_4i.x, P_4i.z, P_4i.y], [P_3i.x, P_3i.z, P_3i.y], [P_4t.x, P_4t.z, P_4t.y], [P_2t.x, P_2t.z, P_2t.y], [P_2i.x, P_2i.z, P_2i.y], [P_4i.x, P_4i.z, P_4i.y], [P_1i.x, P_1i.z, P_1i.y], [P_2i.x, P_2i.z, P_2i.y], [P_4i.x, P_4i.z, P_4i.y], [P_3i.x, P_3i.z, P_3i.y] ] mesh.setVertices(numpy.asarray(verts, dtype=numpy.float32)) indices = [] for i in range(0, nbv, 4): # All 6 quads (12 triangles) indices.append([i, i+2, i+1]) indices.append([i, i+3, i+2]) mesh.setIndices(numpy.asarray(indices, dtype=numpy.int32)) mesh.calculateNormals() return mesh