本文整理汇总了C#中Scene.CreateCloth方法的典型用法代码示例。如果您正苦于以下问题:C# Scene.CreateCloth方法的具体用法?C# Scene.CreateCloth怎么用?C# Scene.CreateCloth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scene
的用法示例。
在下文中一共展示了Scene.CreateCloth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadPhysics
protected override void LoadPhysics(Scene scene)
{
int w = 25;
int h = 25;
float hw = w / 2.0f;
float hh = h / 2.0f;
Vector3 p = new Vector3(0, 20, 0);
// Create a Grid of Points
int vertices, indices;
ClothMesh clothMesh;
{
var grid = VertexGrid.CreateGrid(w, h);
vertices = grid.Points.Length;
indices = grid.Indices.Length;
ClothMeshDescription clothMeshDesc = new ClothMeshDescription();
clothMeshDesc.AllocateVertices<Vector3>(vertices);
clothMeshDesc.AllocateTriangles<int>(indices / 3);
clothMeshDesc.VertexCount = vertices;
clothMeshDesc.TriangleCount = indices / 3;
clothMeshDesc.VerticesStream.SetData(grid.Points);
clothMeshDesc.TriangleStream.SetData(grid.Indices);
// We are using 32 bit integers for our indices, so make sure the 16 bit flag is removed.
// 32 bits are the default, so this isn't technically needed, but it's good to show in a sample
clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;
clothMeshDesc.Flags |= (MeshFlag)((int)clothMeshDesc.Flags | (int)ClothMeshFlag.Tearable);
// Write the cooked data to memory
using (var memoryStream = new MemoryStream())
{
Cooking.InitializeCooking();
Cooking.CookClothMesh(clothMeshDesc, memoryStream);
Cooking.CloseCooking();
// Need to reset the position of the stream to the beginning
memoryStream.Position = 0;
clothMesh = Engine.Core.CreateClothMesh(memoryStream);
}
}
//
int j = vertices * 2;
int k = indices * 3;
var clothDesc = new ClothDescription()
{
ClothMesh = clothMesh,
GlobalPose =
Matrix.Translation(-hw, 0, -hh) *
Matrix.Translation(p),
Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization | ClothFlag.Tearable,
BendingStiffness = 0.1f,
TearFactor = 1.5f
};
clothDesc.MeshData.AllocatePositions<Vector3>(j);
clothDesc.MeshData.AllocateIndices<int>(k);
clothDesc.MeshData.AllocateNormals<Vector3>(j);
clothDesc.MeshData.MaximumVertices = j;
clothDesc.MeshData.MaximumIndices = k;
clothDesc.MeshData.NumberOfVertices = vertices;
clothDesc.MeshData.NumberOfIndices = indices;
_cloth = scene.CreateCloth(clothDesc);
//
// Four corner boxes to hold it in place
var positions = new[]
{
new Vector3(0, 0, -hh), // Back
new Vector3(0, 0, hh), // Front
new Vector3(-hw, 0, 0), // Left
new Vector3(hw, 0, 0), // Right
};
var sizes = new[]
{
new Vector3(w, 1, 1), // Back
new Vector3(w, 1, 1), // Front
new Vector3(1, 1, h), // Left
new Vector3(1, 1, h), //Right
};
for (int i = 0; i < 4; i++)
{
var actorDesc = new ActorDescription()
{
GlobalPose = Matrix.Translation(positions[i] + p),
//.........这里部分代码省略.........
示例2: FlagOfCloth
public static PhysX.Cloth FlagOfCloth(Scene scene)
{
Core core = scene.Core;
// Create a Grid of Points
VertexGrid grid = VertexGrid.CreateGrid(10, 10);
ClothMeshDescription clothMeshDesc = new ClothMeshDescription();
clothMeshDesc.AllocateVertices<Vector3>(grid.Points.Length);
clothMeshDesc.AllocateTriangles<int>(grid.Indices.Length / 3);
clothMeshDesc.VertexCount = grid.Points.Length;
clothMeshDesc.TriangleCount = grid.Indices.Length / 3;
clothMeshDesc.VerticesStream.SetData(grid.Points);
clothMeshDesc.TriangleStream.SetData(grid.Indices);
// We are using 32 bit integers, so make sure the 16 bit flag is removed.
// 32 bits are the default, so this isn't technically needed
clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;
// Write the cooked data to memory
MemoryStream memoryStream = new MemoryStream();
Cooking.InitializeCooking();
Cooking.CookClothMesh(clothMeshDesc, memoryStream);
Cooking.CloseCooking();
// Need to reset the position of the stream to the beginning
memoryStream.Position = 0;
ClothMesh clothMesh = core.CreateClothMesh(memoryStream);
//
ClothDescription clothDesc = new ClothDescription()
{
ClothMesh = clothMesh,
Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
GlobalPose =
Matrix.RotationYawPitchRoll(0, (float)Math.PI / 2.0f, (float)Math.PI / 2.0f) *
Matrix.Translation(0, 20, 0)
};
clothDesc.MeshData.AllocatePositions<Vector3>(grid.Points.Length);
clothDesc.MeshData.AllocateIndices<int>(grid.Indices.Length);
clothDesc.MeshData.MaximumVertices = grid.Points.Length;
clothDesc.MeshData.MaximumIndices = grid.Indices.Length;
clothDesc.MeshData.NumberOfVertices = grid.Points.Length;
clothDesc.MeshData.NumberOfIndices = grid.Indices.Length;
var flag = scene.CreateCloth(clothDesc);
// Flag Pole
ActorDescription flagPoleActorDesc = new ActorDescription()
{
GlobalPose = Matrix.Translation(0, 10, 0),
Shapes = { new BoxShapeDescription(1.0f, 20.0f, 1.0f) }
};
Actor flagPoleActor = scene.CreateActor(flagPoleActorDesc);
flag.AttachToShape(flagPoleActor.Shapes[0], 0);
flag.WindAcceleration = new Vector3(10, 10, 10);
flag.BendingStiffness = 0.1f;
return flag;
}
示例3: LoadPhysics
protected override void LoadPhysics(Scene scene)
{
int w = 26;
int h = 26;
float hw = w / 2.0f;
float hh = h / 2.0f;
Vector3 p = new Vector3(0, h + 1, 0);
// Create a Grid of Points
int vertices, indices;
ClothMesh clothMesh;
{
var grid = VertexGrid.CreateGrid(w, h);
vertices = grid.Points.Length;
indices = grid.Indices.Length;
ClothMeshDescription clothMeshDesc = new ClothMeshDescription();
clothMeshDesc.AllocateVertices<Vector3>(vertices);
clothMeshDesc.AllocateTriangles<int>(indices / 3);
clothMeshDesc.VertexCount = vertices;
clothMeshDesc.TriangleCount = indices / 3;
clothMeshDesc.VerticesStream.SetData(grid.Points);
clothMeshDesc.TriangleStream.SetData(grid.Indices);
// We are using 32 bit integers for our indices, so make sure the 16 bit flag is removed.
// 32 bits are the default, so this isn't technically needed, but it's good to show in a sample
clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;
clothMeshDesc.Flags |= (MeshFlag)((int)clothMeshDesc.Flags | (int)ClothMeshFlag.Tearable);
//var elements = new[]
//{
//new SlimDX.Direct3D10.InputElement("Position", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 0, 0),
//new SlimDX.Direct3D10.InputElement("Color", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 16, 0)
//};
//mesh = new SlimDX.Direct3D10.Mesh(Engine.GraphicsDevice, elements, "Position", vertices, indices / 3, SlimDX.Direct3D10.MeshFlags.Has32BitIndices);
// Write the cooked data to memory
using (var memoryStream = new MemoryStream())
{
Cooking.InitializeCooking();
Cooking.CookClothMesh(clothMeshDesc, memoryStream);
Cooking.CloseCooking();
// Need to reset the position of the stream to the beginning
memoryStream.Position = 0;
clothMesh = Engine.Core.CreateClothMesh(memoryStream);
}
}
//
int j = vertices * 2;
int k = indices * 3;
var clothDesc = new ClothDescription()
{
ClothMesh = clothMesh,
GlobalPose =
Matrix.RotationX((float)Math.PI / 2.0F) *
Matrix.Translation(-w - 1, 0, 0) *
Matrix.Translation(p),
Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
BendingStiffness = 0.1f,
TearFactor = 1.5f,
WindAcceleration = new Vector3(windX, windY, windZ)
};
clothDesc.MeshData.AllocatePositions<Vector3>(j);
clothDesc.MeshData.AllocateIndices<int>(k);
clothDesc.MeshData.AllocateNormals<Vector3>(j);
clothDesc.MeshData.MaximumVertices = j;
clothDesc.MeshData.MaximumIndices = k;
clothDesc.MeshData.NumberOfVertices = vertices;
clothDesc.MeshData.NumberOfIndices = indices;
_clothL = scene.CreateCloth(clothDesc);
var clothDesc2 = new ClothDescription()
{
ClothMesh = clothMesh,
GlobalPose =
Matrix.RotationX((float)Math.PI / 2.0F) *
Matrix.Translation(1, 0, 0) *
Matrix.Translation(p),
Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
BendingStiffness = 0.1f,
TearFactor = 1.5f,
WindAcceleration = new Vector3(windX, windY, windZ)
};
clothDesc2.MeshData.AllocatePositions<Vector3>(j);
clothDesc2.MeshData.AllocateIndices<int>(k);
clothDesc2.MeshData.AllocateNormals<Vector3>(j);
//.........这里部分代码省略.........