public List <DisplayListCommand> GetDecodedCommands()
        {
            var decoded = new List <DisplayListCommand>();

            decoded.Add(new DisplayListCommand
            {
                G3dCommand = G3dCommand.Begin,
                IntArgs    = new[] { (uint)G3dDisplayList.GetPrimitiveType(Type) }
            });

            foreach (var command in Commands)
            {
                if (command.G3dCommand == G3dCommand.RestoreMatrix) //todo: check if it's right
                {
                    if (command.GetDecodedCommand().IntArgs[0] != 0)
                    {
                        decoded.Add(command.GetDecodedCommand());
                    }
                }
                else
                {
                    decoded.Add(command.GetDecodedCommand());
                }
            }

            decoded.Add(new DisplayListCommand
            {
                G3dCommand = G3dCommand.End
            });

            return(decoded);
        }
Beispiel #2
0
        private static ShapeSet GetShapeSet(Imd imd)
        {
            var shapes = new ShapeSet
            {
                dict  = new Dictionary <ShapeSetData>(),
                shape = new Shape[imd.Body.PolygonArray.Polygons.Count]
            };

            int idx = 0;

            foreach (var polygon in imd.Body.PolygonArray.Polygons)
            {
                shapes.dict.Add(polygon.Name, new ShapeSetData());

                Shape.NNS_G3D_SHPFLAG flag = 0;

                if (polygon.TexFlag == "on")
                {
                    flag = Shape.NNS_G3D_SHPFLAG.NNS_G3D_SHPFLAG_USE_TEXCOORD;
                }
                if (polygon.ClrFlag == "on")
                {
                    flag |= Shape.NNS_G3D_SHPFLAG.NNS_G3D_SHPFLAG_USE_COLOR;
                }
                if (polygon.NrmFlag == "on")
                {
                    flag |= Shape.NNS_G3D_SHPFLAG.NNS_G3D_SHPFLAG_USE_NORMAL;
                }

                //TODO
                shapes.shape[idx++] = new Shape
                {
                    flag = flag,
                    DL   = G3dDisplayList.Encode(polygon.MatrixPrimitives[0].PrimitiveArray.GetDisplayList())
                };
            }

            return(shapes);
        }
Beispiel #3
0
        private void Test()
        {
            var test = new NSBMD(File.ReadAllBytes(@"testfiles\patapata.nsbmd"));

            var dlA = test.ModelSet.models[0].shapes.shape[2].DL;
            var dlB = G3dDisplayList.Encode(G3dDisplayList.Decode(test.ModelSet.models[0].shapes.shape[2].DL).Where(x => x.G3dCommand != G3dCommand.Nop));

            var dlC = G3dDisplayList.Encode(new[]
            {
                new DisplayListCommand
                {
                    G3dCommand = G3dCommand.TexCoord, RealArgs = new[] { 10f, 10f }
                },
                new DisplayListCommand
                {
                    G3dCommand = G3dCommand.Vertex, RealArgs = new[] { 5f, 5f, 5f }
                },
                new DisplayListCommand
                {
                    G3dCommand = G3dCommand.End
                },
            });

            DumpDisplayList(G3dDisplayList.Decode(dlA), "testfiles/dlA.txt");
            DumpDisplayList(G3dDisplayList.Decode(dlB), "testfiles/dlB.txt");
            DumpDisplayList(G3dDisplayList.Decode(dlC), "testfiles/dlC.txt");

            //DL DECODE TEST

            /*var decoded = new List<List<DecodedCommand>>();
             *
             * foreach (var s in _testNsbmd.ModelSet.models[0].shapes.shape)
             * {
             *  decoded.Add(G3dDisplayList.Decode(s.DL));
             * }*/

            /*var dl = _testNsbmd.ModelSet.models[0].shapes.shape[0].DL;
             *
             * var decoded = G3dDisplayList.Decode(dl);
             * var decodedNoNops = decoded.Where(x => x.G3dCommand != G3dCommand.Nop).ToList();
             * var decodedImd = _imd.Body.PolygonArray.Polygons[0].MatrixPrimitives[0].PrimitiveArray.GetDecodedCommands();
             *
             * //var encoded = G3dDisplayList.Encode(decodedImd);
             *
             * var encodedFromNsbmd = G3dDisplayList.Encode(decoded); //Must be 992 bytes long
             * var encodedNoNops = G3dDisplayList.Encode(decodedNoNops);
             *
             * var encodedFromImd = G3dDisplayList.Encode(decodedImd);
             * var decoded3 = G3dDisplayList.Decode(encodedFromImd);
             *
             * var sbc = new Sbc.Sbc(_testNsbmd.ModelSet.models[0].sbc);
             *
             * var test = sbc.Write();
             *
             * _nsbmd.ModelSet.models[0].sbc = test;*/

            /*for (int i = 0; i < dl.Length; i++)
             * {
             *  try
             *  {
             *      if (dl[i] != encoded[i])
             *      {
             *          Console.WriteLine($"Different! At offset {i}: {dl[i]} {encoded[i]}");
             *      }
             *  }
             *  catch (Exception e)
             *  {
             *      Console.WriteLine(e);
             *  }
             * }*/
            //File.WriteAllBytes(@"E:\ermel\Desktop\test.nsbmd", _nsbmd.Write());


            //var testNsbmd2 = new NSBMD(File.ReadAllBytes(@"testfiles/test.nsbmd"));

            //Test patching shapes

            /*for (int i = 0; i < _testNsbmd.ModelSet.models[0].shapes.shape.Length; i++)
             * {
             *  var newUnwrittenShape = _nsbmd.ModelSet.models[0].shapes.shape[i];
             *  var newShape = testNsbmd2.ModelSet.models[0].shapes.shape[i];
             *  var oldShape = _testNsbmd.ModelSet.models[0].shapes.shape[i];
             *
             *  DumpDisplayList(G3dDisplayList.Decode(newUnwrittenShape.DL), $"testfiles/newdl/new_{i}.txt");
             *  DumpDisplayList(G3dDisplayList.Decode(oldShape.DL), $"testfiles/olddl/{i}.txt");
             *
             *  File.AppendAllText("testfiles/newdl/dlinfo.txt", $"NEW SHAPE: Encoded DL Length = {newUnwrittenShape.DL.Length} ; Decoded DL Length = {G3dDisplayList.Decode(newUnwrittenShape.DL).Count}" +
             *                                                   $" OLD SHAPE: Encoded DL Length = {oldShape.DL.Length} ; Decoded DL Length = {G3dDisplayList.Decode(oldShape.DL).Count}\n");
             * }*/
        }