예제 #1
0
        private void DeSerializeConvexHullShapeData(XmlElement element)
        {
            int ptr = int.Parse(element.GetAttribute("pointer"));

            byte[] convexHullData = new byte[Marshal.SizeOf(typeof(ConvexHullShapeData))];

            using (var stream = new MemoryStream(convexHullData))
            {
                using (var writer = new BulletWriter(stream))
                {
                    XmlNode node = element["m_convexInternalShapeData"];
                    if (node == null)
                    {
                        return;
                    }
                    DeSerializeConvexInternalShapeData(node as XmlElement, writer);

                    SetPointerValue(writer, element["m_unscaledPointsFloatPtr"], ConvexHullShapeData.Offset("UnscaledPointsFloatPtr"));
                    SetPointerValue(writer, element["m_unscaledPointsDoublePtr"], ConvexHullShapeData.Offset("UnscaledPointsDoublePtr"));
                    SetIntValue(writer, element["m_numUnscaledPoints"], ConvexHullShapeData.Offset("NumUnscaledPoints"));
                }
            }

            _collisionShapeData.Add(convexHullData);
            _pointerLookup.Add(ptr, convexHullData);
        }
예제 #2
0
        private void DeSerializeCompoundShapeData(XmlElement element)
        {
            int ptr = int.Parse(element.GetAttribute("pointer"));

            byte[] convexShape = new byte[Marshal.SizeOf(typeof(CompoundShapeData))];

            using (var stream = new MemoryStream(convexShape))
            {
                using (var writer = new BulletWriter(stream))
                {
                    XmlNode node = element["m_collisionShapeData"];
                    if (node == null)
                    {
                        return;
                    }
                    DeSerializeCollisionShapeData(node as XmlElement, writer);

                    SetIntValue(writer, element["m_numChildShapes"], CompoundShapeData.Offset("NumChildShapes"));
                    SetPointerValue(writer, element["m_childShapePtr"], CompoundShapeData.Offset("ChildShapePtr"));
                    SetFloatValue(writer, element["m_collisionMargin"], CompoundShapeData.Offset("CollisionMargin"));
                }
            }

            _collisionShapeData.Add(convexShape);
            _pointerLookup.Add(ptr, convexShape);
        }
예제 #3
0
        private void DeSerializeStaticPlaneShapeData(XmlElement element)
        {
            int ptr = int.Parse(element.GetAttribute("pointer"));

            byte[] convexShape = new byte[Marshal.SizeOf(typeof(StaticPlaneShapeData))];

            using (var stream = new MemoryStream(convexShape))
            {
                using (var writer = new BulletWriter(stream))
                {
                    XmlNode node = element["m_collisionShapeData"];
                    if (node == null)
                    {
                        return;
                    }
                    DeSerializeCollisionShapeData(node as XmlElement, writer);

                    SetVector4Value(writer, element["m_localScaling"], StaticPlaneShapeData.Offset("LocalScaling"));
                    SetVector4Value(writer, element["m_planeNormal"], StaticPlaneShapeData.Offset("PlaneNormal"));
                    SetFloatValue(writer, element["m_planeConstant"], StaticPlaneShapeData.Offset("PlaneConstant"));
                }
            }

            _collisionShapeData.Add(convexShape);
            _pointerLookup.Add(ptr, convexShape);
        }
예제 #4
0
        private void DeSerializeVector3FloatData(XmlElement element)
        {
            int ptr = int.Parse(element.GetAttribute("pointer"));

            XmlNodeList vectors    = element.SelectNodes("m_floats");
            int         numVectors = vectors.Count;

            int vectorSize = Marshal.SizeOf(typeof(Vector3FloatData));

            byte[] v = new byte[numVectors * vectorSize];

            using (var stream = new MemoryStream(v))
            {
                using (var writer = new BulletWriter(stream))
                {
                    int offset = 0;
                    for (int i = 0; i < numVectors; i++)
                    {
                        SetVector4Value(writer, vectors[i], offset);
                        offset += vectorSize;
                    }
                }
            }

            _pointerLookup.Add(ptr, v);
        }
예제 #5
0
        private void DeSerializeCompoundShapeChildData(XmlElement element)
        {
            int ptr = int.Parse(element.GetAttribute("pointer"));

            XmlNodeList transforms      = element.SelectNodes("m_transform");
            XmlNodeList childShapes     = element.SelectNodes("m_childShape");
            XmlNodeList childShapeTypes = element.SelectNodes("m_childShapeType");
            XmlNodeList childMargins    = element.SelectNodes("m_childMargin");

            int numChildren = transforms.Count;
            int dataSize    = Marshal.SizeOf(typeof(CompoundShapeChildData));

            byte[] compoundChild = new byte[dataSize * numChildren];

            using (var stream = new MemoryStream(compoundChild))
            {
                using (var writer = new BulletWriter(stream))
                {
                    int offset = 0;
                    for (int i = 0; i < numChildren; i++)
                    {
                        SetTransformValue(writer, transforms[i], offset + CompoundShapeChildData.Offset("Transform"));
                        SetPointerValue(writer, childShapes[i], offset + CompoundShapeChildData.Offset("ChildShape"));
                        SetIntValue(writer, childShapeTypes[i], offset + CompoundShapeChildData.Offset("ChildShapeType"));
                        SetFloatValue(writer, childMargins[i], offset + CompoundShapeChildData.Offset("ChildMargin"));

                        offset += dataSize;
                    }
                }
            }

            _pointerLookup.Add(ptr, compoundChild);
        }
예제 #6
0
        private void SetMatrix3x3Value(BulletWriter writer, XmlElement valueNode, int offset)
        {
            XmlNode floats = valueNode["m_el"]["m_floats"];

            SetVector4Value(writer, floats, offset);
            floats = floats.NextSibling;
            SetVector4Value(writer, floats, offset + 16);
            floats = floats.NextSibling;
            SetVector4Value(writer, floats, offset + 32);
        }
예제 #7
0
        private void DeSerializeConvexInternalShapeData(XmlElement element, BulletWriter writer)
        {
            XmlNode node = element["m_collisionShapeData"];

            if (node == null)
            {
                return;
            }
            DeSerializeCollisionShapeData(node as XmlElement, writer);

            SetFloatValue(writer, element["m_collisionMargin"], ConvexInternalShapeData.Offset("CollisionMargin"));
            SetVector4Value(writer, element["m_localScaling"], ConvexInternalShapeData.Offset("LocalScaling"));
            SetVector4Value(writer, element["m_implicitShapeDimensions"], ConvexInternalShapeData.Offset("ImplicitShapeDimensions"));
        }
