本文整理汇总了Python中UM.Math.Quaternion.Quaternion.setByMatrix方法的典型用法代码示例。如果您正苦于以下问题:Python Quaternion.setByMatrix方法的具体用法?Python Quaternion.setByMatrix怎么用?Python Quaternion.setByMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UM.Math.Quaternion.Quaternion
的用法示例。
在下文中一共展示了Quaternion.setByMatrix方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _updateLocalTransformation
# 需要导入模块: from UM.Math.Quaternion import Quaternion [as 别名]
# 或者: from UM.Math.Quaternion.Quaternion import setByMatrix [as 别名]
def _updateLocalTransformation(self):
translation, euler_angle_matrix, scale, shear = self._transformation.decompose()
self._position = translation
self._scale = scale
self._shear = shear
orientation = Quaternion()
orientation.setByMatrix(euler_angle_matrix)
self._orientation = orientation
示例2: _updateTransformation
# 需要导入模块: from UM.Math.Quaternion import Quaternion [as 别名]
# 或者: from UM.Math.Quaternion.Quaternion import setByMatrix [as 别名]
def _updateTransformation(self):
scale, shear, euler_angles, translation, mirror = self._transformation.decompose()
self._position = translation
self._scale = scale
self._shear = shear
self._mirror = mirror
orientation = Quaternion()
euler_angle_matrix = Matrix()
euler_angle_matrix.setByEuler(euler_angles.x, euler_angles.y, euler_angles.z)
orientation.setByMatrix(euler_angle_matrix)
self._orientation = orientation
if self._parent:
self._world_transformation = self._parent.getWorldTransformation().multiply(self._transformation, copy = True)
else:
self._world_transformation = self._transformation
world_scale, world_shear, world_euler_angles, world_translation, world_mirror = self._world_transformation.decompose()
self._derived_position = world_translation
self._derived_scale = world_scale
world_euler_angle_matrix = Matrix()
world_euler_angle_matrix.setByEuler(world_euler_angles.x, world_euler_angles.y, world_euler_angles.z)
self._derived_orientation.setByMatrix(world_euler_angle_matrix)
示例3: read
# 需要导入模块: from UM.Math.Quaternion import Quaternion [as 别名]
# 或者: from UM.Math.Quaternion.Quaternion import setByMatrix [as 别名]
def read(self, file_name):
result = None
extension = os.path.splitext(file_name)[1]
if extension.lower() == self._supported_extension:
result = SceneNode()
# The base object of 3mf is a zipped archive.
archive = zipfile.ZipFile(file_name, 'r')
try:
root = ET.parse(archive.open("3D/3dmodel.model"))
# There can be multiple objects, try to load all of them.
objects = root.findall("./3mf:resources/3mf:object", self._namespaces)
for object in objects:
mesh = MeshData()
node = SceneNode()
vertex_list = []
#for vertex in object.mesh.vertices.vertex:
for vertex in object.findall(".//3mf:vertex", self._namespaces):
vertex_list.append([vertex.get("x"), vertex.get("y"), vertex.get("z")])
triangles = object.findall(".//3mf:triangle", self._namespaces)
mesh.reserveFaceCount(len(triangles))
#for triangle in object.mesh.triangles.triangle:
for triangle in triangles:
v1 = int(triangle.get("v1"))
v2 = int(triangle.get("v2"))
v3 = int(triangle.get("v3"))
mesh.addFace(vertex_list[v1][0],vertex_list[v1][1],vertex_list[v1][2],vertex_list[v2][0],vertex_list[v2][1],vertex_list[v2][2],vertex_list[v3][0],vertex_list[v3][1],vertex_list[v3][2])
#TODO: We currently do not check for normals and simply recalculate them.
mesh.calculateNormals()
node.setMeshData(mesh)
node.setSelectable(True)
transformation = root.findall("./3mf:build/3mf:item[@objectid='{0}']".format(object.get("id")), self._namespaces)
if transformation:
transformation = transformation[0]
if transformation.get("transform"):
splitted_transformation = transformation.get("transform").split()
## Transformation is saved as:
## M00 M01 M02 0.0
## M10 M11 M12 0.0
## M20 M21 M22 0.0
## M30 M31 M32 1.0
## We switch the row & cols as that is how everyone else uses matrices!
temp_mat = Matrix()
# Rotation & Scale
temp_mat._data[0,0] = splitted_transformation[0]
temp_mat._data[1,0] = splitted_transformation[1]
temp_mat._data[2,0] = splitted_transformation[2]
temp_mat._data[0,1] = splitted_transformation[3]
temp_mat._data[1,1] = splitted_transformation[4]
temp_mat._data[2,1] = splitted_transformation[5]
temp_mat._data[0,2] = splitted_transformation[6]
temp_mat._data[1,2] = splitted_transformation[7]
temp_mat._data[2,2] = splitted_transformation[8]
# Translation
temp_mat._data[0,3] = splitted_transformation[9]
temp_mat._data[1,3] = splitted_transformation[10]
temp_mat._data[2,3] = splitted_transformation[11]
node.setPosition(Vector(temp_mat.at(0,3), temp_mat.at(1,3), temp_mat.at(2,3)))
temp_quaternion = Quaternion()
temp_quaternion.setByMatrix(temp_mat)
node.setOrientation(temp_quaternion)
# Magical scale extraction
S2 = temp_mat.getTransposed().multiply(temp_mat)
scale_x = math.sqrt(S2.at(0,0))
scale_y = math.sqrt(S2.at(1,1))
scale_z = math.sqrt(S2.at(2,2))
node.setScale(Vector(scale_x,scale_y,scale_z))
# We use a different coordinate frame, so rotate.
rotation = Quaternion.fromAngleAxis(-0.5 * math.pi, Vector(1,0,0))
node.rotate(rotation)
result.addChild(node)
#If there is more then one object, group them.
try:
if len(objects) > 1:
group_decorator = GroupDecorator()
result.addDecorator(group_decorator)
except:
pass
except Exception as e:
Logger.log("e" ,"exception occured in 3mf reader: %s" , e)
return result
示例4: SceneNode
# 需要导入模块: from UM.Math.Quaternion import Quaternion [as 别名]
# 或者: from UM.Math.Quaternion.Quaternion import setByMatrix [as 别名]
#.........这里部分代码省略.........
# \return False if the view should render this node, True if we handle our own rendering.
def render(self, renderer) -> bool:
return False
## Get whether this SceneNode is enabled, that is, it can be modified in any way.
def isEnabled(self) -> bool:
return self._enabled
## Set whether this SceneNode is enabled.
# \param enable True if this object should be enabled, False if not.
# \sa isEnabled
def setEnabled(self, enable: bool):
self._enabled = enable
## Get whether this SceneNode can be selected.
#
# \note This will return false if isEnabled() returns false.
def isSelectable(self) -> bool:
return self._enabled and self._selectable
## Set whether this SceneNode can be selected.
#
# \param select True if this SceneNode should be selectable, False if not.
def setSelectable(self, select: bool):
self._selectable = select
## Get the bounding box of this node and its children.
def getBoundingBox(self) -> Optional[AxisAlignedBox]:
if not self._calculate_aabb:
return None
if self._aabb is None:
self._calculateAABB()
return self._aabb
## Set whether or not to calculate the bounding box for this node.
#
# \param calculate True if the bounding box should be calculated, False if not.
def setCalculateBoundingBox(self, calculate: bool):
self._calculate_aabb = calculate
boundingBoxChanged = Signal()
def getShear(self) -> Vector:
return self._shear
## private:
def _transformChanged(self):
self._updateTransformation()
self._resetAABB()
self.transformationChanged.emit(self)
for child in self._children:
child._transformChanged()
def _updateTransformation(self):
scale, shear, euler_angles, translation, mirror = self._transformation.decompose()
self._position = translation
self._scale = scale
self._shear = shear
self._mirror = mirror
orientation = Quaternion()
euler_angle_matrix = Matrix()
euler_angle_matrix.setByEuler(euler_angles.x, euler_angles.y, euler_angles.z)
orientation.setByMatrix(euler_angle_matrix)
self._orientation = orientation
if self._parent:
self._world_transformation = self._parent.getWorldTransformation().multiply(self._transformation, copy = True)
else:
self._world_transformation = self._transformation
world_scale, world_shear, world_euler_angles, world_translation, world_mirror = self._world_transformation.decompose()
self._derived_position = world_translation
self._derived_scale = world_scale
world_euler_angle_matrix = Matrix()
world_euler_angle_matrix.setByEuler(world_euler_angles.x, world_euler_angles.y, world_euler_angles.z)
self._derived_orientation.setByMatrix(world_euler_angle_matrix)
def _resetAABB(self):
if not self._calculate_aabb:
return
self._aabb = None
if self.getParent():
self.getParent()._resetAABB()
self.boundingBoxChanged.emit()
def _calculateAABB(self):
aabb = None
if self._mesh_data:
aabb = self._mesh_data.getExtents(self.getWorldTransformation())
else: # If there is no mesh_data, use a boundingbox that encompasses the local (0,0,0)
position = self.getWorldPosition()
aabb = AxisAlignedBox(minimum = position, maximum = position)
for child in self._children:
if aabb is None:
aabb = child.getBoundingBox()
else:
aabb = aabb + child.getBoundingBox()
self._aabb = aabb
示例5: SceneNode
# 需要导入模块: from UM.Math.Quaternion import Quaternion [as 别名]
# 或者: from UM.Math.Quaternion.Quaternion import setByMatrix [as 别名]
#.........这里部分代码省略.........
# you can override this method and render the node. Return True to prevent the
# view from rendering any attached mesh data.
#
# \param renderer The renderer object to use for rendering.
#
# \return False if the view should render this node, True if we handle our own rendering.
def render(self, renderer):
return False
## Get whether this SceneNode is enabled, that is, it can be modified in any way.
def isEnabled(self):
if self._parent != None and self._enabled:
return self._parent.isEnabled()
else:
return self._enabled
## Set whether this SceneNode is enabled.
# \param enable True if this object should be enabled, False if not.
# \sa isEnabled
def setEnabled(self, enable):
self._enabled = enable
## Get whether this SceneNode can be selected.
#
# \note This will return false if isEnabled() returns false.
def isSelectable(self):
return self._enabled and self._selectable
## Set whether this SceneNode can be selected.
#
# \param select True if this SceneNode should be selectable, False if not.
def setSelectable(self, select):
self._selectable = select
## Get the bounding box of this node and its children.
#
# Note that the AABB is calculated in a separate thread. This method will return an invalid (size 0) AABB
# while the calculation happens.
def getBoundingBox(self):
if self._aabb:
return self._aabb
if not self._aabb_job:
self._resetAABB()
return AxisAlignedBox()
## Set whether or not to calculate the bounding box for this node.
#
# \param calculate True if the bounding box should be calculated, False if not.
def setCalculateBoundingBox(self, calculate):
self._calculate_aabb = calculate
boundingBoxChanged = Signal()
## private:
def _transformChanged(self):
self._updateTransformation()
self._resetAABB()
self.transformationChanged.emit(self)
for child in self._children:
child._transformChanged()
def _updateTransformation(self):
scale, shear, euler_angles, translation = self._transformation.decompose()
self._position = translation
self._scale = scale
self._shear = shear
orientation = Quaternion()
euler_angle_matrix = Matrix()
euler_angle_matrix.setByEuler(euler_angles.x, euler_angles.y, euler_angles.z)
orientation.setByMatrix(euler_angle_matrix)
self._orientation = orientation
if self._parent:
self._world_transformation = self._parent.getWorldTransformation().multiply(self._transformation, copy = True)
else:
self._world_transformation = self._transformation
world_scale, world_shear, world_euler_angles, world_translation = self._world_transformation.decompose()
self._derived_position = world_translation
self._derived_scale = world_scale
world_euler_angle_matrix = Matrix()
world_euler_angle_matrix.setByEuler(world_euler_angles.x, world_euler_angles.y, world_euler_angles.z)
self._derived_orientation.setByMatrix(world_euler_angle_matrix)
world_scale, world_shear, world_euler_angles, world_translation = self._world_transformation.decompose()
def _resetAABB(self):
if not self._calculate_aabb:
return
self._aabb = None
if self._aabb_job:
self._aabb_job.cancel()
self._aabb_job = _CalculateAABBJob(self)
self._aabb_job.start()