Hi!
Based on the tutorial from the wiki, I am trying to create some procedural geometry and am having some problems with the way UV-mapping it. Here is a simple example with a cube, illustrating my problem:
Code:
H3DRes matRes = h3dAddResource(H3DResTypes::Material, "materials/testpattern.material.xml", 0);
h3dutLoadResourcesFromDisk( _params->ContentDirectory.c_str() );
float posData[] = {
-0.5, -0.5, -0.5,
+0.5, -0.5, -0.5,
-0.5, -0.5, +0.5,
+0.5, -0.5, +0.5,
-0.5, +0.5, -0.5,
+0.5, +0.5, -0.5,
-0.5, +0.5, +0.5,
+0.5, +0.5, +0.5,
};
unsigned int posDataCount = 8+2;
unsigned int indexData[] = { 4,0,6, 6,0,2, 2,3,6, 6,3,7, 7,3,5, 5,3,1, 1,0,5, 5,0,4, 4,8,5, 5,8,9 };
unsigned int indexDataCount = 24;
short normalData[] = {
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
};
float uvData[] = {
0,0,//0=3
1,0,//1=2
1,0,//2=1
0,0,//3=0
0,1,//4=7
1,1,//5=6
1,1,//6=5
0,1, //7=4
};
H3DRes geoRes = h3dutCreateGeometryRes( "geoRes", posDataCount, indexDataCount, posData, indexData, normalData, 0, 0, uvData, 0 );
H3DNode model = h3dAddModelNode( H3DRootNode, "DynGeoModelNode", geoRes );
H3DNode cube = h3dAddMeshNode( model, "DynGeoMesh", matRes, 0, indexDataCount, 0, 3 );
It generates a cube-"shell" without a top or bottom. But now I really want to add a top! Sadly since the UV-coordinates seem to be mapped to the vertices, it is not possible to just add two more entries to indexData to the top and bottom like I did with the sides, because those vertices are mapped to the same UV-Coordinates.
Currently I do a workaround by adding two more vertices like this:
Code:
H3DRes matRes = h3dAddResource(H3DResTypes::Material, "materials/testpattern.material.xml", 0);
h3dutLoadResourcesFromDisk( _params->ContentDirectory.c_str() );
float posData[] = {
-0.5, -0.5, -0.5,
+0.5, -0.5, -0.5,
-0.5, -0.5, +0.5,
+0.5, -0.5, +0.5,
-0.5, +0.5, -0.5,
+0.5, +0.5, -0.5,
-0.5, +0.5, +0.5,
+0.5, +0.5, +0.5,
-0.5, +0.5, +0.5,//copy of 6
+0.5, +0.5, +0.5 //copy of 7
};
unsigned int posDataCount = 8+2;
unsigned int indexData[] = { 4,0,6, 6,0,2, 2,3,6, 6,3,7, 7,3,5, 5,3,1, 1,0,5, 5,0,4, 4,8,5, 5,8,9 };
unsigned int indexDataCount = 24+6;
short normalData[] = {
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,//one more
0, 0, 1 //one more
};
float uvData[] = {
0,0,//0=3
1,0,//1=2
1,0,//2=1
0,0,//3=0
0,1,//4=7
1,1,//5=6
1,1,//6=5
0,1, //7=4
0,0,//8=top=0
1,0 //9=top=1
};
H3DRes geoRes = h3dutCreateGeometryRes( "geoRes", posDataCount, indexDataCount, posData, indexData, normalData, 0, 0, uvData, 0 );
H3DNode model = h3dAddModelNode( H3DRootNode, "DynGeoModelNode", geoRes );
H3DNode cube = h3dAddMeshNode( model, "DynGeoMesh", matRes, 0, indexDataCount, 0, 3 );
Works fine, but that can't be the right way to do it. A cube shouldn't need 12 vertices (?). So here are my questions (which probably already include my problem):
- If you have two polygons sharing two vertices, is it possible to UV-map both independently of each other?
- What is the purpose of texture2 in the h3dutCreateGeometryRes? The documentation doesn't tell and the internet is empty.
- Can you draw Quads or Trianglestrips instead of raw polygons? Would that even be faster?
- Are transparent pngs not supported, or do they have to be enabled somehow?
Any help would be greatly appreciated.