예제 #8
0
        private void SetVector4Value(BulletWriter writer, XmlNode valueNode, int offset)
        {
            int i = 0;

            foreach (string value in valueNode.InnerText.Split(' '))
            {
                if (!string.IsNullOrWhiteSpace(value))
                {
                    writer.Write(Scalar.Parse(value, CultureInfo.InvariantCulture), offset + i * sizeof(Scalar));
                    i++;
                    if (i == 4)
                    {
                        break;
                    }
                }
            }
        }
예제 #9
0
        private void DeSerializeConvexInternalShapeData(XmlElement element)
        {
            int ptr = int.Parse(element.GetAttribute("pointer"));

            byte[] convexShapeData = new byte[Marshal.SizeOf(typeof(ConvexInternalShapeData))];

            using (var stream = new MemoryStream(convexShapeData))
            {
                using (var writer = new BulletWriter(stream))
                {
                    DeSerializeConvexInternalShapeData(element, writer);
                }
            }

            _collisionShapeData.Add(convexShapeData);
            _pointerLookup.Add(ptr, convexShapeData);
        }
예제 #10
0
        private void DeSerializeGeneric6DofConstraintData(XmlElement element)
        {
            int ptr = int.Parse(element.GetAttribute("pointer"));

            byte[] dof6Data = new byte[Marshal.SizeOf(typeof(Generic6DofConstraintFloatData))];

            using (var stream = new MemoryStream(dof6Data))
            {
                using (var writer = new BulletWriter(stream))
                {
                    XmlNode node = element["m_typeConstraintData"];
                    if (node == null)
                    {
                        return;
                    }
                    SetPointerValue(writer, node["m_rbA"], TypedConstraintFloatData.Offset("RigidBodyA"));
                    SetPointerValue(writer, node["m_rbB"], TypedConstraintFloatData.Offset("RigidBodyB"));
                    writer.Write(0, TypedConstraintFloatData.Offset("Name"));
                    SetIntValue(writer, node["m_objectType"], TypedConstraintFloatData.Offset("ObjectType"));
                    SetIntValue(writer, node["m_userConstraintType"], TypedConstraintFloatData.Offset("UserConstraintType"));
                    SetIntValue(writer, node["m_userConstraintId"], TypedConstraintFloatData.Offset("UserConstraintId"));
                    SetIntValue(writer, node["m_needsFeedback"], TypedConstraintFloatData.Offset("NeedsFeedback"));
                    SetFloatValue(writer, node["m_appliedImpulse"], TypedConstraintFloatData.Offset("AppliedImpulse"));
                    SetFloatValue(writer, node["m_dbgDrawSize"], TypedConstraintFloatData.Offset("DebugDrawSize"));
                    SetIntValue(writer, node["m_disableCollisionsBetweenLinkedBodies"], TypedConstraintFloatData.Offset("DisableCollisionsBetweenLinkedBodies"));
                    SetIntValue(writer, node["m_overrideNumSolverIterations"], TypedConstraintFloatData.Offset("OverrideNumSolverIterations"));
                    SetFloatValue(writer, node["m_breakingImpulseThreshold"], TypedConstraintFloatData.Offset("BreakingImpulseThreshold"));
                    SetIntValue(writer, node["m_isEnabled"], TypedConstraintFloatData.Offset("IsEnabled"));

                    SetTransformValue(writer, element["m_rbAFrame"], Generic6DofConstraintFloatData.Offset("RigidBodyAFrame"));
                    SetTransformValue(writer, element["m_rbBFrame"], Generic6DofConstraintFloatData.Offset("RigidBodyBFrame"));
                    SetVector4Value(writer, element["m_linearUpperLimit"], Generic6DofConstraintFloatData.Offset("LinearUpperLimit"));
                    SetVector4Value(writer, element["m_linearLowerLimit"], Generic6DofConstraintFloatData.Offset("LinearLowerLimit"));
                    SetVector4Value(writer, element["m_angularUpperLimit"], Generic6DofConstraintFloatData.Offset("AngularUpperLimit"));
                    SetVector4Value(writer, element["m_angularLowerLimit"], Generic6DofConstraintFloatData.Offset("AngularLowerLimit"));
                    SetIntValue(writer, element["m_useLinearReferenceFrameA"], Generic6DofConstraintFloatData.Offset("UseLinearReferenceFrameA"));
                    SetIntValue(writer, element["m_useOffsetForConstraintFrame"], Generic6DofConstraintFloatData.Offset("UseOffsetForConstraintFrame"));
                }
            }

            _constraintData.Add(dof6Data);
        }
        private void DeSerializeConvexInternalShapeData(XmlElement element)
        {
            int ptr = int.Parse(element.GetAttribute("pointer"));
            byte[] convexShapeData = new byte[Marshal.SizeOf(typeof(ConvexInternalShapeFloatData))];

            using (var stream = new MemoryStream(convexShapeData))
            {
                using (var writer = new BulletWriter(stream))
                {
                    DeSerializeConvexInternalShapeData(element, writer);
                }
            }

            _collisionShapeData.Add(convexShapeData);
            _pointerLookup.Add(ptr, convexShapeData);
        }
        private void DeSerializeConvexInternalShapeData(XmlElement element, BulletWriter writer)
        {
            XmlNode node = element["m_collisionShapeData"];
            if (node == null)
            {
                return;
            }
            DeSerializeCollisionShapeData(node as XmlElement, writer);

            SetFloatValue(writer, element["m_collisionMargin"], ConvexInternalShapeFloatData.Offset("CollisionMargin"));
            SetVector4Value(writer, element["m_localScaling"], ConvexInternalShapeFloatData.Offset("LocalScaling"));
            SetVector4Value(writer, element["m_implicitShapeDimensions"], ConvexInternalShapeFloatData.Offset("ImplicitShapeDimensions"));
        }
        private void DeSerializeVector3FloatData(XmlElement element)
        {
            int ptr = int.Parse(element.GetAttribute("pointer"));

            XmlNodeList vectors = element.SelectNodes("m_floats");
            int numVectors = vectors.Count;

            int vectorSize = Marshal.SizeOf(typeof(Vector3FloatData));
            byte[] v = new byte[numVectors * vectorSize];

            using (var stream = new MemoryStream(v))
            {
                using (var writer = new BulletWriter(stream))
                {
                    int offset = 0;
                    for (int i = 0; i < numVectors; i++)
                    {
                        SetVector4Value(writer, vectors[i], offset);
                        offset += vectorSize;
                    }
                }
            }

            _pointerLookup.Add(ptr, v);
        }
예제 #14
0
 private void SetPointerValue(BulletWriter writer, XmlNode valueNode, int offset)
 {
     writer.Write(new IntPtr(long.Parse(valueNode.InnerText)), offset);
 }
