suncc
07-12-2009 09:16:08
CAN MOGRE create new meshs? and how?
suncc
07-12-2009 09:16:08
AndroidAdam
08-12-2009 03:52:22
suncc
08-12-2009 08:11:42
WarehouseJim
08-12-2009 14:33:34
private SceneNode CreateTestTetrahedron(string name, float scale, Vector3 position, String materialName)
{
var mo = sceneManager.CreateManualObject(name);
mo.CastShadows = true;
var node = sceneManager.RootSceneNode.CreateChildSceneNode();
Vector3[] c = new Vector3[4]; // corners
// calculate corners of tetrahedron (with point of origin in middle of volume)
Single mbot = scale * 0.2f; // distance middle to bottom
Single mtop = scale * 0.62f; // distance middle to top
Single mf = scale * 0.289f; // distance middle to front
Single mb = scale * 0.577f; // distance middle to back
Single mlr = scale * 0.5f; // distance middle to left right
// width / hight / depth
c[0] = new Vector3(-mlr, -mbot, mf); // left bottom front
c[1] = new Vector3(mlr, -mbot, mf); // right bottom front
c[2] = new Vector3(0, -mbot, -mb); // (middle) bottom back
c[3] = new Vector3(0, mtop, 0); // (middle) top (middle)
// add position offset for all corners (move tetrahedron)
for (Int16 i = 0; i <= 3; i++)
c[i] += position;
// create bottom
mo.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
var normal = (c[1] - c[0]).CrossProduct(c[1] - c[2]).NormalisedCopy;
var normalA = normal;
var normalB = normal;
var normalC = normal;
//this is an attempt to try to make it seem softer.
normalA.x += 2f;
normalA.y += 0.5f;
normalB.y -= 2f;
normalB.x -= 0.5f;
mo.Position(c[0]);
mo.Normal(normalA);
mo.TextureCoord(0,0);
mo.Position(c[1]);
mo.Normal(normalB);
mo.TextureCoord(0,1);
mo.Position(c[2]);
mo.Normal(normalC);
mo.TextureCoord(1,1);
mo.Triangle(0, 1, 2);
mo.Triangle(0, 2, 1);
mo.End();
float lineLen = scale/3;
// create right back side
mo.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
normal = (c[1] - c[2]).CrossProduct(c[1] - c[3]).NormalisedCopy;
normalA = normal;
normalB = normal;
normalC = normal;
normalA.x += 2f;
normalA.y += 0.5f;
normalB.y -= 2f;
normalB.x -= 0.5f;
mo.Position(c[1]);
mo.Normal(normalA);
mo.Position(c[2]);
mo.Normal(normalB);
mo.Position(c[3]);
mo.Normal(normalC);
mo.Triangle(0, 1, 2);
mo.Triangle(0, 2, 1);
mo.End();
// create left back side
normal = (c[0] - c[2]).CrossProduct(c[2] - c[3]);
mo.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
mo.Position(c[3]);
mo.Normal(normal);
mo.Position(c[2]);
mo.Normal(normal);
mo.Position(c[0]);
mo.Normal(normal);
mo.Triangle(0, 1, 2);
mo.Triangle(0, 2, 1);
mo.End();
// create front side
normal = (c[1] - c[3]).CrossProduct(c[0] - c[3]);
mo.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
mo.Position(c[0]);
mo.Normal(normal);
mo.Position(c[1]);
mo.Normal(normal);
mo.Position(c[3]);
mo.Normal(normal);
mo.Triangle(0, 1, 2);
mo.Triangle(0, 2, 1);
mo.End();
node.AttachObject(mo);
return node;
}
MatrixAlgebra
09-12-2009 09:36:15
MatrixAlgebra
09-12-2009 09:47:21
MatrixAlgebra
09-12-2009 10:09:25
WarehouseJim
09-12-2009 10:23:00
public MeshPtr CreateMesh(Vertex[] vertexList, Index[] indexList, string meshName, string materialName)
{
ManualObject mo = sceneManager.CreateManualObject(meshName+"ManualObject");
mo.Begin(materialName, RenderOperation.OperationTypes.OT_TRIANGLE_LIST); //Set the material and state that you are making a mesh out of triangles
//Create all the vertices
foreach(Vertex v in vertexList)
{
mo.Position(v.Position);
mo.Normal(v.Normal);
mo.Colour(v.Color); //NB Ogre uses British English spelling of Colour.
mo.TextureCoord(v.textureCoord.U, v.textureCoord.V);
}
//Create the triangles
foreach(Index index in indexList)
{
mo.Triangle(index.pos1, index.pos2, index.pos3);
}
mo.End(); // End creating the manual object.
return mo.ConvertToMesh(meshName); //Create an actual mesh from the ManualObject, and return.
}