Example #1
0
 /// <summary>
 /// Calculates the bounding box of the mesh and sets the mesh to [0, 0, 0].
 /// </summary>
 /// <param name="mesh"></param>
 public static void SetToOrigin(Geometry geom)
 {
     Mesh mesh = geom.Mesh;
     if (mesh.BoundingBox == null)
         mesh.BoundingBox = mesh.CreateBoundingBox();
     Vector3f difference = geom.GetLocalTranslation().Subtract(mesh.BoundingBox.Center);
     for (int i = 0; i < mesh.indices.Count; i++)
     {
         mesh.vertices[mesh.indices[i]].SetPosition(mesh.vertices[mesh.indices[i]].GetPosition().Add(difference));
     }
     mesh.SetVertices(mesh.vertices, mesh.indices);
     if (geom.GetController(typeof(Scene.Physics.RigidBodyControl)) != null)
     {
         Scene.Physics.RigidBodyControl rbc = (Scene.Physics.RigidBodyControl)geom.GetController(typeof(Scene.Physics.RigidBodyControl));
     }
     geom.SetLocalTranslation(mesh.BoundingBox.Center);
 }
Example #2
0
 private static void SaveGeometry(Geometry geom, XmlWriter writer)
 {
     writer.WriteStartElement(TOKEN_GEOMETRY);
     if (geom.Name != "root")
         writer.WriteAttributeString(TOKEN_NAME, geom.Name);
     else
         writer.WriteAttributeString(TOKEN_NAME, "root_model");
     writer.WriteStartElement(TOKEN_TRANSLATION);
     writer.WriteAttributeString("x", geom.GetLocalTranslation().x.ToString());
     writer.WriteAttributeString("y", geom.GetLocalTranslation().y.ToString());
     writer.WriteAttributeString("z", geom.GetLocalTranslation().z.ToString());
     writer.WriteStartElement(TOKEN_SCALE);
     writer.WriteAttributeString("x", geom.GetLocalScale().x.ToString());
     writer.WriteAttributeString("y", geom.GetLocalScale().y.ToString());
     writer.WriteAttributeString("z", geom.GetLocalScale().z.ToString());
     writer.WriteEndElement();
     writer.WriteStartElement(TOKEN_ROTATION);
     writer.WriteAttributeString("x", geom.GetLocalRotation().x.ToString());
     writer.WriteAttributeString("y", geom.GetLocalRotation().y.ToString());
     writer.WriteAttributeString("z", geom.GetLocalRotation().z.ToString());
     writer.WriteAttributeString("w", geom.GetLocalRotation().w.ToString());
     writer.WriteEndElement();
     writer.WriteEndElement();
     if (geom.Mesh != null)
     {
         SaveMesh(geom.Mesh, writer);
     }
     SaveMaterial(geom.Material, writer);
     writer.WriteEndElement();
 }