예제 #15
0
 private void SetFloatValue(BulletWriter writer, XmlNode valueNode, int offset)
 {
     writer.Write(Scalar.Parse(valueNode.InnerText, CultureInfo.InvariantCulture), offset);
 }
        private void DeSerializeConvexHullShapeData(XmlElement element)
        {
            int ptr = int.Parse(element.GetAttribute("pointer"));
            byte[] convexHullData = new byte[Marshal.SizeOf(typeof(ConvexHullShapeFloatData))];

            using (var stream = new MemoryStream(convexHullData))
            {
                using (var writer = new BulletWriter(stream))
                {
                    XmlNode node = element["m_convexInternalShapeData"];
                    if (node == null)
                    {
                        return;
                    }
                    DeSerializeConvexInternalShapeData(node as XmlElement, writer);

                    SetPointerValue(writer, element["m_unscaledPointsFloatPtr"], ConvexHullShapeFloatData.Offset("UnscaledPointsFloatPtr"));
                    SetPointerValue(writer, element["m_unscaledPointsFloatPtr"], ConvexHullShapeFloatData.Offset("UnscaledPointsFloatPtr"));
                    SetIntValue(writer, element["m_numUnscaledPoints"], ConvexHullShapeFloatData.Offset("NumUnscaledPoints"));
                }
            }

            _collisionShapeData.Add(convexHullData);
            _pointerLookup.Add(ptr, convexHullData);
        }
예제 #17
0
 private void SetTransformValue(BulletWriter writer, XmlNode valueNode, int offset)
 {
     SetMatrix3x3Value(writer, valueNode["m_basis"], offset);
     SetVector4Value(writer, valueNode["m_origin"], offset + TransformFloatData.OriginOffset);
 }
 private void SetVector4Value(BulletWriter writer, XmlNode valueNode, int offset)
 {
     int i = 0;
     foreach (string value in valueNode.InnerText.Split(' '))
     {
         if (!string.IsNullOrWhiteSpace(value))
         {
             writer.Write(float.Parse(value, CultureInfo.InvariantCulture), offset + i * sizeof(float));
             i++;
             if (i == 4)
             {
                 break;
             }
         }
     }
 }
 private void SetTransformValue(BulletWriter writer, XmlNode valueNode, int offset)
 {
     SetMatrix3x3Value(writer, valueNode["m_basis"], offset);
     SetVector4Value(writer, valueNode["m_origin"], offset + TransformFloatData.OriginOffset);
 }
 private void SetPointerValue(BulletWriter writer, XmlNode valueNode, int offset)
 {
     writer.Write(new IntPtr(long.Parse(valueNode.InnerText)), offset);
 }
 private void SetMatrix3x3Value(BulletWriter writer, XmlElement valueNode, int offset)
 {
     XmlNode floats = valueNode["m_el"]["m_floats"];
     SetVector4Value(writer, floats, offset);
     floats = floats.NextSibling;
     SetVector4Value(writer, floats, offset + 16);
     floats = floats.NextSibling;
     SetVector4Value(writer, floats, offset + 32);
 }
 private void SetIntValue(BulletWriter writer, XmlNode valueNode, int offset)
 {
     writer.Write(int.Parse(valueNode.InnerText), offset);
 }
 private void SetFloatValue(BulletWriter writer, XmlNode valueNode, int offset)
 {
     writer.Write(float.Parse(valueNode.InnerText, CultureInfo.InvariantCulture), offset);
 }
        private void DeSerializeCompoundShapeChildData(XmlElement element)
        {
            int ptr = int.Parse(element.GetAttribute("pointer"));

            XmlNodeList transforms = element.SelectNodes("m_transform");
            XmlNodeList childShapes = element.SelectNodes("m_childShape");
            XmlNodeList childShapeTypes = element.SelectNodes("m_childShapeType");
            XmlNodeList childMargins = element.SelectNodes("m_childMargin");

            int numChildren = transforms.Count;
            int dataSize = Marshal.SizeOf(typeof(CompoundShapeChildFloatData));
            byte[] compoundChild = new byte[dataSize * numChildren];

            using (var stream = new MemoryStream(compoundChild))
            {
                using (var writer = new BulletWriter(stream))
                {
                    int offset = 0;
                    for (int i = 0; i < numChildren; i++)
                    {
                        SetTransformValue(writer, transforms[i], offset + CompoundShapeChildFloatData.Offset("Transform"));
                        SetPointerValue(writer, childShapes[i], offset + CompoundShapeChildFloatData.Offset("ChildShape"));
                        SetIntValue(writer, childShapeTypes[i], offset + CompoundShapeChildFloatData.Offset("ChildShapeType"));
                        SetFloatValue(writer, childMargins[i], offset + CompoundShapeChildFloatData.Offset("ChildMargin"));

                        offset += dataSize;
                    }
                }
            }

            _pointerLookup.Add(ptr, compoundChild);
        }
