Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
I am creating and exporting a cube using python FBX SDK. I also create normals but when I export, the normals in the exported model are completely off. I don't know what I am missing - could you please help?
The code is below, but I have also posted on StackOverflow and there also some illustrations are available. You can see here. The .fbx file you can please find attached.
The code:
import fbx
memory_manager = fbx.FbxManager.Create()
scene = fbx.FbxScene.Create(memory_manager, '')
mesh_node = fbx.FbxNode.Create(memory_manager, 'cube')
scene.GetRootNode().AddChild(mesh_node)
# -- mesh
mesh_attribute: fbx.FbxMesh = fbx.FbxMesh.Create(memory_manager, '')
mesh_node.AddNodeAttribute(mesh_attribute)
# -- mesh -- vertices
mesh_attribute.InitControlPoints(8)
CUBE_VERTS = (
(0,0,0),
(0,0,1),
(0,1,0),
(0,1,1),
(1,0,0),
(1,0,1),
(1,1,0),
(1,1,1)
)
for i in range(0, 8):
vert = CUBE_VERTS[i]
mesh_attribute.SetControlPointAt(fbx.FbxVector4(vert[0], vert[1], vert[2], 0.0), i)
# -- mesh -- faces
CUBE_FACES = (
(0,1,3,2),
(3,2,6,7),
(4,5,7,6),
(0,1,5,4),
(1,3,7,5),
(0,2,6,4)
)
for i in range(0, len(CUBE_FACES)):
mesh_attribute.BeginPolygon()
mesh_attribute.AddPolygon(CUBE_FACES[i][0])
mesh_attribute.AddPolygon(CUBE_FACES[i][1])
mesh_attribute.AddPolygon(CUBE_FACES[i][2])
mesh_attribute.AddPolygon(CUBE_FACES[i][3])
mesh_attribute.EndPolygon()
# -- mesh -- normals
NORMALS = [
[-0.57735, -0.57735, -0.57735, 1.0],
[-0.57735, -0.57735, 0.57735, 1.0],
[-0.57735, 0.57735, -0.57735, 1.0],
[-0.57735, 0.57735, 0.57735, 1.0],
[0.57735, -0.57735, -0.57735, 1.0],
[0.57735, -0.57735, 0.57735, 1.0],
[0.57735, 0.57735, -0.57735, 1.0],
[0.57735, 0.57735, 0.57735, 1.0]
]
normal_element: fbx.FbxLayerElementNormal = mesh_attribute.CreateElementNormal()
normal_element.SetMappingMode(fbx.FbxLayerElementNormal.eByControlPoint)
normal_element.SetReferenceMode(fbx.FbxLayerElementNormal.eDirect)
for i in range(0, 8):
normal_element.GetDirectArray().Add(fbx.FbxVector4(NORMALS[i][0], NORMALS[i][1], NORMALS[i][2]))
print_normals_info(mesh_attribute)
# EXPORT
exporter = fbx.FbxExporter.Create(memory_manager, '')
exporter.Initialize('cuby', -1, memory_manager.GetIOSettings())
result = exporter.Export(scene)
if result:
print('exported succesfully')
memory_manager.Destroy()
Solved! Go to Solution.
Solved by serhii.poklonskyi. Go to Solution.
I have answered this question on stack overflow here: https://stackoverflow.com/questions/74330986/create-mesh-normals-in-fbx-sdk
Can't find what you're looking for? Ask the community or share your knowledge.