本文整理汇总了Python中UM.Scene.SceneNode.SceneNode.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python SceneNode.rotate方法的具体用法?Python SceneNode.rotate怎么用?Python SceneNode.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UM.Scene.SceneNode.SceneNode
的用法示例。
在下文中一共展示了SceneNode.rotate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rotate
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import rotate [as 别名]
def test_rotate(self):
node = SceneNode()
self.assertEqual(node.getOrientation(), Quaternion())
node.rotate(Quaternion.fromAngleAxis(math.pi / 4, Vector.Unit_Z))
self.assertEqual(node.getOrientation(), Quaternion.fromAngleAxis(math.pi / 4, Vector.Unit_Z))
node.rotate(Quaternion.fromAngleAxis(math.pi / 4, Vector.Unit_Z))
self.assertEqual(node.getOrientation(), Quaternion.fromAngleAxis(math.pi / 2, Vector.Unit_Z))
示例2: test_rotate
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import rotate [as 别名]
def test_rotate(self):
node = SceneNode()
self.assertEqual(node.getOrientation(), Quaternion())
node.rotate(Quaternion.fromAngleAxis(math.pi / 4, Vector.Unit_Z))
node_orientation = deepcopy(node.getOrientation())
node_orientation.normalize() #For fair comparison.
self.assertEqual(node_orientation, Quaternion.fromAngleAxis(math.pi / 4, Vector.Unit_Z))
node.rotate(Quaternion.fromAngleAxis(math.pi / 4, Vector.Unit_Z))
node_orientation = deepcopy(node.getOrientation())
node_orientation.normalize()
self.assertEqual(node_orientation, Quaternion.fromAngleAxis(math.pi / 2, Vector.Unit_Z))
示例3: test_translateWorld
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import rotate [as 别名]
def test_translateWorld(self):
node1 = SceneNode()
node2 = SceneNode(node1)
self.assertEqual(node2.getWorldPosition(), Vector(0, 0, 0))
node1.translate(Vector(0, 0, 10))
self.assertEqual(node1.getWorldPosition(), Vector(0, 0, 10))
self.assertEqual(node2.getWorldPosition(), Vector(0, 0, 10))
node2.translate(Vector(0, 0, 10))
self.assertEqual(node1.getWorldPosition(), Vector(0, 0, 10))
self.assertEqual(node2.getWorldPosition(), Vector(0, 0, 20))
node1.rotate(Quaternion.fromAngleAxis(math.pi / 2, Vector.Unit_Y))
self.assertEqual(node1.getWorldPosition(), Vector(0, 0, 10))
self.assertEqual(node2.getWorldPosition(), Vector(10, 0, 10))
node2.translate(Vector(0, 0, 10))
# Local translation on Z with a parent rotated 90 degrees results in movement on X axis
pos = node2.getWorldPosition()
#Using fuzzyCompare due to accumulation of floating point error
self.assertTrue(Float.fuzzyCompare(pos.x, 20, 1e-5), "{0} does not equal {1}".format(pos, Vector(20, 0, 10)))
self.assertTrue(Float.fuzzyCompare(pos.y, 0, 1e-5), "{0} does not equal {1}".format(pos, Vector(20, 0, 10)))
self.assertTrue(Float.fuzzyCompare(pos.z, 10, 1e-5), "{0} does not equal {1}".format(pos, Vector(20, 0, 10)))
node2.translate(Vector(0, 0, 10), SceneNode.TransformSpace.World)
# World translation on Z with a parent rotated 90 degrees results in movement on Z axis
pos = node2.getWorldPosition()
self.assertTrue(Float.fuzzyCompare(pos.x, 20, 1e-5), "{0} does not equal {1}".format(pos, Vector(20, 0, 20)))
self.assertTrue(Float.fuzzyCompare(pos.y, 0, 1e-5), "{0} does not equal {1}".format(pos, Vector(20, 0, 20)))
self.assertTrue(Float.fuzzyCompare(pos.z, 20, 1e-5), "{0} does not equal {1}".format(pos, Vector(20, 0, 20)))
node1.translate(Vector(0, 0, 10))
self.assertEqual(node1.getWorldPosition(), Vector(10, 0, 10))
pos = node2.getWorldPosition()
self.assertTrue(Float.fuzzyCompare(pos.x, 30, 1e-5), "{0} does not equal {1}".format(pos, Vector(30, 0, 20)))
self.assertTrue(Float.fuzzyCompare(pos.y, 0, 1e-5), "{0} does not equal {1}".format(pos, Vector(30, 0, 20)))
self.assertTrue(Float.fuzzyCompare(pos.z, 20, 1e-5), "{0} does not equal {1}".format(pos, Vector(30, 0, 20)))
node1.scale(Vector(2, 2, 2))
pos = node2.getWorldPosition()
self.assertTrue(Float.fuzzyCompare(pos.x, 50, 1e-4), "{0} does not equal {1}".format(pos, Vector(50, 0, 30)))
self.assertTrue(Float.fuzzyCompare(pos.y, 0, 1e-4), "{0} does not equal {1}".format(pos, Vector(50, 0, 30)))
self.assertTrue(Float.fuzzyCompare(pos.z, 30, 1e-4), "{0} does not equal {1}".format(pos, Vector(50, 0, 30)))
node2.translate(Vector(0, 0, 10))
pos = node2.getWorldPosition()
self.assertTrue(Float.fuzzyCompare(pos.x, 70, 1e-4), "{0} does not equal {1}".format(pos, Vector(70, 0, 30)))
self.assertTrue(Float.fuzzyCompare(pos.y, 0, 1e-4), "{0} does not equal {1}".format(pos, Vector(70, 0, 30)))
self.assertTrue(Float.fuzzyCompare(pos.z, 30, 1e-4), "{0} does not equal {1}".format(pos, Vector(70, 0, 30)))
# World space set position
node1 = SceneNode()
node2 = SceneNode(node1)
node1.setPosition(Vector(15,15,15))
node2.setPosition(Vector(10,10,10))
self.assertEqual(node2.getWorldPosition(), Vector(25, 25, 25))
node2.setPosition(Vector(15,15,15), SceneNode.TransformSpace.World)
self.assertEqual(node2.getWorldPosition(), Vector(15, 15, 15))
self.assertEqual(node2.getPosition(), Vector(0,0,0))
node1.setPosition(Vector(15,15,15))
node2.setPosition(Vector(0,0,0))
node2.rotate(Quaternion.fromAngleAxis(-math.pi / 2, Vector.Unit_Y))
node2.translate(Vector(10,0,0))
self.assertEqual(node2.getWorldPosition(), Vector(15,15,25))
node2.setPosition(Vector(15,15,25), SceneNode.TransformSpace.World)
self.assertEqual(node2.getWorldPosition(), Vector(15,15,25))
self.assertEqual(node2.getPosition(), Vector(0,0,10))
示例4: read
# 需要导入模块: from UM.Scene.SceneNode import SceneNode [as 别名]
# 或者: from UM.Scene.SceneNode.SceneNode import rotate [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