Beispiel #1
0
        private void DumpEntry2(Coct.CollisionMesh mesh, int indent)
        {
            writer.WriteLine($"{new string(' ', indent)}{ObjDumpUtil.FormatObj(mesh, it => it.BoundingBox, it => it.v10, it => it.v12)}");

            foreach (var face in mesh.Collisions)
            {
                DumpEntry3(face, indent + 1);
            }
        }
Beispiel #2
0
        private void DumpMeshInfo(Coct.CollisionMesh mesh, int indent)
        {
            writer.WriteLine($"{new string(' ', indent)}{ObjDumpUtil.FormatObj(mesh, it => it.BoundingBox, it => it.Visibility, it => it.Group)}");

            foreach (var face in mesh.Collisions)
            {
                DumpFace(face, indent + 1);
            }
        }
Beispiel #3
0
            protected int OnExecute(CommandLineApplication app)
            {
                var coct = new Coct();

                var bbox = BBox.Split(',')
                           .Select(one => short.Parse(one))
                           .ToArray();

                var invMinX = bbox[0];
                var invMinY = bbox[1];
                var invMinZ = bbox[2];
                var invMaxX = bbox[3];
                var invMaxY = bbox[4];
                var invMaxZ = bbox[5];

                var minX = -invMinX;
                var minY = -invMinY;
                var minZ = -invMinZ;
                var maxX = -invMaxX;
                var maxY = -invMaxY;
                var maxZ = -invMaxZ;

                var builder = new Coct.BuildHelper(coct);

                // (forwardVec)
                // +Z
                // A  / +Y (upVec)
                // | /
                // |/
                // +--> +X (rightVec)

                //   7 == 6  top
                //   |    |  top
                //   4 == 5  top
                //
                // 3 == 2  bottom
                // |    |  bottom
                // 0 == 1  bottom

                var table4Idxes = new short[]
                {
                    builder.AllocateVertex(minX, minY, minZ, 1),
                    builder.AllocateVertex(maxX, minY, minZ, 1),
                    builder.AllocateVertex(maxX, minY, maxZ, 1),
                    builder.AllocateVertex(minX, minY, maxZ, 1),
                    builder.AllocateVertex(minX, maxY, minZ, 1),
                    builder.AllocateVertex(maxX, maxY, minZ, 1),
                    builder.AllocateVertex(maxX, maxY, maxZ, 1),
                    builder.AllocateVertex(minX, maxY, maxZ, 1),
                };

                // side:
                // 0 bottom
                // 1 top
                // 2 west
                // 3 east
                // 4 south
                // 5 north

                var planes = new Plane[]
                {
                    new Plane(0, -1, 0, +minY), //bottom
                    new Plane(0, +1, 0, -maxY), //up
                    new Plane(-1, 0, 0, +minX), //west
                    new Plane(+1, 0, 0, -maxX), //east
                    new Plane(0, 0, -1, +minZ), //south
                    new Plane(0, 0, +1, -maxZ), //north
                };

                var faceVertexOrders = new int[, ]
                {
                    { 0, 1, 2, 3 }, //bottom
                    { 4, 7, 6, 5 }, //top
                    { 3, 7, 4, 0 }, //west
                    { 1, 5, 6, 2 }, //east
                    { 2, 6, 7, 3 }, //south
                    { 0, 4, 5, 1 }, //north
                };

                var collisionMesh = new Coct.CollisionMesh
                {
                    Collisions = new List <Coct.Collision>()
                };

                for (var side = 0; side < 6; side++)
                {
                    var collision = new Coct.Collision
                    {
                        Ground      = 0,
                        FloorLevel  = 0,
                        Vertex1     = table4Idxes[faceVertexOrders[side, 0]],
                        Vertex2     = table4Idxes[faceVertexOrders[side, 1]],
                        Vertex3     = table4Idxes[faceVertexOrders[side, 2]],
                        Vertex4     = table4Idxes[faceVertexOrders[side, 3]],
                        Plane       = planes[side],
                        BoundingBox = BoundingBoxInt16.Invalid,
                        Attributes  = new Coct.Attributes()
                        {
                            Flags = 0x3F1
                        },
                    };
                    coct.Complete(collision);
                    collisionMesh.Collisions.Add(collision);
                }

                coct.Complete(collisionMesh);

                coct.CompleteAndAdd(
                    new Coct.CollisionNode
                {
                    Meshes = new List <Coct.CollisionMesh>()
                    {
                        collisionMesh
                    }
                }
                    );

                var buff = new MemoryStream();

                coct.Write(buff);
                buff.Position = 0;
                File.WriteAllBytes(CoctOut, buff.ToArray());

                return(0);
            }
