Example #1
0
def euler_to_quat(euler):
    ang = euler[0] * 0.5
    sr = math.sin(ang)
    cr = math.cos(ang)

    ang = euler[1] * 0.5
    sp = math.sin(ang)
    cp = math.cos(ang)

    ang = euler[2] * 0.5
    sy = math.sin(ang)
    cy = math.cos(ang)

    cpcy = cp * cy
    spcy = sp * cy
    cpsy = cp * sy
    spsy = sp * sy

    quat = Quat(cr*cpcy + sr*spsy, sr * cpcy - cr*spsy, cr*spcy + sr * cpsy, cr * cpsy - sr * spcy)
    quat.normalize()
    return quat
Example #2
0
def euler_to_quat(euler):
    ang = euler[0] * 0.5
    sr = math.sin(ang)
    cr = math.cos(ang)

    ang = euler[1] * 0.5
    sp = math.sin(ang)
    cp = math.cos(ang)

    ang = euler[2] * 0.5
    sy = math.sin(ang)
    cy = math.cos(ang)

    cpcy = cp * cy
    spcy = sp * cy
    cpsy = cp * sy
    spsy = sp * sy

    quat = QQuaternion(cr * cpcy + sr * spsy, sr * cpcy - cr * spsy,
                       cr * spcy + sr * cpsy, cr * cpsy - sr * spcy)
    quat.normalize()
    return quat
Example #3
0
    def save(self, filename, nodes):
        from PythonQt.QtGui import QQuaternion
        newdoc = self.impl.createDocument(None, "scene formatVersion=\"\"",
                                          None)
        top_element = newdoc.documentElement
        nodesNode = newdoc.createElement('nodes')
        top_element.appendChild(nodesNode)

        if (nodes != None):
            for k, oNode in nodes.iteritems():
                nodeNode = newdoc.createElement('node')
                nodeNode.setAttribute("name", k)
                nodeNode.setAttribute("id", oNode.id)

                position = newdoc.createElement('position')

                position.setAttribute(
                    "x", str(oNode.naali_ent.placeable.Position.x()))
                position.setAttribute(
                    "y", str(oNode.naali_ent.placeable.Position.y()))
                position.setAttribute(
                    "z", str(oNode.naali_ent.placeable.Position.z()))

                nodeNode.appendChild(position)

                rotation = newdoc.createElement('rotation')
                # XXX counter the 'fix' done in loading the scene
                # loader.py in def create_naali_meshentity()
                #ort = oNode.naali_ent.placeable.Orientation * QQuaternion(1, 0, 0, -1) * QQuaternion(1, 0, 0, -1)
                #ort = oNode.naali_ent.placeable.Orientation * QQuaternion(math.sqrt(0.5),0,0,math.sqrt(0.5)) * QQuaternion(math.sqrt(0.5),0,0,math.sqrt(0.5))
                rotate90z = QQuaternion(1, 0, 0, -1)
                rotate90z.normalize()
                ort = oNode.naali_ent.placeable.Orientation * rotate90z * rotate90z

                rotation.setAttribute("qx", str(ort.x()))
                rotation.setAttribute("qy", str(ort.y()))
                rotation.setAttribute("qz", str(ort.z()))
                rotation.setAttribute("qw", str(ort.scalar()))
                nodeNode.appendChild(rotation)

                scale = newdoc.createElement('scale')
                scale.setAttribute("x",
                                   str(oNode.naali_ent.placeable.Scale.x()))
                scale.setAttribute("y",
                                   str(oNode.naali_ent.placeable.Scale.y()))
                scale.setAttribute("z",
                                   str(oNode.naali_ent.placeable.Scale.z()))
                nodeNode.appendChild(scale)

                entity = newdoc.createElement('entity')
                entity.setAttribute("name",
                                    oNode.entityNode.getAttribute("name"))
                entity.setAttribute("meshFile",
                                    oNode.entityNode.getAttribute("meshFile"))
                if oNode.entityNode.hasAttribute("collisionFile"):
                    entity.setAttribute(
                        "collisionFile",
                        oNode.entityNode.getAttribute("collisionFile"))
                if oNode.entityNode.hasAttribute("collisionPrim"):
                    entity.setAttribute(
                        "collisionPrim",
                        oNode.entityNode.getAttribute("collisionPrim"))
                entity.setAttribute("static",
                                    oNode.entityNode.getAttribute("static"))
                nodeNode.appendChild(entity)
                nodesNode.appendChild(nodeNode)

        f = open(filename, 'w')
        # remove first line + change ending tag from </scene formatVersion=""> to </scene>
        contents = newdoc.toprettyxml()
        lines = contents.split('\n')
        lines = lines[1:]
        lines = lines[:-1]
        lines.remove("</scene formatVersion=\"\">")
        lines.append("</scene>")
        contents = '\n'.join(lines)
        f.write(contents)
        f.close()