예제 #25
0
        private void DeSerializeRigidBodyFloatData(XmlElement element)
        {
            int ptr;

            if (!int.TryParse(element.GetAttribute("pointer"), out ptr))
            {
                _fileOK = false;
                return;
            }

            byte[] rbData = new byte[Marshal.SizeOf(typeof(RigidBodyFloatData))];

            using (var stream = new MemoryStream(rbData))
            {
                using (var writer = new BulletWriter(stream))
                {
                    XmlNode node = element["m_collisionObjectData"];
                    if (node == null)
                    {
                        return;
                    }
                    SetPointerValue(writer, node["m_collisionShape"], CollisionObjectFloatData.Offset("CollisionShape"));
                    SetTransformValue(writer, node["m_worldTransform"], CollisionObjectFloatData.Offset("WorldTransform"));
                    SetTransformValue(writer, node["m_interpolationWorldTransform"], CollisionObjectFloatData.Offset("InterpolationWorldTransform"));
                    SetVector4Value(writer, node["m_interpolationLinearVelocity"], CollisionObjectFloatData.Offset("InterpolationLinearVelocity"));
                    SetVector4Value(writer, node["m_interpolationAngularVelocity"], CollisionObjectFloatData.Offset("InterpolationAngularVelocity"));
                    SetVector4Value(writer, node["m_anisotropicFriction"], CollisionObjectFloatData.Offset("AnisotropicFriction"));
                    SetFloatValue(writer, node["m_contactProcessingThreshold"], CollisionObjectFloatData.Offset("ContactProcessingThreshold"));
                    SetFloatValue(writer, node["m_deactivationTime"], CollisionObjectFloatData.Offset("DeactivationTime"));
                    SetFloatValue(writer, node["m_friction"], CollisionObjectFloatData.Offset("Friction"));
                    SetFloatValue(writer, node["m_restitution"], CollisionObjectFloatData.Offset("Restitution"));
                    SetFloatValue(writer, node["m_hitFraction"], CollisionObjectFloatData.Offset("HitFraction"));
                    SetFloatValue(writer, node["m_ccdSweptSphereRadius"], CollisionObjectFloatData.Offset("CcdSweptSphereRadius"));
                    SetFloatValue(writer, node["m_ccdMotionThreshold"], CollisionObjectFloatData.Offset("CcdMotionThreshold"));
                    SetIntValue(writer, node["m_hasAnisotropicFriction"], CollisionObjectFloatData.Offset("HasAnisotropicFriction"));
                    SetIntValue(writer, node["m_collisionFlags"], CollisionObjectFloatData.Offset("CollisionFlags"));
                    SetIntValue(writer, node["m_islandTag1"], CollisionObjectFloatData.Offset("IslandTag1"));
                    SetIntValue(writer, node["m_companionId"], CollisionObjectFloatData.Offset("CompanionId"));
                    SetIntValue(writer, node["m_activationState1"], CollisionObjectFloatData.Offset("ActivationState1"));
                    SetIntValue(writer, node["m_internalType"], CollisionObjectFloatData.Offset("InternalType"));
                    SetIntValue(writer, node["m_checkCollideWith"], CollisionObjectFloatData.Offset("CheckCollideWith"));

                    SetMatrix3x3Value(writer, element["m_invInertiaTensorWorld"], RigidBodyFloatData.Offset("InvInertiaTensorWorld"));
                    SetVector4Value(writer, element["m_linearVelocity"], RigidBodyFloatData.Offset("LinearVelocity"));
                    SetVector4Value(writer, element["m_angularVelocity"], RigidBodyFloatData.Offset("AngularVelocity"));
                    SetVector4Value(writer, element["m_angularFactor"], RigidBodyFloatData.Offset("AngularFactor"));
                    SetVector4Value(writer, element["m_linearFactor"], RigidBodyFloatData.Offset("LinearFactor"));
                    SetVector4Value(writer, element["m_gravity"], RigidBodyFloatData.Offset("Gravity"));
                    SetVector4Value(writer, element["m_gravity_acceleration"], RigidBodyFloatData.Offset("GravityAcceleration"));
                    SetVector4Value(writer, element["m_invInertiaLocal"], RigidBodyFloatData.Offset("InvInertiaLocal"));
                    SetVector4Value(writer, element["m_totalTorque"], RigidBodyFloatData.Offset("TotalTorque"));
                    SetVector4Value(writer, element["m_totalForce"], RigidBodyFloatData.Offset("TotalForce"));
                    SetFloatValue(writer, element["m_inverseMass"], RigidBodyFloatData.Offset("InverseMass"));
                    SetFloatValue(writer, element["m_linearDamping"], RigidBodyFloatData.Offset("LinearDamping"));
                    SetFloatValue(writer, element["m_angularDamping"], RigidBodyFloatData.Offset("AngularDamping"));
                    SetFloatValue(writer, element["m_additionalDampingFactor"], RigidBodyFloatData.Offset("AdditionalDampingFactor"));
                    SetFloatValue(writer, element["m_additionalLinearDampingThresholdSqr"], RigidBodyFloatData.Offset("AdditionalLinearDampingThresholdSqr"));
                    SetFloatValue(writer, element["m_additionalAngularDampingThresholdSqr"], RigidBodyFloatData.Offset("AdditionalAngularDampingThresholdSqr"));
                    SetFloatValue(writer, element["m_additionalAngularDampingFactor"], RigidBodyFloatData.Offset("AdditionalAngularDampingFactor"));
                    SetFloatValue(writer, element["m_angularSleepingThreshold"], RigidBodyFloatData.Offset("AngularSleepingThreshold"));
                    SetFloatValue(writer, element["m_linearSleepingThreshold"], RigidBodyFloatData.Offset("LinearSleepingThreshold"));
                    SetIntValue(writer, element["m_additionalDamping"], RigidBodyFloatData.Offset("AdditionalDamping"));
                }
            }

            _rigidBodyData.Add(rbData);
        }
