3 using SiliconStudio.Core.Mathematics;
4 using SiliconStudio.Core.Serialization.Assets;
5 using SiliconStudio.Core.Serialization.Converters;
13 throw new NotImplementedException();
20 var type = desc.GetType();
24 var rotation = Quaternion.Identity;
25 shape =
new Box2DColliderShape(boxDesc.HalfExtent) { LocalOffset = boxDesc.LocalOffset, LocalRotation = rotation };
27 else if (type == typeof(BoxColliderShapeDesc))
29 var boxDesc = (BoxColliderShapeDesc)desc;
30 var rotation = Quaternion.Identity;
31 shape =
new BoxColliderShape(boxDesc.HalfExtents) { LocalOffset = boxDesc.LocalOffset, LocalRotation = rotation };
33 else if (type == typeof(CapsuleColliderShapeDesc))
35 var capsuleDesc = (CapsuleColliderShapeDesc)desc;
36 var rotation = Quaternion.Identity;
37 shape =
new CapsuleColliderShape(capsuleDesc.Is2D, capsuleDesc.Radius, capsuleDesc.Height, capsuleDesc.UpAxis) { LocalOffset = capsuleDesc.LocalOffset, LocalRotation = rotation };
39 else if (type == typeof(CylinderColliderShapeDesc))
41 var cylinderDesc = (CylinderColliderShapeDesc)desc;
42 var rotation = Quaternion.Identity;
43 shape =
new CylinderColliderShape(cylinderDesc.HalfExtents, cylinderDesc.UpAxis) { LocalOffset = cylinderDesc.LocalOffset, LocalRotation = rotation };
45 else if (type == typeof(SphereColliderShapeDesc))
47 var sphereDesc = (SphereColliderShapeDesc)desc;
48 shape =
new SphereColliderShape(sphereDesc.Is2D, sphereDesc.Radius) { LocalOffset = sphereDesc.LocalOffset };
50 else if (type == typeof(StaticPlaneColliderShapeDesc))
52 var planeDesc = (StaticPlaneColliderShapeDesc)desc;
53 shape =
new StaticPlaneColliderShape(planeDesc.Normal, planeDesc.Offset);
55 else if (type == typeof(ConvexHullColliderShapeDesc))
57 var convexDesc = (ConvexHullColliderShapeDesc)desc;
61 if (convexDesc.ConvexHulls.Count == 1)
63 if (convexDesc.ConvexHulls[0].Count == 1)
65 shape =
new ConvexHullColliderShape(convexDesc.ConvexHulls[0][0], convexDesc.ConvexHullsIndices[0][0])
67 NeedsCustomCollisionCallback =
true
70 shape.UpdateLocalTransformations();
75 if (convexDesc.ConvexHulls[0].Count <= 1)
return null;
77 var subCompound =
new CompoundColliderShape
79 NeedsCustomCollisionCallback =
true
82 for (var i = 0; i < convexDesc.ConvexHulls[0].Count; i++)
84 var verts = convexDesc.ConvexHulls[0][i];
85 var indices = convexDesc.ConvexHullsIndices[0][i];
87 var subHull =
new ConvexHullColliderShape(verts, indices);
88 subHull.UpdateLocalTransformations();
89 subCompound.AddChildShape(subHull);
92 subCompound.UpdateLocalTransformations();
97 if (convexDesc.ConvexHulls.Count <= 1)
return null;
99 var compound =
new CompoundColliderShape
101 NeedsCustomCollisionCallback =
true
104 for (var i = 0; i < convexDesc.ConvexHulls.Count; i++)
106 var verts = convexDesc.ConvexHulls[i];
107 var indices = convexDesc.ConvexHullsIndices[i];
109 if (verts.Count == 1)
111 var subHull =
new ConvexHullColliderShape(verts[0], indices[0]);
112 subHull.UpdateLocalTransformations();
113 compound.AddChildShape(subHull);
115 else if (verts.Count > 1)
117 var subCompound =
new CompoundColliderShape();
119 for (var
b = 0;
b < verts.Count;
b++)
121 var subVerts = verts[
b];
122 var subIndex = indices[
b];
124 var subHull =
new ConvexHullColliderShape(subVerts, subIndex);
125 subHull.UpdateLocalTransformations();
126 subCompound.AddChildShape(subHull);
129 subCompound.UpdateLocalTransformations();
131 compound.AddChildShape(subCompound);
135 compound.UpdateLocalTransformations();
140 if (shape != null) shape.UpdateLocalTransformations();
157 compound.AddChildShape(CreateShape(desc));
164 throw new NotImplementedException();
override void ConvertFromData(ConverterContext converterContext, PhysicsColliderShapeData data, ref PhysicsColliderShape obj)
Base class for converters to/from a data type.
List< IColliderShapeDesc > ColliderShapes
override void ConstructFromData(ConverterContext converterContext, PhysicsColliderShapeData data, ref PhysicsColliderShape obj)
using SiliconStudio.Paradox. Physics
override void ConvertToData(ConverterContext converterContext, ref PhysicsColliderShapeData data, PhysicsColliderShape obj)