示例#1
0
        private void PerMeshClipRendering(IEnumerable <BigMesh> bigMeshes)
        {
            var firstIdx2 = coct.CollisionMeshList.Count;

            var helper = new BuildHelper(coct);

            foreach (var mesh in bigMeshes
                     .Where(it => !it.matDef.noclip)
                     )
            {
                var firstIdx3 = coct.CollisionList.Count;

                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;

                    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;

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

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

            var lastIdx2 = coct.CollisionMeshList.Count;

            coct.CompleteAndAdd(
                new CollisionMeshGroup
            {
                CollisionMeshStart = Convert.ToUInt16(firstIdx2),
                CollisionMeshEnd   = Convert.ToUInt16(lastIdx2),
            }
                );

            // Entry2 index is tightly coupled to vifPacketRenderingGroup's index.
            // Thus do not add Entry2 unplanned.

            CreateDoctFromCoct();
        }
示例#2
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,
                    });
                }
            }