Beispiel #1
0
        public bool ReadFromStream(Stream stream, ushort type, ushort size, uint nameHash)
        {
            Type     = type;
            Size     = size;
            NameHash = nameHash;

            if (size == 156)
            {
                var reader = new BinaryReader(stream);
                //Read data present in all templates
                ConstraintType = (ConstraintType)reader.ReadUInt32();
                NameUnused     = reader.ReadUInt32();

                BodyANameUnused = reader.ReadUInt32();
                BodyAIndex      = reader.ReadUInt32();
                BodyAOrient     = reader.ReadMatrix33();
                BodyAPos        = reader.ReadVector3f();

                BodyBNameUnused = reader.ReadUInt32();
                BodyBIndex      = reader.ReadUInt32();
                BodyBOrient     = reader.ReadMatrix33();
                BodyBPos        = reader.ReadVector3f();

                Threshold = reader.ReadSingle();

                //Read constraint data, dependent on constraint type
                switch (ConstraintType)
                {
                case ConstraintType.ConstraintNone:
                    ConstraintData = null;
                    break;

                case ConstraintType.ConstraintPoint:
                    ConstraintData = new PointConstraintData();
                    ConstraintData.ReadFromStream(stream);
                    break;

                case ConstraintType.ConstraintHinge:
                    ConstraintData = new HingeConstraintData();
                    ConstraintData.ReadFromStream(stream);
                    break;

                case ConstraintType.ConstraintPrismatic:
                    ConstraintData = new PrismaticConstraintData();
                    ConstraintData.ReadFromStream(stream);
                    break;

                case ConstraintType.ConstraintRagdoll:
                    ConstraintData = new RagdollConstraintData();
                    ConstraintData.ReadFromStream(stream);
                    break;

                case ConstraintType.ConstraintMotor:
                    ConstraintData = new MotorConstraintData();
                    ConstraintData.ReadFromStream(stream);
                    break;

                case ConstraintType.ConstraintFake:
                    ConstraintData = new FakeConstraintData();
                    ConstraintData.ReadFromStream(stream);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                return(true);
            }
            else
            {
                Console.WriteLine("Error! Found constraint template property with size != 156 bytes. Unknown data! Skipping property.");
                return(false);
            }
        }
Beispiel #2
0
        public void ReadFromXml(XElement propertyRoot, ushort type, ushort size, uint nameHash)
        {
            Type     = type;
            Size     = size;
            NameHash = nameHash;

            var dataNode = propertyRoot.GetRequiredElement("Data");

            ConstraintType = (ConstraintType)dataNode.GetRequiredValue("ConstraintType").ToInt32();
            NameUnused     = dataNode.GetRequiredValue("NameUnused").ToUint32();

            BodyANameUnused = dataNode.GetRequiredValue("BodyANameUnused").ToUint32();
            BodyAIndex      = dataNode.GetRequiredValue("BodyAIndex").ToUint32();
            BodyAOrient     = dataNode.GetRequiredElement("BodyAOrient").ToMatrix33();
            BodyAPos        = dataNode.GetRequiredElement("BodyAPos").ToVector3f();

            BodyBNameUnused = dataNode.GetRequiredValue("BodyBNameUnused").ToUint32();
            BodyBIndex      = dataNode.GetRequiredValue("BodyBIndex").ToUint32();
            BodyBOrient     = dataNode.GetRequiredElement("BodyBOrient").ToMatrix33();
            BodyBPos        = dataNode.GetRequiredElement("BodyBPos").ToVector3f();

            Threshold = dataNode.GetRequiredValue("Threshold").ToSingle();

            //Read constraint data, dependent on constraint type
            var constraintDataNode = dataNode.GetRequiredElement("ConstraintData");

            switch (ConstraintType)
            {
            case ConstraintType.ConstraintNone:
                ConstraintData = null;
                break;

            case ConstraintType.ConstraintPoint:
                ConstraintData = new PointConstraintData();
                ConstraintData.ReadFromXml(constraintDataNode);
                break;

            case ConstraintType.ConstraintHinge:
                ConstraintData = new HingeConstraintData();
                ConstraintData.ReadFromXml(constraintDataNode);
                break;

            case ConstraintType.ConstraintPrismatic:
                ConstraintData = new PrismaticConstraintData();
                ConstraintData.ReadFromXml(constraintDataNode);
                break;

            case ConstraintType.ConstraintRagdoll:
                ConstraintData = new RagdollConstraintData();
                ConstraintData.ReadFromXml(constraintDataNode);
                break;

            case ConstraintType.ConstraintMotor:
                ConstraintData = new MotorConstraintData();
                ConstraintData.ReadFromXml(constraintDataNode);
                break;

            case ConstraintType.ConstraintFake:
                ConstraintData = new FakeConstraintData();
                ConstraintData.ReadFromXml(constraintDataNode);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }