Пример #1
0
        /// <summary>
        /// Parse single NSBMD object.
        /// </summary>
        private static void ParseNsbmdObject(EndianBinaryReader reader, NsbmdObject nsbmdObject, float modelscale)
        {
            UInt16 v = reader.ReadUInt16();
            Int16 divide = reader.ReadInt16();
            divide = (short)NsbmdGlRenderer.sign(divide, 16);
            int unknown = v >> 12 & 0xf;
            nsbmdObject.StackID = unknown;
            //nsbmdObject.isBillboard = ((v >> 12 & 0xf) == 1?true:false);
            float[] s = NsbmdGlRenderer.loadIdentity();
            float[] r = NsbmdGlRenderer.loadIdentity();
            float[] t = NsbmdGlRenderer.loadIdentity();
            if ((v & 1) == 0)
            {
                nsbmdObject.Trans = true;

                nsbmdObject.X = (float)reader.ReadInt32() / 4096f / modelscale;//(float)getdword(reader.ReadBytes(4)) / 4096f; //(float)(reader.ReadDouble() / 4096d);//.ReadUInt32() / 4096;
                nsbmdObject.Y = (float)reader.ReadInt32() / 4096f / modelscale;//(float)getdword(reader.ReadBytes(4)) / 4096f;//(float)(reader.ReadDouble() / 4096d);
                nsbmdObject.Z = (float)reader.ReadInt32() / 4096f / modelscale;//(float)getdword(reader.ReadBytes(4)) / 4096f;//(float)(reader.ReadDouble() / 4096d);
                t = NsbmdGlRenderer.translate(t, nsbmdObject.X, nsbmdObject.Y, nsbmdObject.Z);
            }
            if ((v >> 3 & 0x1) == 0x1)
            {
                nsbmdObject.IsRotated = true;
                float a = reader.ReadInt16();
                a = NsbmdGlRenderer.sign((int)a, 16) / 4096f;
                float b = reader.ReadInt16();
                b = NsbmdGlRenderer.sign((int)b, 16) / 4096f;
                nsbmdObject.Pivot = (int)(v >> 4) & 0x0f;
                nsbmdObject.Neg = (int)(v >> 8) & 0x0f;
                nsbmdObject.RotA = a;
                nsbmdObject.RotB = b;
                nsbmdObject.rotate_mtx = mtxPivot(new float[] { nsbmdObject.RotA, nsbmdObject.RotB }, nsbmdObject.Pivot, nsbmdObject.Neg);
                r = NsbmdGlRenderer.multMatrix(r, nsbmdObject.rotate_mtx);
            }
            if ((v >> 1 & 1) == 0 && (v >> 3 & 1) == 0)
            {
                float[] a = new float[16];
                a[0] = 1.0F;
                a[5] = 1.0F;
                a[10] = 1.0F;
                a[15] = 1.0F;
                float[] rotate = new float[8];
                //msg = (new StringBuilder()).append(msg).append(" | R: ").toString();
                for (int j = 0; j < rotate.Length; j++)
                {
                    //dataParser _tmp4 = pa;
                    int value = NsbmdGlRenderer.sign(reader.ReadInt16(),16); //dataParser.getSign(data, offset + 4 + j * 2 + jump, 2);
                    rotate[j] = (float)value / 4096f;
                    //msg = (new StringBuilder()).append(msg).append(pad(Integer.valueOf(value), 4)).toString();
                    //if(j + 1 < rotate.length)
                    //   msg = (new StringBuilder()).append(msg).append(", ").toString();
                }

                a[0] = (float)divide / 4096f;
                a[1] = rotate[0];
                a[2] = rotate[1];
                a[4] = rotate[2];
                a[5] = rotate[3];
                a[6] = rotate[4];
                a[8] = rotate[5];
                a[9] = rotate[6];
                a[10] = rotate[7];
                nsbmdObject.rotate_mtx = a;
                nsbmdObject.IsRotated = true;
                r = NsbmdGlRenderer.multMatrix(r, nsbmdObject.rotate_mtx);
            }
            if ((v >> 2 & 1) == 0)
            {
                float[] scale = new float[3];
                for (int j = 0; j < scale.Length; j++)
                {
                    int value = reader.ReadInt32();
                    scale[j] = (float)value / 4096f;
                }
                nsbmdObject.scale = scale;
                nsbmdObject.IsScaled = true;
               s = NsbmdGlRenderer.scale(s, scale[0], scale[1], scale[2]);
            }
            nsbmdObject.materix = NsbmdGlRenderer.loadIdentity();
            nsbmdObject.materix = NsbmdGlRenderer.multMatrix(nsbmdObject.materix, t);
            nsbmdObject.materix = NsbmdGlRenderer.multMatrix(nsbmdObject.materix, r);
            nsbmdObject.materix = NsbmdGlRenderer.multMatrix(nsbmdObject.materix, s);
        }
Пример #2
0
        /// <summary>
        /// Parse single NSBMD object.
        /// </summary>
        private static void ParseNsbmdObject(BinaryReader reader, NsbmdObject nsbmdObject)
        {
            UInt32 v = reader.ReadUInt32();
            if ((v & 1) == 0)
            {
                nsbmdObject.Trans = true;

                nsbmdObject.X = reader.ReadUInt32();
                nsbmdObject.Y = reader.ReadUInt32();
                nsbmdObject.Z = reader.ReadUInt32();
            }
            if ((v & 0xa) == 0x8)
            {
                nsbmdObject.IsRotated = true;
                int a = reader.ReadUInt16();
                if ((a & 0x8000) != 0) a |= 0x0000;
                int b = reader.ReadUInt16();
                if ((b & 0x8000) != 0) b |= 0x0000;
                nsbmdObject.Pivot = (v >> 4) & 0x0f;
                nsbmdObject.Neg = (v >> 8) & 0x0f;
                nsbmdObject.RotA = a;
                nsbmdObject.RotB = b;
            }
        }