وفي 12 أيار 2011 04:56 م، قال 16mofed84 متحمساً:
فهمت كيف تعمل لكن عندما جربت ان اضيف CCD SkeletonPer triangleلكنه يصدر خطأPhysXCore = new Core(new CoreDescription(), null);
PhysXCore.SetParameter(PhysicsParameter.VisualizationScale, 2.0f);
PhysXCore.SetParameter(PhysicsParameter.VisualizeCollisionShapes, true);
PhysXCore.SetParameter(PhysicsParameter.VisualizeClothMesh, true);
PhysXCore.SetParameter(PhysicsParameter.VisualizeJointLocalAxes, true);
PhysXCore.SetParameter(PhysicsParameter.VisualizeJointLimits, true);
PhysXCore.SetParameter(PhysicsParameter.VisualizeFluidPosition, true);
PhysXCore.SetParameter(PhysicsParameter.VisualizeFluidEmitters, false); // Slows down rendering a bit to much
PhysXCore.SetParameter(PhysicsParameter.VisualizeForceFields, true);
PhysXCore.SetParameter(PhysicsParameter.VisualizeSoftBodyMesh, true);
SceneDescription sceneDesc = new SceneDescription()
{
//SimulationType = SimulationType.Hardware,
Gravity = new Vector3( 0.0f, -9.81f, 0.0f ),
GroundPlaneEnabled = true
};
PhysXScene = PhysXCore.CreateScene(sceneDesc);
CCDSkeleton ccdSkeletonForBox;
// Create a CCD Skeleton
{
Vector3 size = new Vector3(5, 5, 5);
int[] indices =
{
0, 1, 3,
0, 3, 2,
3, 7, 6,
3, 6, 2,
1, 5, 7,
1, 7, 3,
4, 6, 7,
4, 7, 5,
1, 0, 4,
5, 1, 4,
4, 0, 2,
4, 2, 6
};
Vector3[] vertices =
{
new Vector3( size.X, -size.Y, -size.Z ),
new Vector3( size.X, -size.Y, size.Z ),
new Vector3( size.X, size.Y, -size.Z ),
new Vector3( size.X, size.Y, size.Z ),
new Vector3( -size.X, -size.Y, -size.Z ),
new Vector3( -size.X, -size.Y, size.Z ),
new Vector3( -size.X, size.Y, -size.Z ),
new Vector3( -size.X, size.Y, size.Z )
};
TriangleMeshDescription triangleMeshDesc = new TriangleMeshDescription();
triangleMeshDesc.AllocateVertices(vertices.Length);
triangleMeshDesc.AllocateTriangles(indices.Length);
triangleMeshDesc.VerticesStream.SetData(vertices);
triangleMeshDesc.TriangleStream.SetData(indices);
triangleMeshDesc.VertexCount = vertices.Length;
triangleMeshDesc.TriangleCount = indices.Length / 3;
ccdSkeletonForBox = PhysXCore.CreateCCDSkeleton(triangleMeshDesc);
// Enable CCD and CCD Visualization
PhysXCore.SetParameter(PhysicsParameter.ContinuousCollisionDetection, true);
PhysXCore.SetParameter(PhysicsParameter.VisualizeContinuousCollisionDetectionTests, true);
}
int CurrentID = 0;
foreach (Entity ent in entities)
{
TriangleMeshShapeDescription ShapeDesc = new TriangleMeshShapeDescription()
{
TriangleMesh = MeshToMeshShape(ent.vertices,ent.indices),
Flags = ShapeFlag.Visualization
};
ActorDescription actorDesc = new ActorDescription()
{
Name = ent.Name,
//BodyDescription = new BodyDescription(ent.Mass),//problem here
////////////////////////////////// /////////////////////////////////
////////////////////////////////////////////
//////////////////////////////////////////
///////////////////////////////////////////
//////////////////////////////////////////
//////////////////////////////////////////////
//////////////////////////////////////////////
GlobalPose = Matrix.CreateTranslation(ent.Position),
Shapes = { ShapeDesc }
};
ent.actor = null;
ent.actor = PhysXScene.CreateActor(
actorDesc
);
ent.ActorID = CurrentID;
CurrentID++;
}
}
private int[] shortArTointAr(short[] ar)
{
int[] ar2 = new int[ar.Length];
int i = 0;
foreach (short m in ar)
{
ar2[i] = (int)m;
i++;
}
return ar2;
}
private TriangleMesh MeshToMeshShape(Vector3[] verts, short[] inds)
{
TriangleMeshDescription triangleMeshDesc = new TriangleMeshDescription();
triangleMeshDesc.TriangleCount = shortArTointAr(inds).Length / 3;
triangleMeshDesc.VertexCount = verts.Length;
triangleMeshDesc.AllocateTriangles(triangleMeshDesc.TriangleCount);
triangleMeshDesc.AllocateVertices(triangleMeshDesc.VertexCount);
triangleMeshDesc.TriangleStream.SetData(shortArTointAr(inds));
triangleMeshDesc.VerticesStream.SetData(verts);
MemoryStream s = new MemoryStream();
Cooking.InitializeCooking();
Cooking.CookTriangleMesh(triangleMeshDesc, s);
Cooking.CloseCooking();
s.Position = 0;
TriangleMesh triangleMesh = PhysXCore.CreateTriangleMesh(s);
s.Close();
return triangleMesh;
}
class entity
{
model
triangles
and name and other ....mass...
}