Re: SetIndexBufferData
From: Jason (Jason_at_mobiform.com)
Date: 08/10/04
- Previous message: JuanK: "RE: Sound effects"
- In reply to: Michel Walsh: "Re: SetIndexBufferData"
- Next in thread: Michel Walsh: "Re: SetIndexBufferData"
- Reply: Michel Walsh: "Re: SetIndexBufferData"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 10 Aug 2004 16:02:35 -0700
I did manage to fix it earilier this morning. I think it was a combination
of having to use short, which I had started out with before switching to the
int. As well as using Lock/UnlockIndexBuffer and not SetIndexBufferData
which just never seemed to work.
new stuff looks a little like this..
int slices = (int)_slices.animVal;
int stacks = (int)_stacks.animVal;
int numFaces = ( slices * 2) + ( (stacks+1) * slices * 2);
int numVertices = (( stacks + 4 ) * (slices+1) ) + 2;
Microsoft.DirectX.Direct3D.Mesh mesh = new
Microsoft.DirectX.Direct3D.Mesh( numFaces, numVertices, MeshFlags.Managed,
CustomVertex.PositionNormalTextured.Format, device );
CustomVertex.PositionNormalTextured[] verts;
verts =
(CustomVertex.PositionNormalTextured[])mesh.LockVertexBuffer(typeof(CustomVe
rtex.PositionNormalTextured), LockFlags.None, numVertices);
short []indices;
indices = ( short[] ) mesh.LockIndexBuffer( typeof(short),LockFlags.None,
numFaces*3 );
int currentIndice = 0;
//...
mesh.UnlockVertexBuffer();
mesh.UnlockIndexBuffer();
"Michel Walsh" <vanderghast@VirusAreFunnierThanSpam> wrote in message
news:On6p01vfEHA.592@TK2MSFTNGP11.phx.gbl...
> Hi,
>
>
> Is your graphic card support int4 indexes? Have you tried with an array
of
> short rather than an array of integer? Have you tried to save the mesh in
a
> file (after having Clean it), and edit it into the mesh viewer tool? Have
> your tried with PositionNormal (not textured) CustomVertex?
>
> If int[] to short[] solves your problem, please, report it, so I will
> abandon my own investigation (I try to do the same, but following the
> example in the help file, but with just partial success, right now, ie,
for
> less than around 600 values in the index buffer).
>
>
> Vanderghast, Access MVP
>
>
>
> "Jason" <Jason@mobiform.com> wrote in message
> news:%23NF0CUnfEHA.592@TK2MSFTNGP11.phx.gbl...
> > I cant seem to get my cylinder generation code to work. I suspect it's
the
> > SetIndexBufferDataCall since the create (bool?) remains undefined and
the
> > buffersize remains 0. I must be missing something stupid simple. Perhaps
> > someone can point it out.
> >
> > Jason
> >
> > //The C# following code will try to make a cylinder, tho its totally
> > unconfirmed since I have yet to see its output
> >
> >
> > int slices = (int)_slices.animVal;
> > int stacks = (int)_stacks.animVal;
> > int numFaces = ( slices * 2) + ( (stacks+1) * slices * 2);
> > int numVertices = (( stacks + 2 ) * slices ) + 2;
> >
> >
> > Microsoft.DirectX.Direct3D.Mesh mesh = new
> > Microsoft.DirectX.Direct3D.Mesh( numFaces, numVertices,
MeshFlags.Managed,
> > CustomVertex.PositionNormalTextured.Format, device );
> >
> >
> >
> > float r1 = _r1.animVal.value;
> > float r2 = _r2.animVal.value;
> > float length = _length.animVal.value;
> >
> > CustomVertex.PositionNormalTextured[] verts;
> >
> > verts =
> (CustomVertex.PositionNormalTextured[])mesh.VertexBuffer.Lock(0,
> > typeof(CustomVertex.PositionNormalTextured), 0, numVertices);
> >
> > int []indices = new int[numFaces*3];
> > int currentIndice = 0;
> >
> > float currentY = length/2.0f;
> > float angleInc = SVGViewPlus.SVGDOM.SVG3D.Math.Constants.TWO_PI /
> slices;
> > float heightInc = length / (stacks+1);
> >
> > //middle center top
> > verts[numVertices-2].X = 0.0f;
> > verts[numVertices-2].Y = currentY;
> > verts[numVertices-2].Z = 0.0f;
> > verts[numVertices-2].Nx = 0.0f;
> > verts[numVertices-2].Ny = 1.0f;
> > verts[numVertices-2].Nz = 0.0f;
> > verts[numVertices-2].Tu = 0.0f;
> > verts[numVertices-2].Tv = 0.0f;
> >
> > //middle center bottom
> > verts[numVertices-1].X = 0.0f;
> > verts[numVertices-1].Y = -currentY;
> > verts[numVertices-1].Z = 0.0f;
> > verts[numVertices-1].Nx = 0.0f;
> > verts[numVertices-1].Ny = -1.0f;
> > verts[numVertices-1].Nz = 0.0f;
> > verts[numVertices-1].Tu = 1.0f;
> > verts[numVertices-1].Tv = 1.0f;
> >
> >
> > Matrix33 tempMatrix = new Matrix33();
> > SVGViewPlus.SVGDOM.SVG3D.Math.Vector3 vectorPoint = new
> > SVGViewPlus.SVGDOM.SVG3D.Math.Vector3();
> >
> > for ( int i = 0; i < (stacks + 2); i++ )
> > {
> > float angle = 0.0f;
> > float V = i / (stacks + 1);
> > float radius = SVGViewPlus.SVGDOM.SVG3D.Math.Functions.Lerp( r1, 0,
> r2,
> > 1, V );
> >
> >
> > for ( int j = 0; j < slices; j++ )
> > {
> > angle += angleInc;
> >
> > //build vertices
> > tempMatrix.BuildIdentity();
> > tempMatrix.BuildRotationY( angle );
> >
> > vectorPoint.X = 0.0f;
> > vectorPoint.Y = currentY;
> > vectorPoint.Z = radius;
> >
> > vectorPoint =
SVGViewPlus.SVGDOM.SVG3D.Math.Vector3.TransformNormal(
> > vectorPoint, tempMatrix );
> >
> > int index = (i*slices)+j;
> >
> > verts[index].X = vectorPoint.X;
> > verts[index].Y = vectorPoint.Y;
> > verts[index].Z = vectorPoint.Z;
> >
> > vectorPoint.Y = 0.0f;
> > vectorPoint.Normalize();
> >
> > verts[index].Nx = vectorPoint.X;
> > verts[index].Ny = vectorPoint.Y;
> > verts[index].Nz = vectorPoint.Z;
> >
> > verts[index].Tu = angle /
> > SVGViewPlus.SVGDOM.SVG3D.Math.Constants.TWO_PI;
> > verts[index].Tv = V;
> > //Build indicies
> >
> > if ( i == 0 )
> > {//top cap
> > indices[currentIndice++] = numVertices-2;
> > indices[currentIndice++] = index;
> > if ( (j+1) >= slices )
> > {
> > indices[currentIndice++] = i*slices;
> > }
> > else
> > {
> > indices[currentIndice++] = index+1;
> > }
> > }
> > else if ( i == (stacks + 1) )
> > {//bottom cap
> > indices[currentIndice++] = numVertices-1;
> > indices[currentIndice++] = index;
> > if ( (j+1) >= slices )
> > {
> > indices[currentIndice++] = i*slices;
> > }
> > else
> > {
> > indices[currentIndice++] = index+1;
> > }
> > }
> > else
> > {
> > //1 tri
> > indices[currentIndice++] = index;
> > if ( (j+1) >= slices )
> > {
> > indices[currentIndice++] = (i-1)*slices;
> > }
> > else
> > {
> > indices[currentIndice++] = ((i-1)*slices)+j+1;
> > }
> > indices[currentIndice++] = ((i-1)*slices)+j;
> >
> > //2 tri
> > indices[currentIndice++] = index;
> > indices[currentIndice++] = ((i-1)*slices)+j;
> > if ( (j-1) < 0 )
> > {
> > indices[currentIndice++] = (i)*slices+j-1+slices;
> > }
> > else
> > {
> > indices[currentIndice++] = ((i-1)*slices)+j-1;
> > }
> > }
> >
> > }
> >
> > currentY -= heightInc;
> > }
> >
> >
> > mesh.SetIndexBufferData( indices, LockFlags.None );
> >
> > // mesh.IndexBuffer.SetData( indices, 0, LockFlags.None );
> >
> > // Mesh mesh = Microsoft.DirectX.Direct3D.Mesh.Cylinder(device,
> > _r1.animVal.value, _r2.animVal.value, _length.animVal.value,
> > (int)_slices.animVal, (int) _stacks.animVal);
> > _mesh.D3DMesh = mesh.Clone(MeshFlags.Managed ,
> > CustomVertex.PositionNormalTextured.Format, device);
> > mesh.Dispose();
> >
> > // GenerateRandomTextureCoordinates();
> >
> >
>
>
- Previous message: JuanK: "RE: Sound effects"
- In reply to: Michel Walsh: "Re: SetIndexBufferData"
- Next in thread: Michel Walsh: "Re: SetIndexBufferData"
- Reply: Michel Walsh: "Re: SetIndexBufferData"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|