public static PhysicsObjectRenderer Create(ColladaGeometry geometry) { var Renderer = new PhysicsObjectRenderer(); Renderer.AttachedObject = geometry; return(Renderer); }
public string StrVisuals() { string str = " <library_visual_scenes>\r\n"; foreach (ColladaScene scene in Scenes) { str += " <visual_scene id=\"ID" + scene.Id + "\">\r\n" + " <node name=\"Scene" + scene.Id + "\">\r\n"; foreach (int i in scene.Geometry) { ColladaGeometry geo = FindGeometry(i); str += " <instance_geometry url=\"#ID" + geo.Id + "\">\r\n" + " <bind_material>\r\n" + " <technique_common>\r\n" + " <instance_material symbol=\"Material" + geo.Materialid + "\" target=\"#ID" + geo.Materialid + "\">\r\n" + " <bind_vertex_input semantic=\"UVSET0\" input_semantic=\"TEXCOORD\" input_set=\"0\" />\r\n" + " </instance_material>\r\n" + " </technique_common>\r\n" + " </bind_material>\r\n" + " </instance_geometry>\r\n"; } str += " </node>\r\n" + " </visual_scene>\r\n"; } str += " </library_visual_scenes>"; return(str); }
public static WorldRenderer Create(ColladaGeometry World) { var WorldRender = new WorldRenderer(); WorldRender.AttachedObject = World; return(WorldRender); }
public static void WriteMesh(string filename, RectList rects) { List <ulong> palette = FindRgbaPalette(rects); _nodeid = 1; var scene = new ColladaScene { Id = _nodeid++ }; var collada = new Collada(); collada.Scenes.Add(scene); foreach (ulong rgba in palette) { var effect = new ColladaEffect(); Converter.Ulong2Rgba(rgba, out effect.R, out effect.G, out effect.B, out effect.A); var material = new ColladaMaterial { Id = _nodeid++ }; effect.Id = _nodeid++; material.Url = effect.Id; effect.Rgba = rgba; collada.Materials.Add(material); collada.Effects.Add(effect); } foreach (Rect rect in rects) { var geom = new ColladaGeometry { Id = _nodeid++, PositionId = _nodeid++, NormalId = _nodeid++, PositionId2 = _nodeid++, NormalId2 = _nodeid++, VertexId = _nodeid++ }; int material = collada.FindMaterial(rect.Properties.Rgba); geom.Materialid = material; geom.X1 = rect.Pt1[0]; geom.Y1 = rect.Pt1[1]; geom.Z1 = rect.Pt1[2]; geom.X2 = rect.Pt2[0]; geom.Y2 = rect.Pt2[1]; geom.Z2 = rect.Pt2[2]; collada.Geometries.Add(geom); scene.Geometry.Add(geom.Id); } collada.WriteMesh(filename); }
public void ParseGeometry(XmlNode root) { foreach (XmlNode node in root.ChildNodes) { ColladaGeometry g = new ColladaGeometry(); g.Read(node); library_geometries.Add(g); } }
public RigidBody AddDynamicGeometry(ColladaGeometry geometry, Matrix4 transform, object UserData) { var min = new Vector3(99999999999, 999999999999, 99999999999); var max = new Vector3(0, 0, 0); foreach (Triangle tri in geometry.triangles) { foreach (Vector3 vertex in tri.vertices) { if (vertex.X < min.X) { min.X = vertex.X; } if (vertex.Y < min.Y) { min.Y = vertex.Y; } if (vertex.Z < min.Z) { min.Z = vertex.Z; } if (vertex.X > max.X) { max.X = vertex.X; } if (vertex.Y > max.Y) { max.Y = vertex.Y; } if (vertex.Z > max.Z) { max.Z = vertex.Z; } } } CollisionShape shape = new BoxShape((max.X - min.X) / 2, (max.Y - min.Y) / 2, (max.Z - min.Z) / 2); shape.UserObject = UserData; collisionShapes.Add(shape); RigidBody body = CreateRigidBody(geometry.triangles.Count, transform, shape); return(body); }
public RigidBody AddStaticGeometry(ColladaGeometry geometry, Matrix4 transform, object UserData) { TriangleMesh mesh = new TriangleMesh(); foreach (Triangle tri in geometry.triangles) { mesh.AddTriangle(tri.vertices[0], tri.vertices[1], tri.vertices[2] ); } CollisionShape shape = new BvhTriangleMeshShape(mesh, true); shape.UserObject = UserData; collisionShapes.Add(shape); RigidBody body = CreateRigidBody(0, transform, shape); //Zero mass for static body return(body); }
public RigidBody AddDynamicGeometryAccurateConvel(ColladaGeometry geometry, Matrix4 transform) { TriangleMesh mesh = new TriangleMesh(); foreach (Triangle tri in geometry.triangles) { mesh.AddTriangle( tri.vertices[0], tri.vertices[1], tri.vertices[2] ); } CollisionShape shape = new ConvexTriangleMeshShape(mesh); shape.UserObject = geometry; collisionShapes.Add(shape); RigidBody body = CreateRigidBody(geometry.triangles.Count, transform, shape); return(body); }
static ModelMeshData LoadGeometry(ModelData data, ModelBoneData parentBoneData, ColladaGeometry geometry) { ModelMeshData modelMeshData = new ModelMeshData(); data.Meshes.Add(modelMeshData); modelMeshData.Name = parentBoneData.Name; modelMeshData.ParentBoneIndex = data.Bones.IndexOf(parentBoneData); bool flag = false; foreach (ColladaPolygons current in geometry.Mesh.Polygons) { ModelMeshPartData modelMeshPartData = LoadPolygons(data, current); modelMeshData.MeshParts.Add(modelMeshPartData); modelMeshData.BoundingBox = (flag ? BoundingBox.Union(modelMeshData.BoundingBox, modelMeshPartData.BoundingBox) : modelMeshPartData.BoundingBox); flag = true; } return(modelMeshData); }
public static string StrGeometry(ColladaGeometry geom) { double minx = geom.X1; double miny = geom.Z1; double minz = geom.Y1; double maxx = geom.X2; double maxy = geom.Z2; double maxz = geom.Y2; double[] data = { maxx, maxy, minz, minx, miny, minz, minx, maxy, minz, maxx, miny, minz, minx, maxy, maxz, maxx, maxy, minz, minx, maxy, minz, maxx, maxy, maxz, maxx, maxy, minz, maxx, miny, maxz, maxx, miny, minz, maxx, maxy, maxz, maxx, miny, maxz, minx, miny, minz, maxx, miny, minz, minx, miny, maxz, minx, maxy, maxz, minx, miny, minz, minx, miny, maxz, minx, maxy, minz, maxx, miny, maxz, minx, maxy, maxz, minx, miny, maxz, maxx, maxy, maxz }; string array = ""; const string points = "0 1 2 1 0 3 4 5 6 5 4 7 8 9 10 9 8 11 12 13 14 13 12 15 16 17 18 17 16 19 20 21 22 21 20 23"; const string normals = "0 0 -1 0 0 -1 0 0 -1 0 0 -1 1 0 0 1 0 0 1 0 0 1 0 0 -0 -1 -0 -0 -1 -0 -0 -1 -0 -0 -1 -0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -0 1 0 -0 1 0 -0 1 0 -0 1 0 0 0 1 0 0 1 0 0 1 0 0 1"; for (int i = 0; i < data.Length; i += 3) { double x = data[i + 0]; double y = data[i + 1]; double z = data[i + 2]; array += x + " " + y + " " + z + " "; } string str = " <geometry id=\"ID" + geom.Id + "\">\r\n" + " <mesh>\r\n" + " <source id=\"ID" + geom.PositionId + "\">\r\n" + " <float_array id=\"ID" + geom.PositionId2 + "\" count=\"72\">" + array + "</float_array>\r\n" + " <technique_common>\r\n" + " <accessor count=\"24\" source=\"#ID" + geom.PositionId + "\" stride=\"3\">\r\n" + " <param name=\"X\" type=\"float\" />\r\n" + " <param name=\"Y\" type=\"float\" />\r\n" + " <param name=\"Z\" type=\"float\" />\r\n" + " </accessor>\r\n" + " </technique_common>\r\n" + " </source>\r\n" + " <source id=\"ID" + geom.NormalId + "\">\r\n" + " <float_array id=\"ID" + geom.NormalId2 + "\" count=\"72\">" + normals + "</float_array>\r\n" + " <technique_common>\r\n" + " <accessor count=\"24\" source=\"#ID" + geom.NormalId2 + "\" stride=\"3\">\r\n" + " <param name=\"X\" type=\"float\" />\r\n" + " <param name=\"Y\" type=\"float\" />\r\n" + " <param name=\"Z\" type=\"float\" />\r\n" + " </accessor>\r\n" + " </technique_common>\r\n" + " </source>\r\n" + " <vertices id=\"ID" + geom.VertexId + "\">\r\n" + " <input semantic=\"POSITION\" source=\"#ID" + geom.PositionId + "\" />\r\n" + " <input semantic=\"NORMAL\" source=\"#ID" + geom.NormalId + "\" />\r\n" + " </vertices>\r\n" + " <triangles count=\"12\" material=\"Material" + geom.Materialid + "\">\r\n" + " <input offset=\"0\" semantic=\"VERTEX\" source=\"#ID" + geom.VertexId + "\" />\r\n" + " <p>" + points + "</p>\r\n" + " </triangles>\r\n" + " </mesh>\r\n" + " </geometry>\r\n"; return(str); }