예제 #26
0
 private void DeSerializeCollisionShapeData(XmlElement parent, BulletWriter writer)
 {
     SetIntValue(writer, parent["m_shapeType"], CollisionShapeData.Offset("ShapeType"));
     writer.Write(0, CollisionShapeData.Offset("Name"));
 }
        private void DeSerializeCompoundShapeData(XmlElement element)
        {
            int ptr = int.Parse(element.GetAttribute("pointer"));
            byte[] convexShape = new byte[Marshal.SizeOf(typeof(CompoundShapeFloatData))];

            using (var stream = new MemoryStream(convexShape))
            {
                using (var writer = new BulletWriter(stream))
                {
                    XmlNode node = element["m_collisionShapeData"];
                    if (node == null)
                    {
                        return;
                    }
                    DeSerializeCollisionShapeData(node as XmlElement, writer);

                    SetIntValue(writer, element["m_numChildShapes"], CompoundShapeFloatData.Offset("NumChildShapes"));
                    SetPointerValue(writer, element["m_childShapePtr"], CompoundShapeFloatData.Offset("ChildShapePtr"));
                    SetFloatValue(writer, element["m_collisionMargin"], CompoundShapeFloatData.Offset("CollisionMargin"));
                }
            }

            _collisionShapeData.Add(convexShape);
            _pointerLookup.Add(ptr, convexShape);
        }
        private void DeSerializeRigidBodyFloatData(XmlElement element)
        {
            int ptr;
            if (!int.TryParse(element.GetAttribute("pointer"), out ptr))
            {
                _fileOK = false;
                return;
            }

            byte[] rbData = new byte[Marshal.SizeOf(typeof(RigidBodyFloatData))];

            using (var stream = new MemoryStream(rbData))
            {
                using (var writer = new BulletWriter(stream))
                {
                    XmlNode node = element["m_collisionObjectData"];
                    if (node == null)
                    {
                        return;
                    }
                    SetPointerValue(writer, node["m_collisionShape"], CollisionObjectFloatData.Offset("CollisionShape"));
                    SetTransformValue(writer, node["m_worldTransform"], CollisionObjectFloatData.Offset("WorldTransform"));
                    SetTransformValue(writer, node["m_interpolationWorldTransform"], CollisionObjectFloatData.Offset("InterpolationWorldTransform"));
                    SetVector4Value(writer, node["m_interpolationLinearVelocity"], CollisionObjectFloatData.Offset("InterpolationLinearVelocity"));
                    SetVector4Value(writer, node["m_interpolationAngularVelocity"], CollisionObjectFloatData.Offset("InterpolationAngularVelocity"));
                    SetVector4Value(writer, node["m_anisotropicFriction"], CollisionObjectFloatData.Offset("AnisotropicFriction"));
                    SetFloatValue(writer, node["m_contactProcessingThreshold"], CollisionObjectFloatData.Offset("ContactProcessingThreshold"));
                    SetFloatValue(writer, node["m_deactivationTime"], CollisionObjectFloatData.Offset("DeactivationTime"));
                    SetFloatValue(writer, node["m_friction"], CollisionObjectFloatData.Offset("Friction"));
                    SetFloatValue(writer, node["m_restitution"], CollisionObjectFloatData.Offset("Restitution"));
                    SetFloatValue(writer, node["m_hitFraction"], CollisionObjectFloatData.Offset("HitFraction"));
                    SetFloatValue(writer, node["m_ccdSweptSphereRadius"], CollisionObjectFloatData.Offset("CcdSweptSphereRadius"));
                    SetFloatValue(writer, node["m_ccdMotionThreshold"], CollisionObjectFloatData.Offset("CcdMotionThreshold"));
                    SetIntValue(writer, node["m_hasAnisotropicFriction"], CollisionObjectFloatData.Offset("HasAnisotropicFriction"));
                    SetIntValue(writer, node["m_collisionFlags"], CollisionObjectFloatData.Offset("CollisionFlags"));
                    SetIntValue(writer, node["m_islandTag1"], CollisionObjectFloatData.Offset("IslandTag1"));
                    SetIntValue(writer, node["m_companionId"], CollisionObjectFloatData.Offset("CompanionId"));
                    SetIntValue(writer, node["m_activationState1"], CollisionObjectFloatData.Offset("ActivationState1"));
                    SetIntValue(writer, node["m_internalType"], CollisionObjectFloatData.Offset("InternalType"));
                    SetIntValue(writer, node["m_checkCollideWith"], CollisionObjectFloatData.Offset("CheckCollideWith"));

                    SetMatrix3x3Value(writer, element["m_invInertiaTensorWorld"], RigidBodyFloatData.Offset("InvInertiaTensorWorld"));
                    SetVector4Value(writer, element["m_linearVelocity"], RigidBodyFloatData.Offset("LinearVelocity"));
                    SetVector4Value(writer, element["m_angularVelocity"], RigidBodyFloatData.Offset("AngularVelocity"));
                    SetVector4Value(writer, element["m_angularFactor"], RigidBodyFloatData.Offset("AngularFactor"));
                    SetVector4Value(writer, element["m_linearFactor"], RigidBodyFloatData.Offset("LinearFactor"));
                    SetVector4Value(writer, element["m_gravity"], RigidBodyFloatData.Offset("Gravity"));
                    SetVector4Value(writer, element["m_gravity_acceleration"], RigidBodyFloatData.Offset("GravityAcceleration"));
                    SetVector4Value(writer, element["m_invInertiaLocal"], RigidBodyFloatData.Offset("InvInertiaLocal"));
                    SetVector4Value(writer, element["m_totalTorque"], RigidBodyFloatData.Offset("TotalTorque"));
                    SetVector4Value(writer, element["m_totalForce"], RigidBodyFloatData.Offset("TotalForce"));
                    SetFloatValue(writer, element["m_inverseMass"], RigidBodyFloatData.Offset("InverseMass"));
                    SetFloatValue(writer, element["m_linearDamping"], RigidBodyFloatData.Offset("LinearDamping"));
                    SetFloatValue(writer, element["m_angularDamping"], RigidBodyFloatData.Offset("AngularDamping"));
                    SetFloatValue(writer, element["m_additionalDampingFactor"], RigidBodyFloatData.Offset("AdditionalDampingFactor"));
                    SetFloatValue(writer, element["m_additionalLinearDampingThresholdSqr"], RigidBodyFloatData.Offset("AdditionalLinearDampingThresholdSqr"));
                    SetFloatValue(writer, element["m_additionalAngularDampingThresholdSqr"], RigidBodyFloatData.Offset("AdditionalAngularDampingThresholdSqr"));
                    SetFloatValue(writer, element["m_additionalAngularDampingFactor"], RigidBodyFloatData.Offset("AdditionalAngularDampingFactor"));
                    SetFloatValue(writer, element["m_angularSleepingThreshold"], RigidBodyFloatData.Offset("AngularSleepingThreshold"));
                    SetFloatValue(writer, element["m_linearSleepingThreshold"], RigidBodyFloatData.Offset("LinearSleepingThreshold"));
                    SetIntValue(writer, element["m_additionalDamping"], RigidBodyFloatData.Offset("AdditionalDamping"));
                }
            }

            _rigidBodyData.Add(rbData);
        }
