protected byte[] CreatePositionVector4(RmvVector4 vector)
        {
            var output = new byte[8];

            ushort[] halfs = { new Half(vector.X).RawValue, new Half(vector.Y).RawValue, new Half(vector.Z).RawValue, new Half(vector.W).RawValue };
            for (int i = 0; i < 4; i++)
            {
                var bytes = BitConverter.GetBytes(halfs[i]);
                output[(i * 2)]     = bytes[0];
                output[(i * 2) + 1] = bytes[1];
            }

            return(output);
        }
Exemple #2
0
        public DefaultVertex(RmvVector4 position, RmvVector2 uv, RmvVector3 normal, RmvVector3 biNormal, RmvVector3 tanget)
        {
            _data = new Data()
            {
                position = CreatePositionVector4(position),
                uv       = CreatePositionVector2(uv),
                uvExtra  = CreatePositionVector2(new RmvVector2(0, 0)),
                normal   = CreateNormalVector3(normal),
                biNormal = CreateNormalVector3(biNormal),
                tangent  = CreateNormalVector3(tanget),
                RGBA     = new byte[4] {
                    0, 0, 0, 0
                }
            };

            CreateFromData(_data);
        }
Exemple #3
0
        public WeightedVertex(RmvVector4 position, RmvVector2 uv, RmvVector3 normal, RmvVector3 biNormal, RmvVector3 tanget, BoneInformation[] boneInformation)
        {
            if (boneInformation.Length != 2)
            {
                throw new ArgumentException();
            }

            _data = new Data()
            {
                position   = CreatePositionVector4(position),
                uv         = CreatePositionVector2(uv),
                boneIndex  = boneInformation.Select(x => x.BoneIndex).ToArray(),
                boneWeight = boneInformation.Select(x => (byte)(x.BoneWeight * 255.0f)).ToArray(),
                normal     = CreateNormalVector3(normal),
                biNormal   = CreateNormalVector3(biNormal),
                tangent    = CreateNormalVector3(tanget),
            };

            CreateFromData(_data);
        }
        static Frame ReadFrame(ByteChunk chunk, uint positions, uint rotations)
        {
            var frame = new Frame();

            for (int j = 0; j < positions; j++)
            {
                var vector = new RmvVector3(chunk.ReadSingle(), chunk.ReadSingle(), chunk.ReadSingle());
                frame.Transforms.Add(vector);
            }

            for (int j = 0; j < rotations; j++)
            {
                var maxValue = 1.0f / (float)short.MaxValue;
                var quat     = new short[4] {
                    chunk.ReadShort(), chunk.ReadShort(), chunk.ReadShort(), chunk.ReadShort()
                };

                var quaternion = new RmvVector4(quat[0] * maxValue, quat[1] * maxValue, quat[2] * maxValue, quat[3] * maxValue);
                frame.Quaternion.Add(quaternion);
            }
            return(frame);
        }