Example #4
0
    def save(self, filename, nodes):
        from PythonQt.QtGui import QQuaternion
        newdoc = self.impl.createDocument(None, "scene formatVersion=\"\"", None)
        top_element = newdoc.documentElement
        nodesNode = newdoc.createElement('nodes')
        top_element.appendChild(nodesNode)
        
        if(nodes != None):
            for k, oNode  in nodes.iteritems():
                nodeNode = newdoc.createElement('node')
                nodeNode.setAttribute("name", k)
                nodeNode.setAttribute("id", oNode.id)
                
                position = newdoc.createElement('position')

                position.setAttribute("x", str(oNode.naali_ent.placeable.Position.x()))
                position.setAttribute("y", str(oNode.naali_ent.placeable.Position.y()))
                position.setAttribute("z", str(oNode.naali_ent.placeable.Position.z()))
                                
                nodeNode.appendChild(position)
                
                rotation = newdoc.createElement('rotation')
                # XXX counter the 'fix' done in loading the scene
                # loader.py in def create_naali_meshentity()
                #ort = oNode.naali_ent.placeable.Orientation * QQuaternion(1, 0, 0, -1) * QQuaternion(1, 0, 0, -1)
                #ort = oNode.naali_ent.placeable.Orientation * QQuaternion(math.sqrt(0.5),0,0,math.sqrt(0.5)) * QQuaternion(math.sqrt(0.5),0,0,math.sqrt(0.5))
                rotate90z = QQuaternion(1,0,0,-1)
                rotate90z.normalize()
                ort = oNode.naali_ent.placeable.Orientation * rotate90z * rotate90z
                
                rotation.setAttribute("qx", str(ort.x()))
                rotation.setAttribute("qy", str(ort.y()))
                rotation.setAttribute("qz", str(ort.z()))
                rotation.setAttribute("qw", str(ort.scalar()))
                nodeNode.appendChild(rotation)
                
                scale = newdoc.createElement('scale')
                scale.setAttribute("x", str(oNode.naali_ent.placeable.Scale.x()))
                scale.setAttribute("y", str(oNode.naali_ent.placeable.Scale.y()))
                scale.setAttribute("z", str(oNode.naali_ent.placeable.Scale.z()))
                nodeNode.appendChild(scale)
                
                entity = newdoc.createElement('entity')
                entity.setAttribute("name", oNode.entityNode.getAttribute("name"))
                entity.setAttribute("meshFile", oNode.entityNode.getAttribute("meshFile"))
                if oNode.entityNode.hasAttribute("collisionFile"):
                    entity.setAttribute("collisionFile", oNode.entityNode.getAttribute("collisionFile"))
                if oNode.entityNode.hasAttribute("collisionPrim"):
                    entity.setAttribute("collisionPrim", oNode.entityNode.getAttribute("collisionPrim"))
                entity.setAttribute("static", oNode.entityNode.getAttribute("static"))
                nodeNode.appendChild(entity)
                nodesNode.appendChild(nodeNode)
        
        f = open(filename, 'w')
        # remove first line + change ending tag from </scene formatVersion=""> to </scene>
        contents = newdoc.toprettyxml()
        lines = contents.split('\n')
        lines = lines[1:]
        lines = lines[:-1]
        lines.remove("</scene formatVersion=\"\">")
        lines.append("</scene>")
        contents = '\n'.join(lines)
        f.write(contents)
        f.close()