예제 #29
0
 private void SetIntValue(BulletWriter writer, XmlNode valueNode, int offset)
 {
     writer.Write(int.Parse(valueNode.InnerText), offset);
 }
        private void DeSerializeGeneric6DofConstraintData(XmlElement element)
        {
            int ptr = int.Parse(element.GetAttribute("pointer"));
            byte[] dof6Data = new byte[Marshal.SizeOf(typeof(Generic6DofConstraintFloatData))];

            using (var stream = new MemoryStream(dof6Data))
            {
                using (var writer = new BulletWriter(stream))
                {
                    XmlNode node = element["m_typeConstraintData"];
                    if (node == null)
                    {
                        return;
                    }
                    SetPointerValue(writer, node["m_rbA"], TypedConstraintFloatData.Offset("RigidBodyA"));
                    SetPointerValue(writer, node["m_rbB"], TypedConstraintFloatData.Offset("RigidBodyB"));
                    writer.Write(0, TypedConstraintFloatData.Offset("Name"));
                    SetIntValue(writer, node["m_objectType"], TypedConstraintFloatData.Offset("ObjectType"));
                    SetIntValue(writer, node["m_userConstraintType"], TypedConstraintFloatData.Offset("UserConstraintType"));
                    SetIntValue(writer, node["m_userConstraintId"], TypedConstraintFloatData.Offset("UserConstraintId"));
                    SetIntValue(writer, node["m_needsFeedback"], TypedConstraintFloatData.Offset("NeedsFeedback"));
                    SetFloatValue(writer, node["m_appliedImpulse"], TypedConstraintFloatData.Offset("AppliedImpulse"));
                    SetFloatValue(writer, node["m_dbgDrawSize"], TypedConstraintFloatData.Offset("DebugDrawSize"));
                    SetIntValue(writer, node["m_disableCollisionsBetweenLinkedBodies"], TypedConstraintFloatData.Offset("DisableCollisionsBetweenLinkedBodies"));
                    SetIntValue(writer, node["m_overrideNumSolverIterations"], TypedConstraintFloatData.Offset("OverrideNumSolverIterations"));
                    SetFloatValue(writer, node["m_breakingImpulseThreshold"], TypedConstraintFloatData.Offset("BreakingImpulseThreshold"));
                    SetIntValue(writer, node["m_isEnabled"], TypedConstraintFloatData.Offset("IsEnabled"));

                    SetTransformValue(writer, element["m_rbAFrame"], Generic6DofConstraintFloatData.Offset("RigidBodyAFrame"));
                    SetTransformValue(writer, element["m_rbBFrame"], Generic6DofConstraintFloatData.Offset("RigidBodyBFrame"));
                    SetVector4Value(writer, element["m_linearUpperLimit"], Generic6DofConstraintFloatData.Offset("LinearUpperLimit"));
                    SetVector4Value(writer, element["m_linearLowerLimit"], Generic6DofConstraintFloatData.Offset("LinearLowerLimit"));
                    SetVector4Value(writer, element["m_angularUpperLimit"], Generic6DofConstraintFloatData.Offset("AngularUpperLimit"));
                    SetVector4Value(writer, element["m_angularLowerLimit"], Generic6DofConstraintFloatData.Offset("AngularLowerLimit"));
                    SetIntValue(writer, element["m_useLinearReferenceFrameA"], Generic6DofConstraintFloatData.Offset("UseLinearReferenceFrameA"));
                    SetIntValue(writer, element["m_useOffsetForConstraintFrame"], Generic6DofConstraintFloatData.Offset("UseOffsetForConstraintFrame"));
                }
            }

            _constraintData.Add(dof6Data);
        }
        public bool ConvertAllObjects(BulletFile file)
        {
            _shapeMap.Clear();
            _bodyMap.Clear();

            foreach (byte[] bvhData in file._bvhs)
            {
                OptimizedBvh bvh = CreateOptimizedBvh();

                if ((file.Flags & FileFlags.DoublePrecision) != 0)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    // QuantizedBvhData is parsed in C++, so we need to actually fix pointers
                    GCHandle bvhDataHandle = GCHandle.Alloc(bvhData, GCHandleType.Pinned);
                    IntPtr bvhDataPinnedPtr = bvhDataHandle.AddrOfPinnedObject();

                    IntPtr contiguousNodesHandlePtr = IntPtr.Zero;
                    IntPtr quantizedContiguousNodesHandlePtr = IntPtr.Zero;
                    IntPtr subTreeInfoHandlePtr = IntPtr.Zero;

                    using (MemoryStream stream = new MemoryStream(bvhData))
                    {
                        using (BulletReader reader = new BulletReader(stream))
                        {
                            long contiguousNodesPtr = reader.ReadPtr(QuantizedBvhFloatData.Offset("ContiguousNodesPtr"));
                            long quantizedContiguousNodesPtr = reader.ReadPtr(QuantizedBvhFloatData.Offset("QuantizedContiguousNodesPtr"));
                            long subTreeInfoPtr = reader.ReadPtr(QuantizedBvhFloatData.Offset("SubTreeInfoPtr"));

                            using (BulletWriter writer = new BulletWriter(stream))
                            {
                                if (contiguousNodesPtr != 0)
                                {
                                    GCHandle contiguousNodesHandle = GCHandle.Alloc(file.LibPointers[contiguousNodesPtr], GCHandleType.Pinned);
                                    contiguousNodesHandlePtr = GCHandle.ToIntPtr(contiguousNodesHandle);
                                    stream.Position = QuantizedBvhFloatData.Offset("ContiguousNodesPtr");
                                    writer.Write(contiguousNodesHandle.AddrOfPinnedObject());
                                }
                                if (quantizedContiguousNodesPtr != 0)
                                {
                                    GCHandle quantizedContiguousNodesHandle = GCHandle.Alloc(file.LibPointers[quantizedContiguousNodesPtr], GCHandleType.Pinned);
                                    quantizedContiguousNodesHandlePtr = GCHandle.ToIntPtr(quantizedContiguousNodesHandle);
                                    stream.Position = QuantizedBvhFloatData.Offset("QuantizedContiguousNodesPtr");
                                    writer.Write(quantizedContiguousNodesHandle.AddrOfPinnedObject());
                                }
                                if (subTreeInfoPtr != 0)
                                {
                                    GCHandle subTreeInfoHandle = GCHandle.Alloc(file.LibPointers[subTreeInfoPtr], GCHandleType.Pinned);
                                    subTreeInfoHandlePtr = GCHandle.ToIntPtr(subTreeInfoHandle);
                                    stream.Position = QuantizedBvhFloatData.Offset("SubTreeInfoPtr");
                                    writer.Write(subTreeInfoHandle.AddrOfPinnedObject());
                                }
                            }
                        }
                    }

                    bvh.DeSerializeFloat(bvhDataPinnedPtr);
                    bvhDataHandle.Free();

                    if (contiguousNodesHandlePtr != IntPtr.Zero)
                    {
                        GCHandle.FromIntPtr(contiguousNodesHandlePtr).Free();
                    }
                    if (quantizedContiguousNodesHandlePtr != IntPtr.Zero)
                    {
                        GCHandle.FromIntPtr(quantizedContiguousNodesHandlePtr).Free();
                    }
                    if (subTreeInfoHandlePtr != IntPtr.Zero)
                    {
                        GCHandle.FromIntPtr(subTreeInfoHandlePtr).Free();
                    }
                }

                foreach (KeyValuePair<long, byte[]> lib in file.LibPointers)
                {
                    if (lib.Value == bvhData)
                    {
                        _bvhMap.Add(lib.Key, bvh);
                        break;
                    }
                }
            }

            foreach (byte[] shapeData in file._collisionShapes)
            {
                CollisionShape shape = ConvertCollisionShape(shapeData, file.LibPointers);
                if (shape != null)
                {
                    foreach (KeyValuePair<long, byte[]> lib in file.LibPointers)
                    {
                        if (lib.Value == shapeData)
                        {
                            _shapeMap.Add(lib.Key, shape);
                            break;
                        }
                    }

                    using (MemoryStream stream = new MemoryStream(shapeData, false))
                    {
                        using (BulletReader reader = new BulletReader(stream))
                        {
                            long namePtr = reader.ReadPtr(CollisionShapeFloatData.Offset("Name"));
                            if (namePtr != 0)
                            {
                                byte[] nameData = file.LibPointers[namePtr];
                                int length = Array.IndexOf(nameData, (byte)0);
                                string name = System.Text.Encoding.ASCII.GetString(nameData, 0, length);
                                _objectNameMap.Add(shape, name);
                                _nameShapeMap.Add(name, shape);
                            }
                        }
                    }
                }
            }

            foreach (byte[] solverInfoData in file._dynamicsWorldInfo)
            {
                if ((file.Flags & FileFlags.DoublePrecision) != 0)
                {
                    //throw new NotImplementedException();
                }
                else
                {
                    //throw new NotImplementedException();
                }
            }

            foreach (byte[] bodyData in file._rigidBodies)
            {
                if ((file.Flags & FileFlags.DoublePrecision) != 0)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    ConvertRigidBodyFloat(bodyData, file.LibPointers);
                }
            }

            foreach (byte[] colObjData in file._collisionObjects)
            {
                if ((file.Flags & FileFlags.DoublePrecision) != 0)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    using (MemoryStream colObjStream = new MemoryStream(colObjData, false))
                    {
                        using (BulletReader colObjReader = new BulletReader(colObjStream))
                        {
                            long shapePtr = colObjReader.ReadPtr(CollisionObjectFloatData.Offset("CollisionShape"));
                            CollisionShape shape = _shapeMap[shapePtr];
                            Math.Matrix startTransform = colObjReader.ReadMatrix(CollisionObjectFloatData.Offset("WorldTransform"));
                            long namePtr = colObjReader.ReadPtr(CollisionObjectFloatData.Offset("Name"));
                            string name = null;
                            if (namePtr != 0)
                            {
                                byte[] nameData = file.FindLibPointer(namePtr);
                                int length = Array.IndexOf(nameData, (byte)0);
                                name = System.Text.Encoding.ASCII.GetString(nameData, 0, length);
                            }
                            CollisionObject colObj = CreateCollisionObject(ref startTransform, shape, name);
                            _bodyMap.Add(colObjData, colObj);
                        }
                    }
                }
            }

            foreach (byte[] constraintData in file._constraints)
            {
                MemoryStream stream = new MemoryStream(constraintData, false);
                using (BulletReader reader = new BulletReader(stream))
                {
                    long collisionObjectAPtr = reader.ReadPtr(TypedConstraintFloatData.Offset("RigidBodyA"));
                    long collisionObjectBPtr = reader.ReadPtr(TypedConstraintFloatData.Offset("RigidBodyB"));

                    RigidBody a = null, b = null;

                    if (collisionObjectAPtr != 0)
                    {
                        if (!file.LibPointers.ContainsKey(collisionObjectAPtr))
                        {
                            a = TypedConstraint.GetFixedBody();
                        }
                        else
                        {
                            byte[] coData = file.LibPointers[collisionObjectAPtr];
                            a = RigidBody.Upcast(_bodyMap[coData]);
                            if (a == null)
                            {
                                a = TypedConstraint.GetFixedBody();
                            }
                        }
                    }

                    if (collisionObjectBPtr != 0)
                    {
                        if (!file.LibPointers.ContainsKey(collisionObjectBPtr))
                        {
                            b = TypedConstraint.GetFixedBody();
                        }
                        else
                        {
                            byte[] coData = file.LibPointers[collisionObjectBPtr];
                            b = RigidBody.Upcast(_bodyMap[coData]);
                            if (b == null)
                            {
                                b = TypedConstraint.GetFixedBody();
                            }
                        }
                    }

                    if (a == null && b == null)
                    {
                        stream.Dispose();
                        continue;
                    }

                    if ((file.Flags & FileFlags.DoublePrecision) != 0)
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
                        ConvertConstraintFloat(a, b, constraintData, file.Version, file.LibPointers);
                    }
                }
                stream.Dispose();
            }

            return true;
        }
        private void DeSerializeStaticPlaneShapeData(XmlElement element)
        {
            int ptr = int.Parse(element.GetAttribute("pointer"));
            byte[] convexShape = new byte[Marshal.SizeOf(typeof(StaticPlaneShapeFloatData))];

            using (var stream = new MemoryStream(convexShape))
            {
                using (var writer = new BulletWriter(stream))
                {
                    XmlNode node = element["m_collisionShapeData"];
                    if (node == null)
                    {
                        return;
                    }
                    DeSerializeCollisionShapeData(node as XmlElement, writer);

                    SetVector4Value(writer, element["m_localScaling"], StaticPlaneShapeFloatData.Offset("LocalScaling"));
                    SetVector4Value(writer, element["m_planeNormal"], StaticPlaneShapeFloatData.Offset("PlaneNormal"));
                    SetFloatValue(writer, element["m_planeConstant"], StaticPlaneShapeFloatData.Offset("PlaneConstant"));
                }
            }

            _collisionShapeData.Add(convexShape);
            _pointerLookup.Add(ptr, convexShape);
        }
