本文整理汇总了C#中DynamicVertexBuffer.SetData方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicVertexBuffer.SetData方法的具体用法?C# DynamicVertexBuffer.SetData怎么用?C# DynamicVertexBuffer.SetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicVertexBuffer
的用法示例。
在下文中一共展示了DynamicVertexBuffer.SetData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalcVertexBuffer
public void CalcVertexBuffer()
{
if (instanceVertexBuffer != null)
instanceVertexBuffer.Dispose();
instanceVertexBuffer = new DynamicVertexBuffer(BaseClass.Device, instanceVertexDeclaration, instanceTransformMatrices.Count, BufferUsage.WriteOnly);
instanceVertexBuffer.SetData(instanceTransformMatrices.Values.ToArray(), 0, instanceTransformMatrices.Count, SetDataOptions.Discard);
}
示例2: StoreOnGPU
public void StoreOnGPU(GraphicsDevice device)
{
GPUMode = true;
GPUBlendVertexBuffer = new DynamicVertexBuffer(device, MeshVertex.SizeInBytes * BlendVertexBuffer.Length, BufferUsage.None);
GPUBlendVertexBuffer.SetData(BlendVertexBuffer);
GPUIndexBuffer = new IndexBuffer(device, sizeof(short) * IndexBuffer.Length, BufferUsage.None, IndexElementSize.SixteenBits);
GPUIndexBuffer.SetData(IndexBuffer);
}
示例3: Initialize
protected override void Initialize()
{
//Создаем буффер индексов и вершин
graphics.GraphicsDevice.Flush();
vertexBuffer = new DynamicVertexBuffer(graphics.GraphicsDevice, typeof(VertexPositionNormalTexture), vertex.Length, BufferUsage.WriteOnly);
indexBuffer = new IndexBuffer(graphics.GraphicsDevice, typeof(int), indices.Length, BufferUsage.WriteOnly);
//Создаем вершины для наших частиц.
CreateVertex();
//Переносим данные в буффер для видеокарты.
indexBuffer.SetData(indices);
vertexBuffer.SetData(vertex);
//Вызываем иниталайз для базового класса и всех компоненетов, если они у нас есть.
base.Initialize();
}
示例4: MMDCPUModelPartP
/// <summary>
/// コンストラクタ
/// </summary>
/// <param name="triangleCount">三角形の個数</param>
/// <param name="vertices">頂点配列</param>
/// <param name="indexBuffer">インデックスバッファ</param>
public MMDCPUModelPartP(int triangleCount, MMDVertex[] vertices,int[] vertMap, IndexBuffer indexBuffer)
: base(triangleCount, vertices.Length, vertMap, indexBuffer)
{
this.vertices = vertices;
//GPUリソース作成
gpuVertices = new VertexPosition[vertices.Length];
vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPosition), vertices.Length, BufferUsage.WriteOnly);
//初期値代入
for (int i = 0; i < vertices.Length; i++)
{
gpuVertices[i].Position = vertices[i].Position;
}
// put the vertices into our vertex buffer
vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
}
示例5: BuildMesh
/// <summary>
/// Build the mesh used to draw the particles
/// </summary>
private void BuildMesh()
{
if (this.mesh != null)
{
this.DestroyMesh();
}
this.maxProjectiles = this.manager.Capacity;
int nVertices = VerticesPerProjectile * this.maxProjectiles;
int nIndices = IndicesPerProjectile * this.maxProjectiles;
// Indices
ushort[] indices = new ushort[nIndices];
for (int i = 0; i < this.maxProjectiles; i++)
{
indices[(i * IndicesPerProjectile) + 0] = (ushort)(i * 4);
indices[(i * IndicesPerProjectile) + 1] = (ushort)((i * 4) + 1);
indices[(i * IndicesPerProjectile) + 2] = (ushort)((i * 4) + 2);
indices[(i * IndicesPerProjectile) + 3] = (ushort)((i * 4) + 2);
indices[(i * IndicesPerProjectile) + 4] = (ushort)((i * 4) + 3);
indices[(i * IndicesPerProjectile) + 5] = (ushort)(i * 4);
}
IndexBuffer indexBuffer = new IndexBuffer(indices);
this.RenderManager.GraphicsDevice.BindIndexBuffer(indexBuffer);
// Vertices
this.vertices = new VertexPositionColorTexture[nVertices];
for (int i = 0; i < this.maxProjectiles; i++)
{
vertices[(i * VerticesPerProjectile) + 0].TexCoord = Vector2.Zero;
vertices[(i * VerticesPerProjectile) + 0].Color = Color.White;
vertices[(i * VerticesPerProjectile) + 1].TexCoord = Vector2.UnitX;
vertices[(i * VerticesPerProjectile) + 1].Color = Color.White;
vertices[(i * VerticesPerProjectile) + 2].TexCoord = Vector2.One;
vertices[(i * VerticesPerProjectile) + 2].Color = Color.White;
vertices[(i * VerticesPerProjectile) + 3].TexCoord = Vector2.UnitY;
vertices[(i * VerticesPerProjectile) + 3].Color = Color.White;
}
DynamicVertexBuffer vertexBuffer = new DynamicVertexBuffer(VertexPositionColorTexture.VertexFormat);
vertexBuffer.SetData(this.vertices);
this.GraphicsDevice.BindVertexBuffer(vertexBuffer);
this.mesh = new Mesh(0, nVertices, 0, nIndices / 3, vertexBuffer, indexBuffer, PrimitiveType.TriangleList)
{
DisableBatch = true
};
}
示例6: Hook
public void Hook(RTSRenderer renderer, GameState s, int ti, int unit)
{
// Filter For Unit Types
RTSTeam team = s.teams[ti];
Data = team.Race.Units[unit];
// Always Add A Unit To List When Spawned
team.OnUnitSpawn += OnUnitSpawn;
// Create Instance Buffer
visible = new List<RTSUnit>();
instVerts = new VertexRTSAnimInst[Data.MaxCount];
instances = new List<RTSUnit>(Data.MaxCount);
dead = new List<RTSUnit>();
for(int i = 0; i < team.Units.Count; i++) {
OnUnitSpawn(team.Units[i]);
}
for(int i = 0; i < instVerts.Length; i++)
instVerts[i] = new VertexRTSAnimInst(Matrix.Identity, 0);
dvbInstances = renderer.CreateDynamicVertexBuffer(VertexRTSAnimInst.Declaration, instVerts.Length, BufferUsage.WriteOnly);
dvbInstances.SetData(instVerts);
dvbInstances.ContentLost += (sender, args) => { rebuildDVB = true; };
rebuildDVB = false;
}
示例7: Vector3
/*public void Transform(Bone bone)
{
var binding = BoneBindings.FirstOrDefault(x => x.BoneName.Equals(bone.Name, StringComparison.InvariantCultureIgnoreCase));
if (binding != null)
{
for (var i = 0; i < binding.RealVertexCount; i++)
{
var vertexIndex = binding.FirstRealVertex + i;
var blendVertexIndex = vertexIndex;//binding.FirstBlendVertex + i;
var realVertex = RealVertexBuffer[vertexIndex];
//var matrix = Matrix.CreateTranslation(realVertex.Position) * bone.AbsoluteMatrix;
//Position
var newPosition = Vector3.Transform(realVertex.Position, bone.AbsoluteMatrix);
BlendVertexBuffer[blendVertexIndex].Position = newPosition;
//Normals
var matrix = Matrix.CreateTranslation(
new Vector3(realVertex.Normal.X,
realVertex.Normal.Y,
realVertex.Normal.Z)) * bone.AbsoluteMatrix;
}
for (var i = 0; i < binding.BlendVertexCount; i++)
{
var blendVertexIndex = binding.FirstBlendVertex + i;
var realVertex = UntransformedBlendVerts[blendVertexIndex];
//Position
var newPosition = Vector3.Transform(realVertex, bone.AbsoluteMatrix);
TransformedBlendVerts[blendVertexIndex] = newPosition;
//todo, alter normals too. would it be correct to linear interpolate that too? it seems like doing that might be kinda stupid
}
}
foreach (var child in bone.Children)
{
Transform(child);
}
if (bone.Name.Equals("ROOT", StringComparison.InvariantCultureIgnoreCase))
{
for (int i = 0; i < BlendData.Length; i++)
{
var data = BlendData[i];
var vert = TransformedBlendVerts[i];
BlendVertexBuffer[data.OtherVertex].Position = Vector3.Lerp(BlendVertexBuffer[data.OtherVertex].Position, vert, data.Weight);
}
InvalidateMesh();
}
}*/
public void StoreOnGPU(GraphicsDevice device)
{
GPUMode = true;
GPUVertexBuffer = new DynamicVertexBuffer(device, typeof(VitaboyVertex), VertexBuffer.Length, BufferUsage.None);
GPUVertexBuffer.SetData(VertexBuffer);
GPUIndexBuffer = new IndexBuffer(device, IndexElementSize.SixteenBits, IndexBuffer.Length, BufferUsage.None);
GPUIndexBuffer.SetData(IndexBuffer);
}
示例8: InitializeBuffers
private void InitializeBuffers()
{
Vertex[] vertices = new Vertex[Size * Size];
for (int i = 0; i < Size; i++)
for (int j = 0; j < Size; j++)
vertices[i + j * Size].Position = new Vector3(i, 0.0f, -j);
int[] indices = new int[(Size - 1) * (Size - 1) * 6];
int count = 0;
for (int i = 0; i < Size - 1; i++)
for (int j = 0; j < Size - 1; j++)
{
indices[count++] = GetIndex(i, j);
indices[count++] = GetIndex(i, j + 1);
indices[count++] = GetIndex(i + 1, j);
indices[count++] = GetIndex(i, j + 1);
indices[count++] = GetIndex(i + 1, j + 1);
indices[count++] = GetIndex(i + 1, j);
}
int maxIndices = (Size - 1) * (Size - 1) * 6;
VertexBuffer = new DynamicVertexBuffer(GraphicsDevice, typeof(Vertex), vertices.Length, BufferUsage.None);
IndexBuffer = new DynamicIndexBuffer(GraphicsDevice, typeof(int), maxIndices, BufferUsage.None);
BasicIndexBuffer = new IndexBuffer(GraphicsDevice, typeof(int), maxIndices, BufferUsage.None);
VertexBuffer.SetData<Vertex>(vertices);
BasicIndexBuffer.SetData<int>(indices);
}
示例9: BuildMesh
/// <summary>
/// Build the mesh used to draw all trails
/// </summary>
private void BuildMesh()
{
if (this.mesh != null)
{
this.DestroyMesh();
}
// Indices
this.indices = new ushort[this.nIndices];
DynamicIndexBuffer indexBuffer = new DynamicIndexBuffer(this.indices);
this.RenderManager.GraphicsDevice.BindIndexBuffer(indexBuffer);
// Vertices
this.vertices = new VertexPositionColorTexture[this.nVertices];
DynamicVertexBuffer vertexBuffer = new DynamicVertexBuffer(VertexPositionColorTexture.VertexFormat);
vertexBuffer.SetData(this.vertices);
this.GraphicsDevice.BindVertexBuffer(vertexBuffer);
this.mesh = new Mesh(0, nVertices, 0, nIndices / 3, vertexBuffer, indexBuffer, PrimitiveType.TriangleStrip)
{
DisableBatch = true
};
}
示例10: InitVertexBuffer
//.........这里部分代码省略.........
int index = 0;
for (int rib = 0; rib < NUM_RIBS; ++rib)
{
double ribAngle = rib * radiansBetweenRibs;
float cos = (float)Math.Cos(ribAngle);
float sin = (float)Math.Sin(ribAngle);
for (int led = 0; led < LEDS_PER_RIB; ++led, index += 4)
{
float rowRadius = (float)Math.Cos(led * radiansBetweenRows) * radiusDome + 1.0f;
float rowHeight = (float)Math.Sin(led * radiansBetweenRows) * heightDome;
Vector3 pos = new Vector3(cos * rowRadius, sin * rowRadius, rowHeight);
m_Lights[index + 0].Color = Color.White;
m_Lights[index + 1].Color = Color.White;
m_Lights[index + 2].Color = Color.White;
m_Lights[index + 3].Color = Color.White;
m_Lights[index + 0].Position = pos;
m_Lights[index + 1].Position = pos;
m_Lights[index + 2].Position = pos;
m_Lights[index + 3].Position = pos;
}
}
// Init our pendant indicators
// H
float radiusPendants = 280.0f;
float heightPendants = 16.0f;
// Angle over which we want to render the pendants:
float arcPendants = (float)Math.PI / 2;
float radiansBetweenPendants = (float)(arcPendants / NUM_PENDANTS_MAX);
// float radiansBetweenPendantLEDs = (float)((Math.PI / 2) / LEDS_PER_PENDANT_MAX);
// The radius between pendant LEDs is spacing between LEDs in a pendant:
float radiusBetweenPendantLEDs = 8.0f; // 32.0f / LEDS_PER_PENDANT_MAX;
m_PendantLightIndexOffset = index / 4;
for (int pendant = 0; pendant < NUM_PENDANTS_MAX; ++pendant)
{
// 3D-position: X and Y are on the ground, Z is up towards top of dome
double angle = ((pendant + 0.5) * radiansBetweenPendants) + (Math.PI / 4);
float cos = (float)Math.Cos(angle);
float sin = (float)Math.Sin(angle);
for (int led = 0; led < LEDS_PER_PENDANT_MAX; ++led, index += 4)
{
float rowRadius = radiusPendants + led * radiusBetweenPendantLEDs; // (float)Math.Cos(led * radiansBetweenPendantLEDs) * radiusPendants + 1.0f;
float rowHeight = heightPendants; // *(float)Math.Sin(led * radiansBetweenPendantLEDs);
Vector3 pos = new Vector3(cos * rowRadius, sin * rowRadius, rowHeight);
m_Lights[index + 0].Color = Color.White;
m_Lights[index + 1].Color = Color.White;
m_Lights[index + 2].Color = Color.White;
m_Lights[index + 3].Color = Color.White;
m_Lights[index + 0].Position = pos;
m_Lights[index + 1].Position = pos;
m_Lights[index + 2].Position = pos;
m_Lights[index + 3].Position = pos;
}
}
// Init our satellites:
float arcSatellites = 2.0f * (float)Math.PI;
float radiansBetweenSatelliteLEDs = (float)(arcSatellites / LEDS_PER_SATELLITE);
float radiusSatellites = 64.0f;
float xOffsetSatellites = 280.0f;
float yOffsetSatellites = 280.0f;
float zOffsetSatellites = 0.0f;
m_SatelliteLightIndexOffset = index / 4;
for (int satellite = 0; satellite < NUM_SATELLITES; ++satellite)
{
// 3D-position: X and Y are on the ground, Z is up towards top of dome
float xOffset = (satellite == 0) ? xOffsetSatellites : -xOffsetSatellites;
for (int led = 0; led < LEDS_PER_SATELLITE; ++led, index += 4)
{
double angle = (led * radiansBetweenSatelliteLEDs);// +(Math.PI / 4);
float cos = (float)Math.Cos(angle);
float sin = (float)Math.Sin(angle);
Vector3 pos = new Vector3(xOffset + cos * radiusSatellites, yOffsetSatellites + sin * radiusSatellites, zOffsetSatellites);
m_Lights[index + 0].Color = Color.White;
m_Lights[index + 1].Color = Color.White;
m_Lights[index + 2].Color = Color.White;
m_Lights[index + 3].Color = Color.White;
m_Lights[index + 0].Position = pos;
m_Lights[index + 1].Position = pos;
m_Lights[index + 2].Position = pos;
m_Lights[index + 3].Position = pos;
}
}
m_VB.SetData(m_Lights);
}
示例11: InitializeVertice
/// <summary>
/// Initialization new RenderVertices
/// </summary>
/// <param name="g"></param>
private void InitializeVertice(GraphicsDevice g)
{
if(_graphic==null)
_graphic = g;
//RenderVertices.RemoveAll(
// delegate(VertexPositionNormalTexture matcher)
// {
// return true;
// });
//for (int i = 0; i < Vertices.Count; i++)
//{
// VertexPositionNormalTexture tmp = new VertexPositionNormalTexture();
// tmp.Position = Vertices.ToArray()[i].Position;
// tmp.Normal = Vertices.ToArray()[i].Normal;
// RenderVertices.Add(tmp);
//}
//RenderVertices = Vertices;
this._indexBuffer = new IndexBuffer(_graphic, typeof(ushort),_indices.Count, BufferUsage.None);
VertexBuffer = new DynamicVertexBuffer(_indexBuffer.GraphicsDevice,
typeof(VertexPositionNormalTexture), this._vertices.Count, BufferUsage.WriteOnly);
_indexBuffer.SetData(this._indices.ToArray());
VertexBuffer.SetData(Vertices.ToArray(), 0, _vertices.Count, SetDataOptions.Discard);
}
示例12: Renderer
public Renderer()
{
planeCam = new Camera { View = Matrix.CreateLookAt(new Vector3(0, 0, 10), new Vector3(0, 0, 0), Vector3.Up), Projection = Matrix.CreateOrthographic(1f, 1f, 1f, 100.0f)};
Device = Game1.Instance.GraphicsDevice;
instanceVertexBuffer = new DynamicVertexBuffer(
Game1.Instance.GraphicsDevice,
typeof(InstanceData),
1,
BufferUsage.WriteOnly);
instanceVertexBuffer.SetData( new []{new InstanceData { World = Matrix.Identity }}, 0, 1, SetDataOptions.Discard);
}
示例13: InitVertexBuffer
private static void InitVertexBuffer()
{
GraphicsDevice device = Core.GetDevice();
m_VB = new DynamicVertexBuffer(device, JellyVertex.VertexDeclaration, TOTAL_LEDS * 4, BufferUsage.WriteOnly);
// 4 verts per quad / particle
m_Lights = new JellyVertex[TOTAL_LEDS * 4];
// corners never change
for (int i = 0; i < TOTAL_LEDS; i++)
{
m_Lights[i * 4 + 0].Corner = new Short2(-1, -1);
m_Lights[i * 4 + 1].Corner = new Short2(1, -1);
m_Lights[i * 4 + 2].Corner = new Short2(1, 1);
m_Lights[i * 4 + 3].Corner = new Short2(-1, 1);
}
// create the actual dome structure
float cos = 1.0f;
float sin = 1.0f;
float radiansBetweenRibs= (float)(2 * Math.PI / NUM_RIBS);
float radiansBetweenRows = (float)((Math.PI / 2) / LEDS_PER_RIB);
float radius = 250.0f;
float height = 250.0f;
int curLight = 0;
for (int rib = 0; rib < NUM_RIBS; ++rib)
{
double ribAngle = rib * radiansBetweenRibs;
cos = (float)Math.Cos(ribAngle);
sin = (float)Math.Sin(ribAngle);
for (int led = 0; led < LEDS_PER_RIB; ++led)
{
float rowRadius = (float)Math.Cos(led * radiansBetweenRows) * radius + 1.0f;
float rowHeight = (float)Math.Sin(led * radiansBetweenRows) * height;
Vector3 pos = new Vector3(cos * rowRadius, sin * rowRadius, rowHeight);
int index = curLight * 4;
m_Lights[index + 0].Color = Color.Black;
m_Lights[index + 1].Color = Color.Black;
m_Lights[index + 2].Color = Color.Black;
m_Lights[index + 3].Color = Color.Black;
m_Lights[index + 0].Position = pos;
m_Lights[index + 1].Position = pos;
m_Lights[index + 2].Position = pos;
m_Lights[index + 3].Position = pos;
++curLight;
}
}
m_VB.SetData(m_Lights);
}
示例14: MMDCPUModelPartPNmTxVc
/// <summary>
/// コンストラクタ
/// </summary>
/// <param name="triangleCount">三角形の個数</param>
/// <param name="vertices">頂点配列</param>
/// <param name="indexBuffer">インデックスバッファ</param>
public MMDCPUModelPartPNmTxVc(int triangleCount, MMDVertexNmTxVc[] vertices, int[] vertMap, IndexBuffer indexBuffer)
: base(triangleCount, vertices.Length, vertMap, indexBuffer)
{
this.vertices = vertices;
//GPUリソース作成
gpuVertices = new VertexPositionNormalTextureColor[vertices.Length];
vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionNormalTextureColor), vertices.Length, BufferUsage.WriteOnly);
//初期値代入
for (int i = 0; i < vertices.Length; i++)
{
gpuVertices[i].Position = vertices[i].Position;
gpuVertices[i].Normal = vertices[i].Normal;
gpuVertices[i].Color = new Color(vertices[i].VertexColor);
gpuVertices[i].TextureCoordinate = vertices[i].TextureCoordinate;
}
// put the vertices into our vertex buffer
vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
}
示例15: ParticleEmitter
internal ParticleEmitter(int maxNumOfParticles, Effect effect, Texture2D texture1, Texture2D texture2 = null)
: base("particleEmitter", new Actor(new DummyAnimation()))
{
//This makes particles draw on top of all objects
Static = true;
//sets max number of particles
this.maxNumOfParticles = maxNumOfParticles;
//instantiate array of particle vertices & indicies
particleVertices = new ParticleVertexFormat[maxNumOfParticles * 4];
particleIndices = new int[maxNumOfParticles * 6];
//instantiate array of time to lives to all particles
expirationTime = new int[maxNumOfParticles];
numOfActiveParticles = 0;
//Allocate memory on gpu for vertices & indicies
vertexBuffer = new DynamicVertexBuffer(This.Game.GraphicsDevice, ParticleVertexFormat.VertexDeclaration, particleVertices.Length, BufferUsage.WriteOnly);
indexBuffer = new IndexBuffer(This.Game.GraphicsDevice, typeof(int), particleIndices.Length, BufferUsage.WriteOnly);
//create all indices (they never change)
for (int i = 0; i < maxNumOfParticles; i++)
setIndices(i);
//give buffer's their data
vertexBuffer.SetData(particleVertices);
indexBuffer.SetData(particleIndices);
//load Texture
this.texture1 = texture1;
this.texture2 = texture2;
//load the HLSL code
this.effect = effect.Clone();
sendConstantsToGPU();
collisionObjects.Add(new Collision_BoundingCircle(1, Vector2.Zero, 10));
this.CollisionList = 2;
}