public IGeometricObjectElementCollide Clone(GeometricObjectCollide mesh) { GeometricObjectElementCollideTriangles sm = (GeometricObjectElementCollideTriangles)MemberwiseClone(); sm.geo = mesh; sm.Reset(); return(sm); }
public GeometricObjectCollide Clone() { GeometricObjectCollide m = (GeometricObjectCollide)MemberwiseClone(); m.Reset(); for (uint i = 0; i < m.num_elements; i++) { if (elements[i] != null) { m.elements[i] = elements[i].Clone(m); } } return(m); }
public GeometricObjectCollide Clone() { GeometricObjectCollide m = (GeometricObjectCollide)MemberwiseClone(); m.gao = new GameObject("Collide Set @ " + offset); m.gao.tag = "Collide"; m.elements = new IGeometricObjectElementCollide[num_elements]; for (uint i = 0; i < m.num_elements; i++) { if (elements[i] != null) { m.elements[i] = elements[i].Clone(m); } } for (uint i = 0; i < m.num_elements; i++) { if (m.elements[i] != null) { GameObject child = m.elements[i].Gao; child.transform.SetParent(m.gao.transform); child.transform.localPosition = Vector3.zero; /*if (m.subblocks[i] is CollideMeshElement) { * GameObject child = ((CollideMeshElement)m.subblocks[i]).Gao; * child.transform.SetParent(m.gao.transform); * child.transform.localPosition = Vector3.zero; * } else if (m.subblocks[i] is CollideSpheresElement) { * GameObject child = ((CollideSpheresElement)m.subblocks[i]).Gao; * child.transform.SetParent(m.gao.transform); * child.transform.localPosition = Vector3.zero; * } else if (m.subblocks[i] is CollideAlignedBoxesElement) { * GameObject child = ((CollideAlignedBoxesElement)m.subblocks[i]).Gao; * child.transform.SetParent(m.gao.transform); * child.transform.localPosition = Vector3.zero; * }*/ } } m.SetVisualsActive(false); // Invisible by default //m.gao.SetActive(false); // Invisible by default return(m); }
public GeometricObjectElementCollideTriangles(Pointer offset, GeometricObjectCollide geo) { this.geo = geo; this.offset = offset; }
public static GeometricObjectElementCollideTriangles Read(Reader reader, Pointer offset, GeometricObjectCollide geo) { MapLoader l = MapLoader.Loader; GeometricObjectElementCollideTriangles sm = new GeometricObjectElementCollideTriangles(offset, geo); sm.off_material = Pointer.Read(reader); if (Settings.s.game == Settings.Game.R2Revolution || Settings.s.game == Settings.Game.LargoWinch) { sm.num_triangles = reader.ReadUInt16(); reader.ReadUInt16(); sm.off_triangles = Pointer.Read(reader); if (Settings.s.game == Settings.Game.LargoWinch) { sm.off_normals = Pointer.Read(reader); sm.off_unk = Pointer.Read(reader); } } else { if (Settings.s.engineVersion < Settings.EngineVersion.R3) { sm.num_triangles = reader.ReadUInt16(); sm.num_mapping = reader.ReadUInt16(); sm.off_triangles = Pointer.Read(reader); sm.off_mapping = Pointer.Read(reader); sm.off_normals = Pointer.Read(reader); sm.off_uvs = Pointer.Read(reader); if (Settings.s.engineVersion == Settings.EngineVersion.Montreal) { reader.ReadUInt32(); } if (Settings.s.game != Settings.Game.TTSE) { Pointer.Read(reader); // table of num_unk vertex indices (vertices, because max = num_vertices - 1) reader.ReadUInt16(); // num_unk sm.ind_parallelBox = reader.ReadInt16(); } } else { sm.off_triangles = Pointer.Read(reader); sm.off_normals = Pointer.Read(reader); sm.num_triangles = reader.ReadUInt16(); sm.ind_parallelBox = reader.ReadInt16(); reader.ReadUInt32(); if (Settings.s.game != Settings.Game.Dinosaur) { sm.off_mapping = Pointer.Read(reader); sm.off_unk = Pointer.Read(reader); // num_mapping_entries * 3 floats sm.off_unk2 = Pointer.Read(reader); // num_mapping_entries * 1 float sm.num_mapping = reader.ReadUInt16(); reader.ReadUInt16(); } } } if (!geo.isBoundingVolume) { if (sm.off_material != null) { sm.gameMaterial = GameMaterial.FromOffsetOrRead(sm.off_material, reader); } } else { // Sector superobject } Pointer.Goto(ref reader, sm.off_triangles); sm.triangles = new int[sm.num_triangles * 3]; for (int j = 0; j < sm.num_triangles; j++) { sm.triangles[(j * 3) + 0] = reader.ReadInt16(); sm.triangles[(j * 3) + 1] = reader.ReadInt16(); sm.triangles[(j * 3) + 2] = reader.ReadInt16(); } Pointer.DoAt(ref reader, sm.off_normals, () => { sm.normals = new Vector3[sm.num_triangles]; for (int j = 0; j < sm.num_triangles; j++) { float x = reader.ReadSingle(); float z = reader.ReadSingle(); float y = reader.ReadSingle(); sm.normals[j] = new Vector3(x, y, z); } }); if (sm.num_mapping > 0 && sm.off_mapping != null) { Pointer.Goto(ref reader, sm.off_mapping); sm.mapping = new int[sm.num_triangles * 3]; for (int i = 0; i < sm.num_triangles; i++) { sm.mapping[(i * 3) + 0] = reader.ReadInt16(); sm.mapping[(i * 3) + 1] = reader.ReadInt16(); sm.mapping[(i * 3) + 2] = reader.ReadInt16(); } if (sm.off_uvs != null) { Pointer.Goto(ref reader, sm.off_uvs); sm.uvs = new Vector2[sm.num_mapping]; for (int i = 0; i < sm.num_mapping; i++) { sm.uvs[i] = new Vector2(reader.ReadSingle(), reader.ReadSingle()); } } } /*R3Pointer.Goto(ref reader, sm.off_mapping); * sm.mapping = new int[sm.num_triangles * 3]; * for (int j = 0; j < sm.num_triangles; j++) { * sm.mapping[(j * 3) + 0] = reader.ReadInt16(); * sm.mapping[(j * 3) + 1] = reader.ReadInt16(); * sm.mapping[(j * 3) + 2] = reader.ReadInt16(); * } * R3Pointer.Goto(ref reader, sm.off_unk); * sm.normals = new Vector3[sm.num_mapping_entries]; * for (int j = 0; j < sm.num_mapping_entries; j++) { * float x = reader.ReadSingle(); * float z = reader.ReadSingle(); * float y = reader.ReadSingle(); * sm.normals[j] = new Vector3(x, y, z); * }*/ return(sm); }
public static GeometricObjectElementCollideSpheres Read(Reader reader, Pointer offset, GeometricObjectCollide geo) { MapLoader l = MapLoader.Loader; GeometricObjectElementCollideSpheres s = new GeometricObjectElementCollideSpheres(offset, geo); if (Settings.s.engineVersion > Settings.EngineVersion.Montreal) { s.off_spheres = Pointer.Read(reader); s.num_spheres = reader.ReadUInt16(); s.ind_parallelBox = reader.ReadInt16(); // -1 } else { s.num_spheres = (ushort)reader.ReadUInt32(); s.off_spheres = Pointer.Read(reader); } if (s.off_spheres != null) { Pointer off_current = Pointer.Goto(ref reader, s.off_spheres); s.spheres = new IndexedSphere[s.num_spheres]; for (uint i = 0; i < s.num_spheres; i++) { s.spheres[i] = new IndexedSphere(); if (Settings.s.engineVersion > Settings.EngineVersion.Montreal) { s.spheres[i].debug_radiusAddress = Pointer.Current(reader); s.spheres[i].radius = reader.ReadSingle(); s.spheres[i].off_material = Pointer.Read(reader); s.spheres[i].centerPoint = reader.ReadUInt16(); reader.ReadUInt16(); } else { s.spheres[i].centerPoint = reader.ReadUInt16(); reader.ReadUInt16(); s.spheres[i].debug_radiusAddress = Pointer.Current(reader); s.spheres[i].radius = reader.ReadSingle(); s.spheres[i].off_material = Pointer.Read(reader); } if (!geo.isBoundingVolume) { s.spheres[i].gameMaterial = GameMaterial.FromOffsetOrRead(s.spheres[i].off_material, reader); } } Pointer.Goto(ref reader, off_current); } return(s); }
public static GeometricObjectCollide Read(Reader reader, Pointer offset, CollideType type = CollideType.None) { MapLoader l = MapLoader.Loader; //l.print("CollideMesh " + offset); GeometricObjectCollide m = new GeometricObjectCollide(offset, type); //l.print("Mesh obj: " + offset); if (Settings.s.engineVersion == Settings.EngineVersion.R3 || Settings.s.game == Settings.Game.R2Revolution) { m.num_vertices = reader.ReadUInt16(); m.num_elements = reader.ReadUInt16(); if (Settings.s.engineVersion == Settings.EngineVersion.R3 && Settings.s.game != Settings.Game.LargoWinch) { reader.ReadUInt32(); } } if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal) { m.num_vertices = (ushort)reader.ReadUInt32(); } m.off_vertices = Pointer.Read(reader); if (Settings.s.engineVersion < Settings.EngineVersion.R3 && Settings.s.game != Settings.Game.R2Revolution) { m.off_normals = Pointer.Read(reader); Pointer.Read(reader); reader.ReadInt32(); } if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal) { m.num_elements = (ushort)reader.ReadUInt32(); } m.off_element_types = Pointer.Read(reader); m.off_elements = Pointer.Read(reader); if (Settings.s.game != Settings.Game.R2Revolution && Settings.s.game != Settings.Game.LargoWinch) { Pointer.Read(reader); if (Settings.s.engineVersion == Settings.EngineVersion.R2) { reader.ReadInt32(); reader.ReadInt32(); reader.ReadInt32(); reader.ReadInt32(); m.num_vertices = reader.ReadUInt16(); m.num_elements = reader.ReadUInt16(); } if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal) { reader.ReadInt32(); reader.ReadInt32(); } } reader.ReadInt32(); reader.ReadSingle(); reader.ReadSingle(); reader.ReadSingle(); reader.ReadSingle(); if (Settings.s.engineVersion < Settings.EngineVersion.R3) { reader.ReadUInt32(); } // Vertices Pointer off_current = Pointer.Goto(ref reader, m.off_vertices); m.vertices = new Vector3[m.num_vertices]; for (int i = 0; i < m.num_vertices; i++) { float x = reader.ReadSingle(); float z = reader.ReadSingle(); float y = reader.ReadSingle(); m.vertices[i] = new Vector3(x, y, z); } // Normals if (m.off_normals != null) { off_current = Pointer.Goto(ref reader, m.off_normals); m.normals = new Vector3[m.num_vertices]; for (int i = 0; i < m.num_vertices; i++) { float x = reader.ReadSingle(); float z = reader.ReadSingle(); float y = reader.ReadSingle(); m.normals[i] = new Vector3(x, y, z); } } // Read subblock types & initialize arrays Pointer.Goto(ref reader, m.off_element_types); m.element_types = new ushort[m.num_elements]; m.elements = new IGeometricObjectElementCollide[m.num_elements]; for (uint i = 0; i < m.num_elements; i++) { m.element_types[i] = reader.ReadUInt16(); } m.gao = new GameObject("Collide Set " + (type != CollideType.None ? type + " " : "") + "@ " + offset); m.gao.tag = "Collide"; m.gao.layer = LayerMask.NameToLayer("Collide"); for (uint i = 0; i < m.num_elements; i++) { Pointer.Goto(ref reader, m.off_elements + (i * 4)); Pointer block_offset = Pointer.Read(reader); Pointer.Goto(ref reader, block_offset); switch (m.element_types[i]) { /*1 = indexedtriangles * 2 = facemap * 3 = sprite * 4 = TMesh * 5 = points * 6 = lines * 7 = spheres * 8 = alignedboxes * 9 = cones * 13 = deformationsetinfo*/ case 1: // Collide submesh m.elements[i] = GeometricObjectElementCollideTriangles.Read(reader, block_offset, m); //material_i++; break; case 7: m.elements[i] = GeometricObjectElementCollideSpheres.Read(reader, block_offset, m); break; case 8: m.elements[i] = GeometricObjectElementCollideAlignedBoxes.Read(reader, block_offset, m); break; default: m.elements[i] = null; l.print("Unknown collide geometric element type " + m.element_types[i] + " at offset " + block_offset + " (Object: " + offset + ")"); break; } } for (uint i = 0; i < m.num_elements; i++) { if (m.elements[i] != null) { GameObject child = m.elements[i].Gao; child.transform.SetParent(m.gao.transform); child.transform.localPosition = Vector3.zero; /*if (m.subblocks[i] is CollideMeshElement) { * GameObject child = ((CollideMeshElement)m.subblocks[i]).Gao; * child.transform.SetParent(m.gao.transform); * child.transform.localPosition = Vector3.zero; * } else if (m.subblocks[i] is CollideSpheresElement) { * GameObject child = ((CollideSpheresElement)m.subblocks[i]).Gao; * child.transform.SetParent(m.gao.transform); * child.transform.localPosition = Vector3.zero; * } else if (m.subblocks[i] is CollideAlignedBoxesElement) { * GameObject child = ((CollideAlignedBoxesElement)m.subblocks[i]).Gao; * child.transform.SetParent(m.gao.transform); * child.transform.localPosition = Vector3.zero; * }*/ } } m.SetVisualsActive(false); // Invisible by default //m.gao.SetActive(false); // Invisible by default return(m); }
public static CollSet Read(Reader reader, Perso perso, Pointer offset) { MapLoader l = MapLoader.Loader; //if (Settings.s.platform == Settings.Platform.DC) return null; //l.print("CollSet @ " + offset); CollSet c = new CollSet(perso, offset); c.off_zdxList[CollideType.ZDD] = Pointer.Read(reader); c.off_zdxList[CollideType.ZDE] = Pointer.Read(reader); c.off_zdxList[CollideType.ZDM] = Pointer.Read(reader); c.off_zdxList[CollideType.ZDR] = Pointer.Read(reader); c.off_activationList[CollideType.ZDD] = Pointer.Read(reader); c.off_activationList[CollideType.ZDE] = Pointer.Read(reader); c.off_activationList[CollideType.ZDM] = Pointer.Read(reader); c.off_activationList[CollideType.ZDR] = Pointer.Read(reader); c.off_zones[CollideType.ZDD] = Pointer.Read(reader); c.off_zones[CollideType.ZDE] = Pointer.Read(reader); c.off_zones[CollideType.ZDM] = Pointer.Read(reader); c.off_zones[CollideType.ZDR] = Pointer.Read(reader); if (Settings.s.engineVersion > Settings.EngineVersion.Montreal) { c.privilegedActivations[CollideType.ZDD] = reader.ReadInt32(); c.privilegedActivations[CollideType.ZDE] = reader.ReadInt32(); c.privilegedActivations[CollideType.ZDM] = reader.ReadInt32(); c.privilegedActivations[CollideType.ZDR] = reader.ReadInt32(); } foreach (KeyValuePair <CollideType, Pointer> entry in c.off_zdxList) { Pointer.DoAt(ref reader, entry.Value, () => { //zdxList = LinkedList<CollideMeshObject>.ReadHeader(r1, o1); c.zdxList[entry.Key] = LinkedList <GeometricObjectCollide> .Read(ref reader, entry.Value, (off_element) => { GeometricObjectCollide col = GeometricObjectCollide.Read(reader, off_element, type: entry.Key); col.gao.transform.SetParent(perso.Gao.transform); return(col); }, flags: LinkedList.Flags.ReadAtPointer | (Settings.s.hasLinkedListHeaderPointers ? LinkedList.Flags.HasHeaderPointers : LinkedList.Flags.NoPreviousPointersForDouble), type: LinkedList.Type.Minimize ); }); } foreach (KeyValuePair <CollideType, Pointer> entry in c.off_zones) { Pointer.DoAt(ref reader, entry.Value, () => { //zdxList = LinkedList<CollideMeshObject>.ReadHeader(r1, o1); c.zones[entry.Key] = LinkedList <CollideActivationZone> .Read(ref reader, entry.Value, (off_element) => { return(CollideActivationZone.Read(reader, off_element)); }, flags: (Settings.s.hasLinkedListHeaderPointers ? LinkedList.Flags.HasHeaderPointers : LinkedList.Flags.NoPreviousPointersForDouble), type: LinkedList.Type.Minimize ); }); } foreach (KeyValuePair <CollideType, Pointer> entry in c.off_activationList) { Pointer.DoAt(ref reader, entry.Value, () => { //zdxList = LinkedList<CollideMeshObject>.ReadHeader(r1, o1); c.activationList[entry.Key] = LinkedList <CollideActivation> .Read(ref reader, entry.Value, (off_element) => { return(CollideActivation.Read(reader, off_element, c, entry.Key)); }, flags: (Settings.s.hasLinkedListHeaderPointers ? LinkedList.Flags.HasHeaderPointers : LinkedList.Flags.NoPreviousPointersForDouble), type: LinkedList.Type.Minimize ); }); } return(c); }
public static GeometricObjectCollide Read(Reader reader, Pointer offset, CollideType type = CollideType.None, bool isBoundingVolume = false) { MapLoader l = MapLoader.Loader; //l.print("CollideMesh " + offset); GeometricObjectCollide m = new GeometricObjectCollide(offset, type); m.isBoundingVolume = isBoundingVolume; if (Settings.s.engineVersion == Settings.EngineVersion.R3 || Settings.s.game == Settings.Game.R2Revolution) { m.num_vertices = reader.ReadUInt16(); m.num_elements = reader.ReadUInt16(); if (Settings.s.engineVersion == Settings.EngineVersion.R3 && Settings.s.game != Settings.Game.LargoWinch) { reader.ReadUInt32(); } } if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal) { m.num_vertices = (ushort)reader.ReadUInt32(); } m.off_vertices = Pointer.Read(reader); if (Settings.s.engineVersion < Settings.EngineVersion.R3 && Settings.s.game != Settings.Game.R2Revolution) { m.off_normals = Pointer.Read(reader); Pointer.Read(reader); reader.ReadInt32(); } if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal) { m.num_elements = (ushort)reader.ReadUInt32(); } m.off_element_types = Pointer.Read(reader); m.off_elements = Pointer.Read(reader); if (Settings.s.game != Settings.Game.R2Revolution && Settings.s.game != Settings.Game.LargoWinch) { Pointer.Read(reader); if (Settings.s.engineVersion < Settings.EngineVersion.R3) { if (Settings.s.engineVersion == Settings.EngineVersion.R2) { reader.ReadInt32(); reader.ReadInt32(); reader.ReadInt32(); reader.ReadInt32(); m.num_vertices = reader.ReadUInt16(); m.num_elements = reader.ReadUInt16(); } if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal) { reader.ReadInt32(); reader.ReadInt32(); } reader.ReadUInt16(); m.num_parallelBoxes = reader.ReadUInt16(); } else { //l.print((Pointer.Current(reader).FileOffset - offset.FileOffset)); m.off_parallelBoxes = Pointer.Read(reader); } } else { reader.ReadUInt32(); } if (Settings.s.engineVersion != Settings.EngineVersion.Montreal) { m.sphereRadius = reader.ReadSingle(); // bounding volume radius float sphereX = reader.ReadSingle(); // x float sphereZ = reader.ReadSingle(); // z float sphereY = reader.ReadSingle(); // y m.sphereCenter = new Vector3(sphereX, sphereY, sphereZ); if (Settings.s.engineVersion == Settings.EngineVersion.R2) { reader.ReadUInt32(); } } // Vertices Pointer off_current = Pointer.Goto(ref reader, m.off_vertices); m.vertices = new Vector3[m.num_vertices]; for (int i = 0; i < m.num_vertices; i++) { float x = reader.ReadSingle(); float z = reader.ReadSingle(); float y = reader.ReadSingle(); m.vertices[i] = new Vector3(x, y, z); } // Normals if (m.off_normals != null) { off_current = Pointer.Goto(ref reader, m.off_normals); m.normals = new Vector3[m.num_vertices]; for (int i = 0; i < m.num_vertices; i++) { float x = reader.ReadSingle(); float z = reader.ReadSingle(); float y = reader.ReadSingle(); m.normals[i] = new Vector3(x, y, z); } } // Read subblock types & initialize arrays Pointer.Goto(ref reader, m.off_element_types); m.element_types = new ushort[m.num_elements]; m.elements = new IGeometricObjectElementCollide[m.num_elements]; for (uint i = 0; i < m.num_elements; i++) { m.element_types[i] = reader.ReadUInt16(); } for (uint i = 0; i < m.num_elements; i++) { Pointer.Goto(ref reader, m.off_elements + (i * 4)); Pointer block_offset = Pointer.Read(reader); Pointer.Goto(ref reader, block_offset); switch (m.element_types[i]) { /*1 = indexedtriangles * 2 = facemap * 3 = sprite * 4 = TMesh * 5 = points * 6 = lines * 7 = spheres * 8 = alignedboxes * 9 = cones * 13 = deformationsetinfo*/ case 1: // Collide submesh m.elements[i] = GeometricObjectElementCollideTriangles.Read(reader, block_offset, m); //material_i++; break; case 7: m.elements[i] = GeometricObjectElementCollideSpheres.Read(reader, block_offset, m); break; case 8: m.elements[i] = GeometricObjectElementCollideAlignedBoxes.Read(reader, block_offset, m); break; default: m.elements[i] = null; l.print("Unknown collide geometric element type " + m.element_types[i] + " at offset " + block_offset + " (Object: " + offset + ")"); break; } } return(m); }
public GeometricObjectElementCollideAlignedBoxes(Pointer offset, GeometricObjectCollide geo) { this.geo = geo; this.offset = offset; }
public static GeometricObjectElementCollideAlignedBoxes Read(Reader reader, Pointer offset, GeometricObjectCollide geo) { MapLoader l = MapLoader.Loader; GeometricObjectElementCollideAlignedBoxes s = new GeometricObjectElementCollideAlignedBoxes(offset, geo); if (Settings.s.engineVersion > Settings.EngineVersion.Montreal) { s.off_boxes = Pointer.Read(reader); s.num_boxes = reader.ReadUInt16(); reader.ReadInt16(); // -1 } else { s.num_boxes = (ushort)reader.ReadUInt32(); s.off_boxes = Pointer.Read(reader); } if (s.off_boxes != null) { Pointer off_current = Pointer.Goto(ref reader, s.off_boxes); s.boxes = new IndexedAlignedBox[s.num_boxes]; for (uint i = 0; i < s.num_boxes; i++) { s.boxes[i] = new IndexedAlignedBox(); s.boxes[i].minPoint = reader.ReadUInt16(); s.boxes[i].maxPoint = reader.ReadUInt16(); s.boxes[i].off_material = Pointer.Read(reader); s.boxes[i].gameMaterial = GameMaterial.FromOffsetOrRead(s.boxes[i].off_material, reader); } Pointer.Goto(ref reader, off_current); } return(s); }