I am trying to permantly transform a mesh so that I don't have to spend valuable computing time transforming a mesh every time I render. I have the following inside my Mesh wrapper class:
[Source]
Sub PermanentTransform(ByRef Matrix As Matrix)
Dim Test As CustomVertex.PositionTextured, I As Integer
Dim Vertices() As Object = myMesh.LockVertexBuffer(myMesh.VertexFormat.GetType, LockFlags.None, myMesh.NumberVertices)
For I = 0 To UBound(Vertices)
Vertices(I).Position = Vector3.TransformCoordinate(Vertices(I).Position, Matrix)
Next I
myMesh.UnlockVertexBuffer()
End Sub
[/Source]
I have read many times to get the vertex format of the mesh through the Mesh.VertexFormat.GetType, but when I do it crashes and gives me the "non-blittable data" error. If I specify a type, like PositionTextured, the net result is a random mess of vertices. I have tried several different types, none of them create a recognizable mesh. By the way, the Matrix I am passing is is a simple Matrix.Scaling(200,200,200).
Ideas

Permanent Transform
Joe K
Hm, I don't think it's a good idea to pretransform a mesh. You could pretransform your object to world space, but only if it is not moving. To further pretransform it into camera space doesn't make sense. As soon as you move your camera you have to retransform it - unless you use a fixed camera. So, you cannot save the matrix multiplication for the view and projection transformations. Also afaik the vertex transformation in hardware is a cheap operation, so you cannot save much computing time. So the only thing you could possibly save is one matrix/matrix multiply in the cpu, if you have a static object pretransformed into world space. But this is not reasonable in my view.
Nico
Andreas_VdBerg
this is in c# and managed directx 2.0
this will preform real rotate,scale,pos on the mesh
so you dont need to transform all the object ever frame
you onlye have to do once
good luck
http://www.3devolution.net
public
PositionNormalTextured Myvertex;#region
Calcluate Position Vertex buffer... public void REALPosition(VertexBuffer MyVertexBuffer, int NumVertex, Vector3 Position){
Matrix mat = Matrix.Identity;mat =
Matrix.Translation(Position.X, Position.Y, Position.Z); GraphicsBuffer<PositionNormalTextured> MyVertexList = MyVertexBuffer.Lock<PositionNormalTextured>(0, NumVertex, LockFlags.None); for (int j = 0; j < NumVertex; j++){
Myvertex = MyVertexList[j];
Myvertex.Position =
Vector3.TransformCoordinate(Myvertex.Position, mat);Myvertex.Normal =
Vector3.TransformCoordinate(Myvertex.Normal, mat);MyVertexList[j] = Myvertex;
}
MyVertexBuffer.Unlock();
MyVertexList.Dispose();
}
#endregion
#region
Calcluate Rotate Vertex buffer... public void REALRotate(VertexBuffer MyVertexBuffer, int NumVertex, Vector3 Rotation){
Matrix mat = Matrix.Identity;mat =
Matrix.RotationYawPitchRoll(Rotation.X, Rotation.Y, Rotation.Z); GraphicsBuffer<PositionNormalTextured> MyVertexList = MyVertexBuffer.Lock<PositionNormalTextured>(0, NumVertex, LockFlags.None); for (int j = 0; j < NumVertex; j++){
Myvertex = MyVertexList[j];
Myvertex.Position =
Vector3.TransformCoordinate(Myvertex.Position, mat);Myvertex.Normal =
Vector3.TransformCoordinate(Myvertex.Normal, mat);MyVertexList[j] = Myvertex;
}
MyVertexBuffer.Unlock();
MyVertexList.Dispose();
}
#endregion
#region
Calcluate Scale Vertex buffer... public void REALScale(VertexBuffer MyVertexBuffer, int NumVertex, Vector3 Scale){
Matrix mat = Matrix.Identity;mat =
Matrix.Scaling(Scale.X, Scale.Y, Scale.Z); GraphicsBuffer<PositionNormalTextured> MyVertexList = MyVertexBuffer.Lock<PositionNormalTextured>(0, NumVertex, LockFlags.None); for (int j = 0; j < NumVertex; j++){
Myvertex = MyVertexList[j];
Myvertex.Position =
Vector3.TransformCoordinate(Myvertex.Position, mat);Myvertex.Normal =
Vector3.TransformCoordinate(Myvertex.Normal, mat);MyVertexList[j] = Myvertex;
}
MyVertexBuffer.Unlock();
MyVertexList.Dispose();
}
#endregion
Alan-CIT
Regardless, I still want to know how to do what I originally asked.
It has been done before, just I have an issue with types.