public static void MQJsonImportAndPatch(IExperimentFace face, List <string> filePath) { Rom n0 = new ORom(filePath[0], ORom.Build.N0); Rom mq = new ORom(filePath[1], ORom.Build.MQU); List <Scene_MQJson> scenes = Load_Scene_MQJson(); foreach (var scene in scenes) { if (!MQRandoScenes.Contains(scene.Id)) { continue; } var n0_scene = SceneRoomReader.InitializeScene(n0, scene.Id); var mq_scene = SceneRoomReader.InitializeScene(mq, scene.Id); CollisionMesh n0_mesh = ((CollisionCommand)n0_scene.Header[HeaderCommands.Collision]).Mesh; CollisionMesh mq_mesh = ((CollisionCommand)mq_scene.Header[HeaderCommands.Collision]).Mesh; var delta = new Col_MQJson(n0_mesh, mq_mesh); scene.ColDelta = delta; } MemoryStream s = SerializeScenes(scenes); StreamReader sr = new StreamReader(s); face.OutputText(sr.ReadToEnd()); }
public void CompleteBBox(CollisionMesh ent2) { ent2.BoundingBox = ent2.Collisions .Where(collision => collision.BoundingBox != BoundingBoxInt16.Invalid) .Select(x => x.BoundingBox) .MergeAll(); }
/// <summary> /// Animates the camera from its current position towards the desired offset /// behind the chased object. The camera's animation is controlled by a simple /// physical spring attached to the camera and anchored to the desired position. /// </summary> public void Update(float elapsedTime, CollisionMesh collision) { UpdateWorldPositions(); // Calculate spring force Vector3 stretch = position - desiredPosition; Vector3 force = -stiffness * stretch - damping * velocity; // Apply acceleration Vector3 acceleration = force / mass; velocity += acceleration * elapsedTime; // Apply velocity position += velocity * elapsedTime; collisionPosition = position; // test camera for collision with world if (collision != null) { float collisionDistance; Vector3 collisionPoint, collisionNormal; if (collision.PointIntersect(lookAt, position, out collisionDistance, out collisionPoint, out collisionNormal)) { Vector3 dir = Vector3.Normalize(collisionPoint - lookAt); collisionPosition = collisionPoint - 10 * dir; } } UpdateMatrices(); }
public override void ButtonClicked(Vector2 position) { _mouseClicked.X = Convert.ToInt32(position.X); _mouseClicked.Y = Convert.ToInt32(position.Y); if (CollisionMesh.Contains(_mouseClicked)) { _click(); } }
public void CompleteBBox(CollisionMesh ent2) { ent2.BoundingBox = Enumerable.Range( ent2.CollisionStart, ent2.CollisionEnd - ent2.CollisionStart ) .Select(index => coct.CollisionList[index].BoundingBoxIndex) .Where(co6Index => co6Index != -1) .Select(co6Index => coct.BoundingBoxList[co6Index]) .MergeAll(); }
public Col_MQJson(CollisionMesh n0, CollisionMesh mq) { IsLarger = (n0.GetFileSize() < mq.GetFileSize()); for (int i = 0; i < mq.PolyList.Count; i++) { var n0poly = n0.PolyList[i]; var mqpoly = mq.PolyList[i]; if (!n0poly.Equals(mqpoly)) { Polys.Add(new ColPoly_MQJson(i, mqpoly.Type, mqpoly.VertexFlagsA)); } } for (int i = 0; i < mq.PolyTypeList.Count; i++) { var mqpolytype = mq.PolyTypeList[i]; if (!(i < n0.PolyTypeList.Count) || !n0.PolyTypeList[i].Equals(mqpolytype)) { PolyTypes.Add(new ColMat_MQJson(i, mqpolytype.HighWord, mqpolytype.LowWord)); } } for (int i = 0; i < mq.CameraDataList.Count; i++) { var mqcam = mq.CameraDataList[i]; ColCam_MQJson cam = null; if (mqcam.PositionAddress == 0) { cam = new ColCam_MQJson(mqcam.CameraS, mqcam.NumCameras, -1); } else { for (int j = 0; j < n0.CameraDataList.Count; j++) { var n0cam = n0.CameraDataList[j]; if (n0cam.IsPositionListIdentical(mqcam)) { cam = new ColCam_MQJson(mqcam.CameraS, mqcam.NumCameras, j); break; } } } if (cam == null) { throw new Exception("BLERG"); } Cams.Add(cam); } }
public DebugRenderMesh(GraphicsDevice device, CollisionMesh cm) { VertexPositionColor[] vertices = new VertexPositionColor[cm.Vertices.Length]; int[] indices = new int[cm.Indices.Length]; for (int i = 0; i < vertices.Length; i++) vertices[i] = new VertexPositionColor(cm.Vertices[i], Color.LightGray); cm.Indices.CopyTo(indices, 0); vertexBuffer = new VertexBuffer(device, typeof(VertexPositionColor), vertices.Length, BufferUsage.None); vertexBuffer.SetData<VertexPositionColor>(vertices); indexBuffer = new IndexBuffer(device, IndexElementSize.ThirtyTwoBits, indices.Length, BufferUsage.None); indexBuffer.SetData<int>(indices); }
static int Main(string[] args) { TestBench.StartLogging(ELogType.Warning); var lvls = TestBench.LoadAndTrackLVLs(new List <string>(args)); for (int i = 0; i < lvls.Count; i++) { Console.WriteLine("Level {0}'s collision meshes: ", i); var level = lvls[i]; Model[] models = level.GetModels(); foreach (Model model in models) { Console.WriteLine("\n\tModel: " + model.name); CollisionMesh mesh = model.GetCollisionMesh(); if (mesh == null) { continue; } Console.WriteLine("\t\tCollision mask flags: {0}", mesh.maskFlags); Console.WriteLine("\t\tNum collision indices: {0}", mesh.GetIndices().Length); Console.WriteLine("\t\tNum collision verticies: {0}", mesh.GetVertices <Vector3>().Length); CollisionPrimitive[] prims = model.GetPrimitivesMasked(16); Console.WriteLine("\t\t{0} Primitives: ", prims.Length); foreach (var prim in prims) { Console.WriteLine("\t\t\tName: {0} Parent: {1}", prim.name, prim.parentName); } } } TestBench.StopLogging(); return(0); }
/// <summary> /// Initializes a new instance of the <see cref="coll"/> class. /// </summary> /// <param name="meta">The meta.</param> /// <remarks></remarks> public coll(ref Meta meta) { BinaryReader BR = new BinaryReader(meta.MS); BR.BaseStream.Position = 28; int tempc = BR.ReadInt32(); int tempr = BR.ReadInt32() - meta.magic - meta.offset; for (int xxx = 0; xxx < tempc; xxx++) { BR.BaseStream.Position = tempr + (xxx * 12); string index1string = meta.Map.Strings.Name[BR.ReadUInt16()]; BR.BaseStream.Position = tempr + (xxx * 12) + 4; int tempcxx = BR.ReadInt32(); int temprxx = BR.ReadInt32() - meta.magic - meta.offset; for (int xx = 0; xx < tempcxx; xx++) { BR.BaseStream.Position = temprxx + (xx * 20); string index2string = meta.Map.Strings.Name[BR.ReadUInt16()]; BR.BaseStream.Position = temprxx + (xx * 20) + 4; int tempcx = BR.ReadInt32(); int temprx = BR.ReadInt32() - meta.magic - meta.offset; // Meshes = new CollisionMesh[tempc]; for (int x = 0; x < tempcx; x++) { CollisionMesh cm = new CollisionMesh(); cm.index1 = xxx; cm.index1string = index1string; cm.index2 = xx; cm.index2string = index2string; if (ConditionStrings.IndexOf(cm.index2string) == -1) { ConditionStrings.Add(cm.index2string); } cm.index3 = x; BR.BaseStream.Position = temprx + (x * 68) + 52; int tempc2 = BR.ReadInt32(); int tempr2 = BR.ReadInt32() - meta.magic - meta.offset; cm.Faces = new ushort[tempc2 * 3]; for (int y = 0; y < tempc2; y++) { BR.BaseStream.Position = tempr2 + (y * 12); cm.Faces[y * 3] = BR.ReadUInt16(); cm.Faces[(y * 3) + 1] = BR.ReadUInt16(); cm.Faces[(y * 3) + 2] = cm.Faces[(y * 3) + 1]; // BR.ReadUInt16(); } // ***** Test Code ****// BR.BaseStream.Position = temprx + (x * 68) + 12; tempc2 = BR.ReadInt32(); tempr2 = BR.ReadInt32() - meta.magic - meta.offset; cm.Normals = new Vector4[tempc2]; for (int y = 0; y < tempc2; y++) { BR.BaseStream.Position = tempr2 + (y * 16) + 0; cm.Normals[y].X = BR.ReadSingle(); cm.Normals[y].Y = BR.ReadSingle(); cm.Normals[y].Z = BR.ReadSingle(); cm.Normals[y].W = BR.ReadSingle(); } BR.BaseStream.Position = temprx + (x * 68) + 44; tempc2 = BR.ReadInt32(); tempr2 = BR.ReadInt32() - meta.magic - meta.offset; cm.SurfaceData = new surfaceData[tempc2]; for (int y = 0; y < tempc2; y++) { BR.BaseStream.Position = tempr2 + (y * 8) + 0; cm.SurfaceData[y] = new surfaceData(); cm.SurfaceData[y].Plane = BR.ReadInt16(); } BR.BaseStream.Position = temprx + (x * 68) + 52; tempc2 = BR.ReadInt32(); tempr2 = BR.ReadInt32() - meta.magic - meta.offset; int[] startEdges = new int[tempc2]; int[] endEdges = new int[tempc2]; int[] forwardEdges = new int[tempc2]; int[] reverseEdges = new int[tempc2]; int[] face1 = new int[tempc2]; int[] face2 = new int[tempc2]; for (int y = 0; y < tempc2; y++) { BR.BaseStream.Position = tempr2 + (y * 12) + 0; startEdges[y] = BR.ReadUInt16(); endEdges[y] = BR.ReadUInt16(); BR.BaseStream.Position = tempr2 + (y * 12) + 4; forwardEdges[y] = BR.ReadUInt16(); reverseEdges[y] = BR.ReadUInt16(); BR.BaseStream.Position = tempr2 + (y * 12) + 8; face1[y] = BR.ReadUInt16(); face2[y] = BR.ReadUInt16(); } for (int y = 0; y < forwardEdges.Length; y++) { int cSurface = face1[y]; if (cm.SurfaceData[cSurface].Vertices == null) { cm.SurfaceData[cSurface].Vertices = new List<int>(); int edge = y; int nextEdge = 0; cm.SurfaceData[cSurface].Vertices.Add(startEdges[edge]); do { if (cSurface == face1[edge]) { cm.SurfaceData[cSurface].Vertices.Add(endEdges[edge]); edge = forwardEdges[edge]; } else if (cSurface == face2[edge]) { cm.SurfaceData[cSurface].Vertices.Add(startEdges[edge]); edge = reverseEdges[edge]; } if (cSurface == face1[edge]) { nextEdge = endEdges[edge]; } else if (cSurface == face2[edge]) { nextEdge = startEdges[edge]; } } while (!cm.SurfaceData[cSurface].Vertices.Contains(nextEdge)); } } for (int y = 0; y < reverseEdges.Length; y++) { int cSurface = face2[y]; if (cm.SurfaceData[cSurface].Vertices == null) { cm.SurfaceData[cSurface].Vertices = new List<int>(); int edge = y; int nextEdge = 0; cm.SurfaceData[cSurface].Vertices.Add(endEdges[edge]); do { if (cSurface == face1[edge]) { cm.SurfaceData[cSurface].Vertices.Add(endEdges[edge]); edge = forwardEdges[edge]; } else if (cSurface == face2[edge]) { cm.SurfaceData[cSurface].Vertices.Add(startEdges[edge]); edge = reverseEdges[edge]; } if (cSurface == face1[edge]) { nextEdge = endEdges[edge]; } else if (cSurface == face2[edge]) { nextEdge = startEdges[edge]; } } while (!cm.SurfaceData[cSurface].Vertices.Contains(nextEdge)); } } // ***** End Test Code ****// BR.BaseStream.Position = temprx + (x * 68) + 60; tempc2 = BR.ReadInt32(); tempr2 = BR.ReadInt32() - meta.magic - meta.offset; // Meshes[x] = new CollisionMesh(); cm.Vertices = new Vector3[tempc2]; for (int y = 0; y < tempc2; y++) { BR.BaseStream.Position = tempr2 + (y * 16); cm.Vertices[y].X = BR.ReadSingle(); cm.Vertices[y].Y = BR.ReadSingle(); cm.Vertices[y].Z = BR.ReadSingle(); } Meshes.Add(cm); } } } BR.BaseStream.Position = 36; tempc = BR.ReadInt32(); tempr = BR.ReadInt32() - meta.magic - meta.offset; for (int xxx = 0; xxx < tempc; xxx++) { BR.BaseStream.Position = tempr + (20 * xxx); PathfindingSphere ps = new PathfindingSphere(); ps.nodeindex = BR.ReadInt32(); ps.position = new Vector3(); ps.position.X = BR.ReadSingle(); ps.position.Y = BR.ReadSingle(); ps.position.Z = BR.ReadSingle(); ps.radius = BR.ReadSingle(); Spheres.Add(ps); } }
/// <summary> /// Updates the player ship for given elapsed time /// </summary> public void Update( float elapsedTime, // elapsed time on this frame CollisionMesh collision, // level collision mesh EntityList entities) // level spawn points { if (collision == null) { throw new ArgumentNullException("collision"); } if (entities == null) { throw new ArgumentNullException("entities"); } // updates damage screen time (zero for no damage indication) damageTime = Math.Max(0.0f, damageTime - elapsedTime); // if player dead if (IsAlive == false) { // disable engine particle system particleBoost.Enabled = false; // updates dead time (if zero, player is alive) deadTime = Math.Max(0.0f, deadTime - elapsedTime); // if player dead time expires, respawn if (IsAlive == true) { // reset player to a random spawn point Reset(entities.GetTransformRandom(random)); // add spawn animated sprite in front of player Vector3 Pos = movement.position + 10 * movement.rotation.Forward; gameManager.AddAnimSprite(AnimSpriteType.Spawn, Pos, 140, 80, 30, DrawMode.Additive, playerIndex); // play spawn sound gameManager.PlaySound("ship_spawn"); // reset energy, shield and boost energy = 1.0f; shield = 1.0f; boost = 1.0f; missileCount = 3; } return; } // hold position before movement Vector3 lastPostion = movement.position; // update movement movement.Update(elapsedTime); // test for collision with level Vector3 collisionPosition; if (collision.BoxMove(box, lastPostion, movement.position, 1.0f, 0.0f, 3, out collisionPosition)) { // update to valid position after collision movement.position = collisionPosition; // compute new velocity after collision Vector3 newVelocity = (collisionPosition - lastPostion) * (1.0f / elapsedTime); // if collision sound enabled if (collisionSound) { // test collision angle to play collision sound Vector3 WorldVel = movement.WorldVelocity; float dot = Vector3.Dot( Vector3.Normalize(WorldVel), Vector3.Normalize(newVelocity)); if (dot < 0.7071f) { // play collision sound gameManager.PlaySound("ship_collide"); // set rumble intensity dot = 1 - 0.5f * (dot + 1); gameManager.SetVibration(playerIndex, dot * 0.5f); // disable collision sounds until ship stops colliding collisionSound = false; } } // set new velocity after collision movement.WorldVelocity = newVelocity; } else { // clear of collisions, re-enable collision sounds collisionSound = true; } // update player transform transform = movement.rotation; transform.Translation = movement.position; // compute inverse transform transformInverse = Matrix.Invert(transform); // get normalized player velocity float velocityFactor = movement.VelocityFactor; // update bobbing bobbingTime += elapsedTime; float bobbingFactor = 1.0f - velocityFactor; float time = GameOptions.ShipBobbingSpeed * bobbingTime % (2 * MathHelper.TwoPi); float distance = bobbingFactor * GameOptions.ShipBobbingRange; bobbing.M41 = distance * (float)Math.Sin(time * 0.5f); bobbing.M42 = distance * (float)Math.Sin(time); bobbingInverse.M41 = -bobbing.M41; bobbingInverse.M42 = -bobbing.M42; // compute transform with bobbing Matrix bobbingTransform = bobbing * transform; // update particle system position particleBoost.Enabled = true; particleBoost.SetTransform(boostTransform * bobbingTransform); // if shield active if (shieldUse) { // update shield position animatedSpriteShield.Position = bobbingTransform.Translation + 10f * bobbingTransform.Forward; // update shiled charge shield -= elapsedTime / GameOptions.ShieldUse; // if shield charge depleted if (shield < 0) { // disable shield shieldUse = false; shield = 0; // kill shield animated sprite animatedSpriteShield.SetTotalTime(0); animatedSpriteShield = null; } } else { // change shield shield = Math.Min(1.0f, shield + elapsedTime / GameOptions.ShieldRecharge); } // if boost active if (boostUse) { // increase ship maximum velocity movement.maxVelocity = GameOptions.MovementVelocityBoost; // apply impulse force forward AddImpulseForce(transform.Forward * GameOptions.BoostForce); // set particle system velocity scale particleBoost.VelocityScale = Math.Min(1.0f, particleBoost.VelocityScale + 4.0f * elapsedTime); // update shield charge boost -= elapsedTime / GameOptions.BoostUse; // if boost depleated if (boost < 0) { // disable boost boostUse = false; boost = 0; } } else { // slowly returns ship maximum velocity to normal levels if (movement.maxVelocity > GameOptions.MovementVelocity) { movement.maxVelocity -= GameOptions.BoostSlowdown * elapsedTime; } // slowly returns particle system velocity scale to normal levels particleBoost.VelocityScale = Math.Max(0.1f, particleBoost.VelocityScale - 2.0f * elapsedTime); // charge boost boost = Math.Min(1.0f, boost + elapsedTime / GameOptions.BoostRecharge); } // charge blaster blaster = Math.Min(1.0f, blaster + elapsedTime / GameOptions.BlasterChargeTime); // charge missile missile = Math.Min(1.0f, missile + elapsedTime / GameOptions.MissileChargeTime); // update chase camera chaseCamera.ChasePosition = transform.Translation; chaseCamera.ChaseDirection = transform.Forward; chaseCamera.Up = transform.Up; chaseCamera.Update(elapsedTime, collision); }
public CollisionMesh Complete(CollisionMesh it) { buildHelper.CompleteBBox(it); return(it); }
public Map() { //Rooms = new List<Room>(); Objects = new MapObjectContainer(); MapCollision = new CollisionMesh(); }
/// <summary> /// Initializes a new instance of the <see cref="coll"/> class. /// </summary> /// <param name="meta">The meta.</param> /// <remarks></remarks> public coll(ref Meta meta) { BinaryReader BR = new BinaryReader(meta.MS); BR.BaseStream.Position = 28; int tempc = BR.ReadInt32(); int tempr = BR.ReadInt32() - meta.magic - meta.offset; for (int xxx = 0; xxx < tempc; xxx++) { BR.BaseStream.Position = tempr + (xxx * 12); string index1string = meta.Map.Strings.Name[BR.ReadUInt16()]; BR.BaseStream.Position = tempr + (xxx * 12) + 4; int tempcxx = BR.ReadInt32(); int temprxx = BR.ReadInt32() - meta.magic - meta.offset; for (int xx = 0; xx < tempcxx; xx++) { BR.BaseStream.Position = temprxx + (xx * 20); string index2string = meta.Map.Strings.Name[BR.ReadUInt16()]; BR.BaseStream.Position = temprxx + (xx * 20) + 4; int tempcx = BR.ReadInt32(); int temprx = BR.ReadInt32() - meta.magic - meta.offset; // Meshes = new CollisionMesh[tempc]; for (int x = 0; x < tempcx; x++) { CollisionMesh cm = new CollisionMesh(); cm.index1 = xxx; cm.index1string = index1string; cm.index2 = xx; cm.index2string = index2string; if (ConditionStrings.IndexOf(cm.index2string) == -1) { ConditionStrings.Add(cm.index2string); } cm.index3 = x; BR.BaseStream.Position = temprx + (x * 68) + 52; int tempc2 = BR.ReadInt32(); int tempr2 = BR.ReadInt32() - meta.magic - meta.offset; cm.Faces = new ushort[tempc2 * 3]; for (int y = 0; y < tempc2; y++) { BR.BaseStream.Position = tempr2 + (y * 12); cm.Faces[y * 3] = BR.ReadUInt16(); cm.Faces[(y * 3) + 1] = BR.ReadUInt16(); cm.Faces[(y * 3) + 2] = cm.Faces[(y * 3) + 1]; // BR.ReadUInt16(); } // ***** Test Code ****// BR.BaseStream.Position = temprx + (x * 68) + 12; tempc2 = BR.ReadInt32(); tempr2 = BR.ReadInt32() - meta.magic - meta.offset; cm.Normals = new Vector4[tempc2]; for (int y = 0; y < tempc2; y++) { BR.BaseStream.Position = tempr2 + (y * 16) + 0; cm.Normals[y].X = BR.ReadSingle(); cm.Normals[y].Y = BR.ReadSingle(); cm.Normals[y].Z = BR.ReadSingle(); cm.Normals[y].W = BR.ReadSingle(); } BR.BaseStream.Position = temprx + (x * 68) + 44; tempc2 = BR.ReadInt32(); tempr2 = BR.ReadInt32() - meta.magic - meta.offset; cm.SurfaceData = new surfaceData[tempc2]; for (int y = 0; y < tempc2; y++) { BR.BaseStream.Position = tempr2 + (y * 8) + 0; cm.SurfaceData[y] = new surfaceData(); cm.SurfaceData[y].Plane = BR.ReadInt16(); } BR.BaseStream.Position = temprx + (x * 68) + 52; tempc2 = BR.ReadInt32(); tempr2 = BR.ReadInt32() - meta.magic - meta.offset; int[] startEdges = new int[tempc2]; int[] endEdges = new int[tempc2]; int[] forwardEdges = new int[tempc2]; int[] reverseEdges = new int[tempc2]; int[] face1 = new int[tempc2]; int[] face2 = new int[tempc2]; for (int y = 0; y < tempc2; y++) { BR.BaseStream.Position = tempr2 + (y * 12) + 0; startEdges[y] = BR.ReadUInt16(); endEdges[y] = BR.ReadUInt16(); BR.BaseStream.Position = tempr2 + (y * 12) + 4; forwardEdges[y] = BR.ReadUInt16(); reverseEdges[y] = BR.ReadUInt16(); BR.BaseStream.Position = tempr2 + (y * 12) + 8; face1[y] = BR.ReadUInt16(); face2[y] = BR.ReadUInt16(); } for (int y = 0; y < forwardEdges.Length; y++) { int cSurface = face1[y]; if (cm.SurfaceData[cSurface].Vertices == null) { cm.SurfaceData[cSurface].Vertices = new List <int>(); int edge = y; int nextEdge = 0; cm.SurfaceData[cSurface].Vertices.Add(startEdges[edge]); do { if (cSurface == face1[edge]) { cm.SurfaceData[cSurface].Vertices.Add(endEdges[edge]); edge = forwardEdges[edge]; } else if (cSurface == face2[edge]) { cm.SurfaceData[cSurface].Vertices.Add(startEdges[edge]); edge = reverseEdges[edge]; } if (cSurface == face1[edge]) { nextEdge = endEdges[edge]; } else if (cSurface == face2[edge]) { nextEdge = startEdges[edge]; } }while (!cm.SurfaceData[cSurface].Vertices.Contains(nextEdge)); } } for (int y = 0; y < reverseEdges.Length; y++) { int cSurface = face2[y]; if (cm.SurfaceData[cSurface].Vertices == null) { cm.SurfaceData[cSurface].Vertices = new List <int>(); int edge = y; int nextEdge = 0; cm.SurfaceData[cSurface].Vertices.Add(endEdges[edge]); do { if (cSurface == face1[edge]) { cm.SurfaceData[cSurface].Vertices.Add(endEdges[edge]); edge = forwardEdges[edge]; } else if (cSurface == face2[edge]) { cm.SurfaceData[cSurface].Vertices.Add(startEdges[edge]); edge = reverseEdges[edge]; } if (cSurface == face1[edge]) { nextEdge = endEdges[edge]; } else if (cSurface == face2[edge]) { nextEdge = startEdges[edge]; } }while (!cm.SurfaceData[cSurface].Vertices.Contains(nextEdge)); } } // ***** End Test Code ****// BR.BaseStream.Position = temprx + (x * 68) + 60; tempc2 = BR.ReadInt32(); tempr2 = BR.ReadInt32() - meta.magic - meta.offset; // Meshes[x] = new CollisionMesh(); cm.Vertices = new Vector3[tempc2]; for (int y = 0; y < tempc2; y++) { BR.BaseStream.Position = tempr2 + (y * 16); cm.Vertices[y].X = BR.ReadSingle(); cm.Vertices[y].Y = BR.ReadSingle(); cm.Vertices[y].Z = BR.ReadSingle(); } Meshes.Add(cm); } } } BR.BaseStream.Position = 36; tempc = BR.ReadInt32(); tempr = BR.ReadInt32() - meta.magic - meta.offset; for (int xxx = 0; xxx < tempc; xxx++) { BR.BaseStream.Position = tempr + (20 * xxx); PathfindingSphere ps = new PathfindingSphere(); ps.nodeindex = BR.ReadInt32(); ps.position = new Vector3(); ps.position.X = BR.ReadSingle(); ps.position.Y = BR.ReadSingle(); ps.position.Z = BR.ReadSingle(); ps.radius = BR.ReadSingle(); Spheres.Add(ps); } }
private void PerMeshClipRendering(IEnumerable <BigMesh> bigMeshes) { var meshList = new List <CollisionMesh>(); var helper = new BuildHelper(coct); foreach (var mesh in bigMeshes.Where(it => !it.matDef.noclip)) { var collisionMesh = new CollisionMesh { Collisions = new List <Collision>() }; var vifPacketIndices = new List <ushort>(mesh.vifPacketIndices); foreach (var set in TriangleStripsToTriangleFans(mesh.triangleStripList)) { var quad = set.Count == 4; var v1 = mesh.vertexList[set[0]]; var v2 = mesh.vertexList[set[1]]; var v3 = mesh.vertexList[set[2]]; var v4 = quad ? mesh.vertexList[set[3]] : Vector3.Zero; collisionMesh.Collisions.Add(coct.Complete( new Collision { Vertex1 = helper.AllocateVertex(v1.X, -v1.Y, -v1.Z), // why -Y and -Z ? Vertex2 = helper.AllocateVertex(v2.X, -v2.Y, -v2.Z), Vertex3 = helper.AllocateVertex(v3.X, -v3.Y, -v3.Z), Vertex4 = Convert.ToInt16(quad ? helper.AllocateVertex(v4.X, -v4.Y, -v4.Z) : -1), SurfaceFlags = new SurfaceFlags() { Flags = mesh.matDef.surfaceFlags } }, inflate: 1 )); } vifPacketRenderingGroup.Add( vifPacketIndices .Distinct() .ToArray() ); coct.Complete(collisionMesh); meshList.Add(collisionMesh); } coct.CompleteAndAdd( new CollisionMeshGroup { Meshes = meshList } ); // Entry2 index is tightly coupled to vifPacketRenderingGroup's index. // Thus do not add Entry2 unplanned. CreateDoctFromCoct(meshList); }
public static void CompareCollision(IExperimentFace face, List <string> filePath) { Rom n0 = new ORom(filePath[0], ORom.Build.N0); Rom mq = new ORom(filePath[1], ORom.Build.MQU); StringBuilder sb_n0 = new StringBuilder(); StringBuilder sb_mq = new StringBuilder(); foreach (int id in MQRandoScenes) { var n0_scene = SceneRoomReader.InitializeScene(n0, id); var mq_scene = SceneRoomReader.InitializeScene(mq, id); CollisionMesh n0_mesh = ((CollisionCommand)n0_scene.Header[HeaderCommands.Collision]).Mesh; CollisionMesh mq_mesh = ((CollisionCommand)mq_scene.Header[HeaderCommands.Collision]).Mesh; sb_n0.AppendLine($"Scene {id}"); sb_mq.AppendLine($"Scene {id}"); sb_n0.AppendLine(n0_mesh.Print()); sb_n0.AppendLine(); sb_n0.AppendLine(mq_mesh.Print()); sb_n0.AppendLine(); //PrintList(sb_n0, n0_mesh.CameraDataList); //PrintList(sb_n0, mq_mesh.CameraDataList); //PrintList(sb_n0, n0_mesh.WaterBoxList); //PrintList(sb_n0, mq_mesh.WaterBoxList); //for (int i = 0; i < n0_mesh.VertexList.Count; i++) //{ // var vertN0 = n0_mesh.VertexList[i]; // var vertMQ = mq_mesh.VertexList[i]; // if (vertN0 != vertMQ) // { // sb_n0.AppendLine($"{i:X4}: {vertN0}"); // sb_mq.AppendLine($"{i:X4}: {vertMQ}"); // } //} //for (int i = 0; i < n0_mesh.Polys; i++) //{ // var n0poly = n0_mesh.PolyList[i]; // var mqpoly = mq_mesh.PolyList[i]; // if (!n0poly.Equals(mqpoly)) // { // if (n0poly.VertexFlagsC != mqpoly.VertexFlagsC // || n0poly.VertexFlagsB != mqpoly.VertexFlagsB) // { // sb_n0.AppendLine($"{i:X4}: {n0poly}"); // sb_mq.AppendLine($"{i:X4}: {mqpoly}"); // } // } //} //sb_mq.AppendLine(); } string result = sb_n0.ToString() + $"{Environment.NewLine}~SPLIT{Environment.NewLine}" + sb_mq.ToString(); face.OutputText(result); }
public static BoundingBox FromCollisionMesh(CollisionMesh m, float padding = 0) => FromVertexPositions(m.CollisionVertices, padding);
public ConvexMeshPoints(CollisionMesh m) { loadedformat = forsavingformat = ElementType.CollisionMesh; }
public void Initialize(System.IO.BinaryReader br) { Mesh = new CollisionMesh(0, CollisionHeaderAddress); Mesh.Initialize(br); }
public CollisionMesh CompleteAndAdd(CollisionMesh it) { buildHelper.CompleteBBox(it); CollisionMeshList.Add(it); return(it); }
private WalkResult Walk(BSP bsp) { var pair = bsp.Split(); if (pair.Length == 2) { return(JoinResult( Walk(pair[0]), Walk(pair[1]) )); } else { var collisionMesh = new CollisionMesh { Collisions = new List <Collision>() }; var vifPacketIndices = new List <ushort>(); foreach (var point in pair[0].Points) { var mesh = point.bigMesh; vifPacketIndices.AddRange(mesh.vifPacketIndices); foreach (var set in TriangleStripsToTriangleFans(mesh.triangleStripList)) { var quad = set.Count == 4; var v1 = mesh.vertexList[set[0]]; var v2 = mesh.vertexList[set[1]]; var v3 = mesh.vertexList[set[2]]; var v4 = quad ? mesh.vertexList[set[3]] : Vector3.Zero; collisionMesh.Collisions.Add(coct.Complete( new Collision { Vertex1 = helper.AllocateVertex(v1.X, -v1.Y, -v1.Z), // why -Y and -Z ? Vertex2 = helper.AllocateVertex(v2.X, -v2.Y, -v2.Z), Vertex3 = helper.AllocateVertex(v3.X, -v3.Y, -v3.Z), Vertex4 = Convert.ToInt16(quad ? helper.AllocateVertex(v4.X, -v4.Y, -v4.Z) : -1), SurfaceFlags = new SurfaceFlags() { Flags = mesh.matDef.surfaceFlags } }, inflate: 1 )); } } coct.Complete(collisionMesh); collisionMeshList.Add(collisionMesh); vifPacketRenderingGroup.Add( vifPacketIndices .Distinct() .ToArray() ); return(new WalkResult { mesh = collisionMesh, }); } }