本文整理汇总了C#中Mesh.LockAttributeBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.LockAttributeBuffer方法的具体用法?C# Mesh.LockAttributeBuffer怎么用?C# Mesh.LockAttributeBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mesh
的用法示例。
在下文中一共展示了Mesh.LockAttributeBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildGridGeometry
void BuildGridGeometry()
{
Vector3[] globalverts, gridverts;
int[] globalindices, gridindices, gridindices2;
float dx = 10.0f;
float dz = 10.0f;
// Generate global grid
GenTriGrid(inputImageHeight, inputImageWidth, dx, dz, new Vector3(0.0f, -1000f, 0f), out globalverts, out globalindices);
// Number of sub-grids
int nGridsY = GetGoodAverage(inputImageHeight);
int nGridsX = GetGoodAverage(inputImageWidth);
// Subgrid size
int GridW = inputImageWidth / nGridsX;
int GridD = inputImageHeight / nGridsY;
int gridNumVerts = (GridW+1) * (GridD+1);
int gridNumTris = (GridD ) * (GridW ) * 2;
// Generate subgrid indices
GenTriGrid(GridD+1, GridW+1, dx, dz, new Vector3(0.0f, -5000f, 0f), out gridverts, out gridindices);
GenTriGrid(GridD, GridW, dx, dz, new Vector3(0.0f, -5000f, 0f), out gridverts, out gridindices2);
// Define some often used variables
bool overflowX = false, overflowY = false;
float w = (GridW*nGridsX) * dx;
float d = (GridD * nGridsY) * dz;
Vector3 normal = new Vector3(0f, 1f, 0f);
Mesh mesh;
VertexPositionNormalTextured[] vertexData = new VertexPositionNormalTextured[gridNumVerts];
int subgridX, subgridY, globalIndex, gridIndex;
// foreach subgrid
for (int gridX = 0; gridX < nGridsX; gridX++)
{
for (int gridY = 0; gridY < nGridsY; gridY++)
{
overflowY = false;
overflowX = false;
mesh = new Mesh(Renderer.Instance.device, gridNumTris, gridNumVerts, MeshFlags.Use32Bit, VertexPositionNormalTextured.Format);
// Check for overflow
if ((gridX+1) * (GridW + 1) > inputImageWidth)
overflowX = true;
else if ((gridY+1) * (GridD + 1) > inputImageHeight)
overflowY = true;
if (overflowY || overflowX)
{
}
else
{
for (int subD = 0; subD < GridD + 1; ++subD)
{
for (int subW = 0; subW < GridW + 1; ++subW)
{
subgridX = gridX * GridW + subW;
subgridY = gridY * GridD + subD;
globalIndex = (subgridY * inputImageHeight) + subgridX;
gridIndex = (subD * (GridD + 1)) + subW;
vertexData[gridIndex].Position = globalverts[globalIndex];
//vertexData[gridIndex].Y += GetHeightFromImage(subgridY, subgridX) * scale;
vertexData[gridIndex].Position.Y += SampleHeightMap3x3(subgridY, subgridX) * scale;
vertexData[gridIndex].Normal = normal;
vertexData[gridIndex].TextureCoordinate = new Vector2((vertexData[gridIndex].Position.X + (0.5f * w)) / w, (vertexData[gridIndex].Position.Z - (0.5f * d)) / -d);
}
}
DataStream gs = mesh.LockVertexBuffer(LockFlags.None);
gs.WriteRange<VertexPositionNormalTextured>(vertexData);
gs.Seek(0, SeekOrigin.Begin);
// Todo: Fix AABB and frustrum culling
Vector3 min, max;
//Geometry.ComputeBoundingBox(gs, gridNumVerts, VertexPositionNormalTextured.Format, out min, out max);
mesh.UnlockVertexBuffer();
//int[] meshIndices = new int[gridNumTris * 3];
DataStream ds = mesh.LockAttributeBuffer(LockFlags.None);
for (int i = 0; i < gridNumTris; ++i)
{
ds.Write<int>(0);
}
mesh.UnlockAttributeBuffer();
//meshIndices = ;
gs = mesh.LockIndexBuffer(LockFlags.None);
gs.WriteRange<int>(gridindices);
mesh.UnlockIndexBuffer();
//gs = mesh.LockAttributeBuffer(LockFlags.None);
//gs.Write(meshAttr);
mesh.ComputeNormals();
int[] adj = new int[mesh.FaceCount * 3];
mesh.GenerateAdjacency(float.Epsilon);
//mesh.OptimizeInPlace(MeshFlags.OptimizeAttributeSort | MeshFlags.OptimizeVertexCache | MeshFlags.OptimizeCompact, adj);
Mesh newmesh = mesh.Clone(Renderer.Instance.device, MeshFlags.Managed, VertexPosTexNormalTanBitan.Elements);
//.........这里部分代码省略.........
示例2: fillAttributeBuffer
protected virtual void fillAttributeBuffer(Mesh mesh, ref int attribId)
{
List<int> attribList = new List<int>();
int faceStart = 0;
int faceEnd = 0;
foreach (Document.Primitive primitive in Primitives)
{
faceEnd = faceStart + primitive.count;
for (int i = faceStart; i < faceEnd; i++)
attribList.Add(attribId);
attribId++;
faceStart = faceEnd;
}
DataStream ds = mesh.LockAttributeBuffer(LockFlags.None);
ds.WriteRange(attribList.ToArray());
mesh.UnlockAttributeBuffer();
}
示例3: CreateCylinderMesh
//.........这里部分代码省略.........
{
Position = vertexPos,
Texture = i < 6 ? startTextures[i] : default(Vector2),
Normal = i < 6 ? GetFlatNormal(vertexPos) : GetSideNormal(vertexPos, height, rtop, rbottom)
}));
var indices = new List<Int16>
{
0, 1, 2,
3, 4, 5,
6, 7, 8,
8, 9, 6
};
var attributes = new List<Int32> {0, 1, 2, 2};
short prevtop = 2;
short prevbot = 4;
short prevtopside = 9;
short prevbotside = 8;
for(short i = 1; i < thetaDiv - 1; i++)
{
var vertcount = (short)(10 + 4 * i);
// Top surface:
Vector3 topPoint = topPoints[i + 1];
vertices.Add(new CustomVertex
{
Position = topPoint,
Texture = GetFlatTextureCoordinates(topPoint, rtop),
Normal = GetFlatNormal(topPoint)
});
indices.Add(0);
indices.Add(prevtop);
indices.Add(vertcount);
attributes.Add(0);
// Bottom surface:
Vector3 bottomPoint = bottomPoints[i + 1];
vertices.Add(new CustomVertex
{
Position = bottomPoint,
Texture = GetFlatTextureCoordinates(bottomPoint, rbottom),
Normal = GetFlatNormal(bottomPoint)
});
indices.Add(3); //center
indices.Add((short)(vertcount + 1)); //latest
indices.Add(prevbot); //previous
attributes.Add(1);
// Side surface:
vertices.Add(new CustomVertex
{
Position = bottomPoint,
Normal = GetSideNormal(bottomPoint, height, rtop, rbottom)
});
vertices.Add(new CustomVertex
{
Position = topPoint,
Normal = GetSideNormal(bottomPoint, height, rtop, rbottom)
});
indices.Add(prevtopside);
indices.Add(prevbotside);
indices.Add((short)(vertcount + 2));
indices.Add((short)(vertcount + 2));
indices.Add((short)(vertcount + 3));
indices.Add(prevtopside);
attributes.Add(2);
attributes.Add(2);
prevtop = vertcount;
prevbot = (short)(vertcount + 1);
prevbotside = (short)(vertcount + 2);
prevtopside = (short)(vertcount + 3);
}
//top
indices.Add(0);
indices.Add(thetaDiv - 1);
indices.Add(1);
attributes.Add(0);
indices.Add(3); //center
indices.Add(5); //latest
indices.Add(thetaDiv - 1);
attributes.Add(1);
indices.Add(prevtopside);
indices.Add(prevbotside);
indices.Add(7);
indices.Add(7);
indices.Add(6);
indices.Add(prevtop);
attributes.Add(2);
attributes.Add(2);
var mesh = new Mesh(device, indices.Count / 3, vertices.Count, MeshFlags.Managed, CustomVertex.TheVertexFormat);
const LockFlags lockFlags = LockFlags.None;
using(DataStream vertexStream = mesh.LockVertexBuffer(lockFlags),
indexStream = mesh.LockIndexBuffer(lockFlags),
attributeStream = mesh.LockAttributeBuffer(lockFlags))
{
vertices.ForEach(vertexStream.Write);
indices.ForEach(indexStream.Write);
attributes.ForEach(attributeStream.Write);
}
mesh.UnlockVertexBuffer();
mesh.UnlockIndexBuffer();
mesh.UnlockAttributeBuffer();
return mesh;
}