예제 #33
0
        public bool ConvertAllObjects(BulletFile file)
        {
            _shapeMap.Clear();
            _bodyMap.Clear();

            foreach (byte[] bvhData in file.Bvhs)
            {
                OptimizedBvh bvh = CreateOptimizedBvh();

                if ((file.Flags & FileFlags.DoublePrecision) != 0)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    // QuantizedBvhData is parsed in C++, so we need to actually fix pointers
                    GCHandle bvhDataHandle    = GCHandle.Alloc(bvhData, GCHandleType.Pinned);
                    IntPtr   bvhDataPinnedPtr = bvhDataHandle.AddrOfPinnedObject();

                    IntPtr contiguousNodesHandlePtr          = IntPtr.Zero;
                    IntPtr quantizedContiguousNodesHandlePtr = IntPtr.Zero;
                    IntPtr subTreeInfoHandlePtr = IntPtr.Zero;

                    using (var stream = new MemoryStream(bvhData))
                    {
                        using (var reader = new BulletReader(stream))
                        {
                            long contiguousNodesPtr          = reader.ReadPtr(QuantizedBvhFloatData.Offset("ContiguousNodesPtr"));
                            long quantizedContiguousNodesPtr = reader.ReadPtr(QuantizedBvhFloatData.Offset("QuantizedContiguousNodesPtr"));
                            long subTreeInfoPtr = reader.ReadPtr(QuantizedBvhFloatData.Offset("SubTreeInfoPtr"));

                            using (var writer = new BulletWriter(stream))
                            {
                                if (contiguousNodesPtr != 0)
                                {
                                    GCHandle contiguousNodesHandle = GCHandle.Alloc(file.LibPointers[contiguousNodesPtr], GCHandleType.Pinned);
                                    contiguousNodesHandlePtr = GCHandle.ToIntPtr(contiguousNodesHandle);
                                    stream.Position          = QuantizedBvhFloatData.Offset("ContiguousNodesPtr");
                                    writer.Write(contiguousNodesHandle.AddrOfPinnedObject());
                                }
                                if (quantizedContiguousNodesPtr != 0)
                                {
                                    GCHandle quantizedContiguousNodesHandle = GCHandle.Alloc(file.LibPointers[quantizedContiguousNodesPtr], GCHandleType.Pinned);
                                    quantizedContiguousNodesHandlePtr = GCHandle.ToIntPtr(quantizedContiguousNodesHandle);
                                    stream.Position = QuantizedBvhFloatData.Offset("QuantizedContiguousNodesPtr");
                                    writer.Write(quantizedContiguousNodesHandle.AddrOfPinnedObject());
                                }
                                if (subTreeInfoPtr != 0)
                                {
                                    GCHandle subTreeInfoHandle = GCHandle.Alloc(file.LibPointers[subTreeInfoPtr], GCHandleType.Pinned);
                                    subTreeInfoHandlePtr = GCHandle.ToIntPtr(subTreeInfoHandle);
                                    stream.Position      = QuantizedBvhFloatData.Offset("SubTreeInfoPtr");
                                    writer.Write(subTreeInfoHandle.AddrOfPinnedObject());
                                }
                            }
                        }
                    }

                    bvh.DeSerializeFloat(bvhDataPinnedPtr);
                    bvhDataHandle.Free();

                    if (contiguousNodesHandlePtr != IntPtr.Zero)
                    {
                        GCHandle.FromIntPtr(contiguousNodesHandlePtr).Free();
                    }
                    if (quantizedContiguousNodesHandlePtr != IntPtr.Zero)
                    {
                        GCHandle.FromIntPtr(quantizedContiguousNodesHandlePtr).Free();
                    }
                    if (subTreeInfoHandlePtr != IntPtr.Zero)
                    {
                        GCHandle.FromIntPtr(subTreeInfoHandlePtr).Free();
                    }
                }

                foreach (KeyValuePair <long, byte[]> lib in file.LibPointers)
                {
                    if (lib.Value == bvhData)
                    {
                        _bvhMap.Add(lib.Key, bvh);
                        break;
                    }
                }
            }

            foreach (byte[] shapeData in file.CollisionShapes)
            {
                CollisionShape shape = ConvertCollisionShape(shapeData, file.LibPointers);
                if (shape != null)
                {
                    foreach (KeyValuePair <long, byte[]> lib in file.LibPointers)
                    {
                        if (lib.Value == shapeData)
                        {
                            _shapeMap.Add(lib.Key, shape);
                            break;
                        }
                    }

                    using (var stream = new MemoryStream(shapeData, false))
                    {
                        using (var reader = new BulletReader(stream))
                        {
                            long namePtr = reader.ReadPtr(CollisionShapeFloatData.Offset("Name"));
                            if (namePtr != 0)
                            {
                                byte[] nameData = file.LibPointers[namePtr];
                                int    length   = Array.IndexOf(nameData, (byte)0);
                                string name     = System.Text.Encoding.ASCII.GetString(nameData, 0, length);
                                _objectNameMap.Add(shape, name);
                                _nameShapeMap.Add(name, shape);
                            }
                        }
                    }
                }
            }

            foreach (byte[] solverInfoData in file.DynamicsWorldInfo)
            {
                if ((file.Flags & FileFlags.DoublePrecision) != 0)
                {
                    //throw new NotImplementedException();
                }
                else
                {
                    //throw new NotImplementedException();
                }
            }

            foreach (byte[] bodyData in file.RigidBodies)
            {
                if ((file.Flags & FileFlags.DoublePrecision) != 0)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    ConvertRigidBodyFloat(bodyData, file.LibPointers);
                }
            }

            foreach (byte[] colObjData in file.CollisionObjects)
            {
                if ((file.Flags & FileFlags.DoublePrecision) != 0)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    using (var colObjStream = new MemoryStream(colObjData, false))
                    {
                        using (var colObjReader = new BulletReader(colObjStream))
                        {
                            long           shapePtr       = colObjReader.ReadPtr(CollisionObjectFloatData.Offset("CollisionShape"));
                            CollisionShape shape          = _shapeMap[shapePtr];
                            Math.Matrix    startTransform = colObjReader.ReadMatrix(CollisionObjectFloatData.Offset("WorldTransform"));
                            long           namePtr        = colObjReader.ReadPtr(CollisionObjectFloatData.Offset("Name"));
                            string         name           = null;
                            if (namePtr != 0)
                            {
                                byte[] nameData = file.FindLibPointer(namePtr);
                                int    length   = Array.IndexOf(nameData, (byte)0);
                                name = System.Text.Encoding.ASCII.GetString(nameData, 0, length);
                            }
                            CollisionObject colObj = CreateCollisionObject(ref startTransform, shape, name);
                            _bodyMap.Add(colObjData, colObj);
                        }
                    }
                }
            }

            foreach (byte[] constraintData in file.Constraints)
            {
                var stream = new MemoryStream(constraintData, false);
                using (var reader = new BulletReader(stream))
                {
                    long collisionObjectAPtr = reader.ReadPtr(TypedConstraintFloatData.Offset("RigidBodyA"));
                    long collisionObjectBPtr = reader.ReadPtr(TypedConstraintFloatData.Offset("RigidBodyB"));

                    RigidBody a = null, b = null;

                    if (collisionObjectAPtr != 0)
                    {
                        if (!file.LibPointers.ContainsKey(collisionObjectAPtr))
                        {
                            a = TypedConstraint.GetFixedBody();
                        }
                        else
                        {
                            byte[] coData = file.LibPointers[collisionObjectAPtr];
                            a = RigidBody.Upcast(_bodyMap[coData]);
                            if (a == null)
                            {
                                a = TypedConstraint.GetFixedBody();
                            }
                        }
                    }

                    if (collisionObjectBPtr != 0)
                    {
                        if (!file.LibPointers.ContainsKey(collisionObjectBPtr))
                        {
                            b = TypedConstraint.GetFixedBody();
                        }
                        else
                        {
                            byte[] coData = file.LibPointers[collisionObjectBPtr];
                            b = RigidBody.Upcast(_bodyMap[coData]);
                            if (b == null)
                            {
                                b = TypedConstraint.GetFixedBody();
                            }
                        }
                    }

                    if (a == null && b == null)
                    {
                        stream.Dispose();
                        continue;
                    }

                    if ((file.Flags & FileFlags.DoublePrecision) != 0)
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
                        ConvertConstraintFloat(a, b, constraintData, file.Version, file.LibPointers);
                    }
                }
                stream.Dispose();
            }

            return(true);
        }
 private void DeSerializeCollisionShapeData(XmlElement parent, BulletWriter writer)
 {
     SetIntValue(writer, parent["m_shapeType"], CollisionShapeFloatData.Offset("ShapeType"));
     writer.Write(0, CollisionShapeFloatData.Offset("Name"));
 }