public void ComposeShape() { ColliderShapeChanged = false; if (ColliderShape != null) { if (!ColliderShape.IsPartOfAsset) { ColliderShape.Dispose(); ColliderShape = null; } else { ColliderShape = null; } } CanScaleShape = true; if (ColliderShapes.Count == 1) //single shape case { if (ColliderShapes[0] == null) { return; } if (ColliderShapes[0].GetType() == typeof(ColliderShapeAssetDesc)) { CanScaleShape = false; } ColliderShape = PhysicsColliderShape.CreateShape(ColliderShapes[0]); ColliderShape?.UpdateLocalTransformations(); } else if (ColliderShapes.Count > 1) //need a compound shape in this case { var compound = new CompoundColliderShape(); foreach (var desc in ColliderShapes) { if (desc == null) { continue; } if (desc.GetType() == typeof(ColliderShapeAssetDesc)) { CanScaleShape = false; } var subShape = PhysicsColliderShape.CreateShape(desc); if (subShape != null) { compound.AddChildShape(subShape); } } ColliderShape = compound; ColliderShape.UpdateLocalTransformations(); } }
internal void DeriveBonePhysicsTransformation(out Matrix derivedTransformation) { Quaternion rotation; Vector3 translation; //derive rotation and translation, scale is ignored for now Vector3 scale; BoneWorldMatrix.Decompose(out scale, out rotation, out translation); derivedTransformation = Matrix.RotationQuaternion(rotation) * Matrix.Translation(translation); //handle dynamic scaling if allowed (aka not using assets) if (CanScaleShape) { if (scale != ColliderShape.Scaling) { ColliderShape.Scaling = scale; ColliderShape.UpdateLocalTransformations(); if (DebugEntity != null) { DebugEntity.Transform.Scale = scale; } } } //Handle collider shape offset if (ColliderShape.LocalOffset != Vector3.Zero || ColliderShape.LocalRotation != Quaternion.Identity) { derivedTransformation = Matrix.Multiply(ColliderShape.PositiveCenterMatrix, derivedTransformation); } }