Beispiel #4
0
            protected int OnExecute(CommandLineApplication app)
            {
                var coct = new Coct();

                var bbox = BBox.Split(',')
                           .Select(one => short.Parse(one))
                           .ToArray();

                var invMinX = bbox[0];
                var invMinY = bbox[1];
                var invMinZ = bbox[2];
                var invMaxX = bbox[3];
                var invMaxY = bbox[4];
                var invMaxZ = bbox[5];

                var minX = -invMinX;
                var minY = -invMinY;
                var minZ = -invMinZ;
                var maxX = -invMaxX;
                var maxY = -invMaxY;
                var maxZ = -invMaxZ;

                var builder = new Coct.BuildHelper(coct);

                var table7Idx = builder.AllocateSurfaceFlags(0x3F1);

                // (forwardVec)
                // +Z
                // A  / +Y (upVec)
                // | /
                // |/
                // +--> +X (rightVec)

                //   7 == 6  top
                //   |    |  top
                //   4 == 5  top
                //
                // 3 == 2  bottom
                // |    |  bottom
                // 0 == 1  bottom

                var table4Idxes = new short[]
                {
                    builder.AllocateVertex(minX, minY, minZ, 1),
                    builder.AllocateVertex(maxX, minY, minZ, 1),
                    builder.AllocateVertex(maxX, minY, maxZ, 1),
                    builder.AllocateVertex(minX, minY, maxZ, 1),
                    builder.AllocateVertex(minX, maxY, minZ, 1),
                    builder.AllocateVertex(maxX, maxY, minZ, 1),
                    builder.AllocateVertex(maxX, maxY, maxZ, 1),
                    builder.AllocateVertex(minX, maxY, maxZ, 1),
                };

                // side:
                // 0 bottom
                // 1 top
                // 2 west
                // 3 east
                // 4 south
                // 5 north

                var table5Idxes = new short[]
                {
                    builder.AllocatePlane(0, -1, 0, +minY), //bottom
                    builder.AllocatePlane(0, +1, 0, -maxY), //up
                    builder.AllocatePlane(-1, 0, 0, +minX), //west
                    builder.AllocatePlane(+1, 0, 0, -maxX), //east
                    builder.AllocatePlane(0, 0, -1, +minZ), //south
                    builder.AllocatePlane(0, 0, +1, -maxZ), //north
                };

                var faceVertexOrders = new int[, ]
                {
                    { 0, 1, 2, 3 }, //bottom
                    { 4, 7, 6, 5 }, //top
                    { 3, 7, 4, 0 }, //west
                    { 1, 5, 6, 2 }, //east
                    { 2, 6, 7, 3 }, //south
                    { 0, 4, 5, 1 }, //north
                };

                var table3FirstIdx = coct.CollisionList.Count;

                for (var side = 0; side < 6; side++)
                {
                    var ent3 = new Coct.Collision
                    {
                        v00               = 0,
                        Vertex1           = table4Idxes[faceVertexOrders[side, 0]],
                        Vertex2           = table4Idxes[faceVertexOrders[side, 1]],
                        Vertex3           = table4Idxes[faceVertexOrders[side, 2]],
                        Vertex4           = table4Idxes[faceVertexOrders[side, 3]],
                        PlaneIndex        = table5Idxes[side],
                        BoundingBoxIndex  = -1, // set later
                        SurfaceFlagsIndex = table7Idx,
                    };

                    builder.CompletePlane(ent3);
                    builder.CompleteBBox(ent3);

                    coct.CollisionList.Add(ent3);
                }

                var table3LastIdx = coct.CollisionList.Count;

                var table2FirstIdx = coct.CollisionMeshList.Count;

                var ent2 = new Coct.CollisionMesh
                {
                    CollisionStart = Convert.ToUInt16(table3FirstIdx),
                    CollisionEnd   = Convert.ToUInt16(table3LastIdx),
                    v10            = 0,
                    v12            = 0,
                };

                builder.CompleteBBox(ent2);

                coct.CollisionMeshList.Add(ent2);

                var table2LastIdx = coct.CollisionMeshList.Count;

                var ent1 = new Coct.CollisionMeshGroup
                {
                    CollisionMeshStart = Convert.ToUInt16(table2FirstIdx),
                    CollisionMeshEnd   = Convert.ToUInt16(table2LastIdx),
                };

                builder.CompleteBBox(ent1);

                coct.CollisionMeshGroupList.Add(ent1);

                var buff = new MemoryStream();

                coct.Write(buff);
                buff.Position = 0;
                File.WriteAllBytes(CoctOut, buff.ToArray());

                return(0);
            }