Ejemplo n.º 1
0
            private WalkResult Walk(BSP bsp)
            {
                var pair = bsp.Split();

                if (pair.Length == 2)
                {
                    return(JoinResult(
                               Walk(pair[0]),
                               Walk(pair[1])
                               ));
                }
                else
                {
                    var firstIdx3 = coct.CollisionList.Count;

                    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;

                            coct.CompleteAndAdd(
                                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),
                                SurfaceFlagsIndex = helper.AllocateSurfaceFlags(mesh.matDef.surfaceFlags),
                            },
                                inflate: 1
                                );
                        }
                    }

                    var lastIdx3 = coct.CollisionList.Count;

                    var firstIdx2 = coct.CollisionMeshList.Count;

                    var collisionMesh = coct.CompleteAndAdd(
                        new CollisionMesh
                    {
                        CollisionStart = Convert.ToUInt16(firstIdx3),
                        CollisionEnd   = Convert.ToUInt16(lastIdx3),
                    }
                        );

                    vifPacketRenderingGroup.Add(
                        vifPacketIndices
                        .Distinct()
                        .ToArray()
                        );

                    return(new WalkResult
                    {
                        meshIndex = firstIdx2,
                    });
                }
            }