Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Exporting to Babylon JS

Exporting to Babylon JS

Anonymous
Not applicable
2,305 Views
13 Replies
Message 1 of 14

Exporting to Babylon JS

Anonymous
Not applicable

Hello, 

I'm trying to develop a custom exporter to babylonjs by I have a problem with the control points.

If I have a cube, the control points are 8 ( vertices ) and babylonjs requires that I assign a normal for each control point ( same also for the UVs )

Obviously the normals are not enough. In babylonjs a cube is represented with  24 control points and 24 normals. Each control point have a unique normal.

I found the call 'EmulateNormalsByPolygonVertex' that generates 36 control points/ normals and the geometry looks ok, but it is a waste of resources. 

How can I generate 24 control points/normals ?

0 Likes
2,306 Views
13 Replies
Replies (13)
Message 2 of 14

Christoph_Schaedl
Mentor
Mentor

I would export the data to Blender and go from there.

----------------------------------------------------------------
https://linktr.ee/cg_oglu
0 Likes
Message 3 of 14

Anonymous
Not applicable

I don't understand: blender is not an exported file format. I see only .dae, .obj and .dxf.

I don't know if I'm writing to the wrong forum, but I'm talking about the fbx sdk

 

0 Likes
Message 4 of 14

Christoph_Schaedl
Mentor
Mentor

Right but Blender does have one of the best BabylonJS exporters.

Export your data first to Blender and export to BabylonJS from there.

 

https://www.blender.org/

https://github.com/BabylonJS/BlenderExporter

 

 

----------------------------------------------------------------
https://linktr.ee/cg_oglu
Message 5 of 14

regalir
Autodesk
Autodesk

Please take a look at the ExportScene03 sample. The function CreateCubeWithTexture is creating a cube with 24 points and normals. With the FBX SDK you have the full control on how you create your geometries. The implementation really depends on your goals.

0 Likes
Message 6 of 14

Anonymous
Not applicable

Thank you for your answer, but I'm looking to something different. I'm a c++ developer and I'm using the fbx sdk to write a custom exporter. I'm not searching for a way to export in babylon js, but for a way to force the sdk to arrange the geometry in a different way

0 Likes
Message 7 of 14

Christoph_Schaedl
Mentor
Mentor

I see sorry for the confusion.

----------------------------------------------------------------
https://linktr.ee/cg_oglu
0 Likes
Message 8 of 14

Anonymous
Not applicable

I've seen this example, but I'm reading a file not created by me.

So if I read for example a cube written by 3ds, it has 8 control points.

0 Likes
Message 9 of 14

regalir
Autodesk
Autodesk

The FbxGeometryConverter::EmulateNormalsByPolygonVertex is the correct function to call. It will add the required numbers of control points to match the number of normals defined on each polygon vertex. So, in the case of the cube, you will effectively end-up with 24 control points, instead of 8.

 

before:

 

	Geometry: 3176076104288, "Geometry::", "Mesh" {
		Properties70:  {
			P: "Color", "ColorRGB", "Color", "",0.0313725490196078,0.431372549019608,0.529411764705882
		}
		Vertices: *24 {
			a: -5,-5,0,5,-5,0,-5,5,0,5,5,0,-5,-5,10,5,-5,10,-5,5,10,5,5,10
		} 
		PolygonVertexIndex: *24 {
			a: 0,2,3,-2,4,5,7,-7,0,1,5,-5,1,3,7,-6,3,2,6,-8,2,0,4,-7
		} 
		Edges: *12 {
			a: 0,1,2,3,4,5,6,7,9,11,13,17
		} 

 

 

after:

	Geometry: 2329100146640, "Geometry::", "Mesh" {
		Properties70:  {
			P: "Color", "ColorRGB", "Color", "",0.0313725490196078,0.431372549019608,0.529411764705882
		}
		Vertices: *72 {
			a: -5,-5,0,-5,5,0,5,5,0,5,-5,0,-5,-5,10,5,-5,10,5,5,10,-5,5,10,-5,-5,0,5,-5,0,5,-5,10,-5,-5,10,5,-5,0,5,5,0,5,5,10,5,-5,10,5,5,0,-5,5,0,-5,5,10,5,5,10,-5,5,0,-5,-5,0,-5,-5,10,-5,5,10
		} 
		PolygonVertexIndex: *24 {
			a: 0,1,2,-4,4,5,6,-8,8,9,10,-12,12,13,14,-16,16,17,18,-20,20,21,22,-24
		} 

 

0 Likes
Message 10 of 14

Anonymous
Not applicable

In my case I end up with 36 control points instead the optimal 24. Do you know why ? Any suggestion ?

 

 

0 Likes
Message 11 of 14

regalir
Autodesk
Autodesk

The file you are working with contains a triangulated cube. Each face is not a quad but rather,  two triangles. This adds the extra 12 vertices. If you call FbxMesh::IsTriangleMesh(), you should get true, indicating that all the polygons in the mesh are triangles. This is certainly a valid mesh and I can only hope that Babylon JS does support triangles. If not, you will have to implement your own functions to convert the triangulated meshes into quads.

0 Likes
Message 12 of 14

Anonymous
Not applicable

The file I’m working is triangulated, but my problem is the number of the control points: they are 8 and are not enough to define the normals. I need 24 control points.

Do you know how I can force fbxsdk to generate 24 control points ?

 

0 Likes
Message 13 of 14

regalir
Autodesk
Autodesk

In the FBX SDK. It is perfectly normal to only have 8 control points (FBX definition of the control point is: the physical 3D coordinate) and 36 vertices (a vertex is the point of one polygon).

 

As I wrote earlier, when you call the FbxGeometryConverter::EmulateNormalsByPolygonVertex(...), the function will duplicate the 8 control points so each control point is matching each polygon vertex. In the case of your cube, because there are 36 vertices, you will get 36 control points.

 

If you absolutely want 24 control points, you need to de-triangulate the mesh to get back 6 quad faces instead of 12 triangular faces (and you will need to write your own code because this functionality is out of the scope of the FBX SDK).

 

On the other hand, if you want to access the control points to re-compute the normals (they should already be present in the file), you need to "walk" the polygons so you can get the 3d coordinate from the polygon vertex index (see DisplayMesh.cxx from the ImportScene sample).

 

int i, j, lPolygonCount = pMesh->GetPolygonCount();
FbxVector4* lControlPoints = pMesh->GetControlPoints(); 
int vertexId = 0;
for (i = 0; i < lPolygonCount; i++)
{
    int lPolygonSize = pMesh->GetPolygonSize(i);
    for (j = 0; j < lPolygonSize; j++)
    {
	int lControlPointIndex = pMesh->GetPolygonVertex(i, j);
	if (lControlPointIndex < 0)
	{
		DisplayString("            Coordinates: Invalid index found!");
		continue;
	}
	else
		Display3DVector("            Coordinates: ", lControlPoints[lControlPointIndex]);
    }
} ...
0 Likes
Message 14 of 14

Anonymous
Not applicable

Thank you for the answer. It is not what I was searching, but at least I know that if I develop my own algorithm I'm not reinventing the wheel.

 

0 Likes