public MeshTriangle(int i0, int i1, int i2, Mesh m, string name) : base(name) { index0 = i0; index1 = i1; index2 = i2; Mesh = m; SetBoundingBox(); }
public HeightMap(byte[] heightpoints, int width, int length, float csize, float _height, string name) : base(name) { m = new Mesh(name + "Mesh"); w = width; h = length; height = _height; cellSize = csize; map = heightpoints; createMesh(); }
public FlatMeshTriangle(int i0, int i1, int i2, Mesh m,string name) : base(i0, i1, i2, m, name) { }
public SmoothMeshTriangle(int i0, int i1, int i2, Mesh m, string name) : base(i0, i1, i2, m, name) { SetBoundingBox(); }
static void getNormals(Mesh mesh, RElement ele) { bool hasNormals = ele.HasElement("Mesh.Normals"); if (hasNormals) { foreach (RElement xe in ele.GetElement(P.Obj.Mesh + ".Normals").Elements) { mesh.Normals.Add(xe.Attributes["Vector"].ToVector3()); } } }
static void getFaces(Mesh mesh, RElement ele) { bool hasNormals = ele.HasElement("Mesh.Normals"); int i = -1; foreach (RElement xe in ele.GetElement(P.Obj.Mesh + ".Faces").Elements) { i++; string[] w = xe.Attributes["Indices"].Value.Replace(" ", "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (hasNormals) { SmoothMeshTriangle fmt = new SmoothMeshTriangle(int.Parse(w[0]), int.Parse(w[1]), int.Parse(w[2]), mesh, i + "" + "smsh" + "Mesh" + mesh.Name); mesh.AddObject(fmt); } else { FlatMeshTriangle fmt = new FlatMeshTriangle(int.Parse(w[0]), int.Parse(w[1]), int.Parse(w[2]), mesh, i + "" + "fmsh" + "Mesh" + mesh.Name); fmt.ComputeNormal(false); mesh.AddObject(fmt); } } }
static void getVertices(Mesh mesh, RElement ele) { foreach (RElement xe in ele.GetElement(P.Obj.Mesh + ".Vertices").Elements) { mesh.Vertices.Add(xe.Attributes[P.Pos].ToVector3()); } }
public static GeometricObject CreateObjectFromElement(this RElement ele, Dictionary<string, Texture> txts, ref bool instance) { string n = ele.Name; string name = getName(ele); bool shad = getShadow(ele); instance = !getInstance(ele); Material m = getMaterial(ele, txts); if (n == P.Obj.Sph) { Sphere sph = new Sphere(ele.Attributes[P.Pos].ToVector3(), ele.Attributes[P.Rad].ToFloat(), name); sph.SetShadows(shad); sph.SetMaterial(m); return sph; } else if (n == P.Obj.Box) { Box box = new Box(ele.Attributes[P.Min].ToVector3(), ele.Attributes[P.Max].ToVector3(), name); box.SetShadows(shad); box.SetMaterial(m); return box; } else if (n == P.Obj.Plane) { Plane p = new Plane(ele.Attributes[P.Pos].ToVector3(), ele.Attributes[P.Dir].ToVector3(), name); p.SetShadows(shad); p.SetMaterial(m); return p; } else if (n == P.Obj.Disk) { Disk d = new Disk(ele.Attributes[P.Pos].ToVector3(), ele.Attributes[P.Dir].ToVector3(), ele.Attributes[P.Rad].ToFloat(), name); d.SetShadows(shad); d.SetMaterial(m); return d; } else if (n == P.Obj.Annulus) { Annulus d = new Annulus(ele.Attributes[P.Pos].ToVector3(), ele.Attributes[P.Dir].ToVector3(), float.Parse(ele.Attributes[P.IRad].Value), float.Parse(ele.Attributes[P.ORad].Value), name); d.SetShadows(shad); d.SetMaterial(m); return d; } else if (n == P.Obj.Tri) { Triangle t = new Triangle(ele.Attributes["P1"].ToVector3(), ele.Attributes["P2"].ToVector3(), ele.Attributes["P3"].ToVector3(), name); t.SetShadows(shad); t.SetMaterial(m); return t; } else if (n == P.Obj.STri) { SmoothTriangle t = new SmoothTriangle(ele.Attributes["P1"].ToVector3(), ele.Attributes["P2"].ToVector3(), ele.Attributes["P3"].ToVector3(), name); t.SetShadows(shad); t.SetMaterial(m); return t; } else if (n == P.Obj.Rect) { Rectangle r = new Rectangle(ele.Attributes["P"].ToVector3(), GetVector(ele.Attributes["A"]), GetVector(ele.Attributes["B"]), name); r.SetShadows(shad); r.SetMaterial(m); return r; } else if (n == P.Obj.OCyl) { OpenCylinder oc = new OpenCylinder(float.Parse(ele.Attributes[P.Bottom].Value), float.Parse(ele.Attributes[P.Top].Value), float.Parse(ele.Attributes[P.Rad].Value), name); oc.SetShadows(shad); oc.SetMaterial(m); return oc; } else if (n == P.Obj.Cyl) { SolidCylinder oc = new SolidCylinder(float.Parse(ele.Attributes[P.Bottom].Value), float.Parse(ele.Attributes[P.Top].Value), float.Parse(ele.Attributes[P.Rad].Value), name); oc.SetShadows(shad); oc.SetMaterial(m); return oc; } else if (n == P.Obj.OC) { OpenCone oc = new OpenCone(float.Parse(ele.Attributes[P.Rad].Value), float.Parse(ele.Attributes[P.Height].Value), name); oc.SetShadows(shad); oc.SetMaterial(m); return oc; } else if (n == P.Obj.COCyl) { ConvexOpenCylinder oc = new ConvexOpenCylinder(float.Parse(ele.Attributes[P.Bottom].Value), float.Parse(ele.Attributes[P.Top].Value), float.Parse(ele.Attributes[P.Rad].Value), name); oc.SetShadows(shad); oc.SetMaterial(m); return oc; } else if (n == P.Obj.Ins) { Instance ins = new Instance(GeometricObject.GetObject(ele.Attributes["ObjectRef"].Value), name); ins.SetShadows(shad); transform(ins, ele); if (m != null) ins.SetMaterial(m); return ins; } else if (n == P.Obj.Tor) { Torus tor = new Torus(ele.Attributes[P.Srad].ToFloat(), ele.Attributes[P.Trad].ToFloat(), name); tor.SetShadows(shad); if (m != null) tor.SetMaterial(m); return tor; } else if (n == P.Obj.ConSph) { ConcaveSphere conc = new ConcaveSphere(ele.Attributes[P.Pos].ToVector3(), ele.Attributes[P.Rad].ToFloat(), name); conc.SetShadows(shad); if (m != null) conc.SetMaterial(m); return conc; } else if (n == P.Obj.ConHsph) { ConcaveHemisphere conc = new ConcaveHemisphere(ele.Attributes[P.Pos].ToVector3(), ele.Attributes[P.Rad].ToFloat(), name); conc.SetShadows(shad); if (m != null) conc.SetMaterial(m); return conc; } else if (n == P.Obj.Mesh) { Mesh mesh = new Mesh(name); mesh.SetShadows(shad); getVertices(mesh, ele); getNormals(mesh, ele); getFaces(mesh, ele); if (m != null) mesh.SetMaterial(m); return mesh; } else { return getCObject(ele); } }
public SmoothUVMeshTriangle(int i0, int i1, int i2, Mesh m, string name) : base(i0, i1, i2, m, name) { }