Skip to content

Commit

Permalink
Add ufbx for FBX importing
Browse files Browse the repository at this point in the history
The feature of automated fbx2gltf scanning was removed from the codebase.

Co-Authored-By: Samuli Raivio <bqqbarbhg@gmail.com>
  • Loading branch information
fire and bqqbarbhg committed Dec 8, 2023
1 parent a311a4b commit 48afc09
Show file tree
Hide file tree
Showing 46 changed files with 40,966 additions and 59 deletions.
5 changes: 5 additions & 0 deletions COPYRIGHT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ Comment: libSquish
Copyright: 2006, Simon Brown
License: Expat

Files: ./thirdparty/ufbx/
Comment: ufbx
Copyright: 2020, Samuli Raivio
License: Expat

Files: ./thirdparty/thorvg/
Comment: ThorVG
Copyright: 2020-2023, The ThorVG Project
Expand Down
25 changes: 25 additions & 0 deletions modules/fbx/SCsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python

Import("env")
Import("env_modules")

env_fbx = env_modules.Clone()
env_fbx.Append(
CPPDEFINES=[
"UFBX_NO_SUBDIVISION",
"UFBX_NO_TESSELLATION",
"UFBX_NO_GEOMETRY_CACHE",
"UFBX_NO_SCENE_EVALUATION",
"UFBX_NO_INDEX_GENERATION",
"UFBX_NO_SKINNING_EVALUATION",
"UFBX_NO_FORMAT_OBJ",
]
)

# Godot source files
env_fbx.add_source_files(env.modules_sources, "*.cpp")
env_fbx.add_source_files(env.modules_sources, "structures/*.cpp")
env_fbx.add_source_files(env.modules_sources, "#thirdparty/ufbx/ufbx.c")
SConscript("extensions/SCsub")
if env.editor_build:
env_fbx.add_source_files(env.modules_sources, "editor/*.cpp")
25 changes: 25 additions & 0 deletions modules/fbx/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def can_build(env, platform):
return not env["disable_3d"]


def configure(env):
pass


def get_doc_classes():
return [
"FBXAnimation",
"FBXDocument",
"FBXDocumentExtension",
"FBXMesh",
"FBXNode",
"FBXSkeleton",
"FBXSkin",
"FBXState",
"FBXTexture",
"EditorSceneFormatImporterUFBX",
]


def get_doc_path():
return "doc_classes"
11 changes: 11 additions & 0 deletions modules/fbx/doc_classes/EditorSceneFormatImporterUFBX.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="EditorSceneFormatImporterUFBX" inherits="EditorSceneFormatImporter" is_experimental="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Import FBX files using the ufbx library.
</brief_description>
<description>
EditorSceneFormatImporterUFBX is designed to load FBX files and supports both binary and ASCII FBX files from version 3000 onward. This class handles invalid files and out of memory errors gracefully, and supports various 3D object types like meshes, skins, blend shapes, materials, and rigging information. It provides utilities for evaluating loaded scenes, such as polygon triangulation, index generation, animation curve evaluation, and CPU skinning. The class aims for feature parity with the official FBX SDK and supports FBX 7.4 specifications.
</description>
<tutorials>
</tutorials>
</class>
15 changes: 15 additions & 0 deletions modules/fbx/doc_classes/FBXAnimation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="FBXAnimation" inherits="Resource" is_experimental="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
</brief_description>
<description>
FBXAnimation handles FBX animations.
</description>
<tutorials>
</tutorials>
<members>
<member name="loop" type="bool" setter="set_loop" getter="get_loop" default="false">
Determines whether the animation should loop.
</member>
</members>
</class>
59 changes: 59 additions & 0 deletions modules/fbx/doc_classes/FBXDocument.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="FBXDocument" inherits="Resource" is_experimental="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Handles FBX documents.
</brief_description>
<description>
The FBXDocument handles FBX documents. It provides methods to append data from buffers or files, generate scenes, and register/unregister document extensions.
When exporting FBX from Blender, use the "FBX Units Scale" option. The "FBX Units Scale" option sets the correct scale factor and avoids manual adjustments when re-importing into Blender, such as through glTF2 export.
</description>
<tutorials>
</tutorials>
<methods>
<method name="append_from_buffer">
<return type="int" enum="Error" />
<param index="0" name="bytes" type="PackedByteArray" />
<param index="1" name="base_path" type="String" />
<param index="2" name="state" type="FBXState" />
<param index="3" name="flags" type="int" default="0" />
<description>
Appends data from a buffer to the FBX document.
</description>
</method>
<method name="append_from_file">
<return type="int" enum="Error" />
<param index="0" name="path" type="String" />
<param index="1" name="state" type="FBXState" />
<param index="2" name="flags" type="int" default="0" />
<param index="3" name="base_path" type="String" default="&quot;&quot;" />
<description>
Appends data from a file to the FBX document.
</description>
</method>
<method name="generate_scene">
<return type="Node" />
<param index="0" name="state" type="FBXState" />
<param index="1" name="bake_fps" type="float" default="30" />
<param index="2" name="trimming" type="bool" default="false" />
<param index="3" name="remove_immutable_tracks" type="bool" default="true" />
<description>
Generates a scene from the FBX document.
</description>
</method>
<method name="register_fbx_document_extension" qualifiers="static">
<return type="void" />
<param index="0" name="extension" type="FBXDocumentExtension" />
<param index="1" name="first_priority" type="bool" default="false" />
<description>
Registers an extension for the FBX document.
</description>
</method>
<method name="unregister_fbx_document_extension" qualifiers="static">
<return type="void" />
<param index="0" name="extension" type="FBXDocumentExtension" />
<description>
Unregisters an extension from the FBX document.
</description>
</method>
</methods>
</class>
50 changes: 50 additions & 0 deletions modules/fbx/doc_classes/FBXDocumentExtension.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="FBXDocumentExtension" inherits="Resource" is_experimental="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
</brief_description>
<description>
FBXDocumentExtension handles FBX document extensions.
</description>
<tutorials>
</tutorials>
<methods>
<method name="_generate_scene_node" qualifiers="virtual">
<return type="Node3D" />
<param index="0" name="state" type="FBXState" />
<param index="1" name="fbx_node" type="FBXNode" />
<param index="2" name="scene_parent" type="Node" />
<description>
Generates a new scene node based on the given FBX node.
</description>
</method>
<method name="_get_supported_extensions" qualifiers="virtual">
<return type="PackedStringArray" />
<description>
Returns a list of file extensions supported by this class.
</description>
</method>
<method name="_import_post" qualifiers="virtual">
<return type="int" enum="Error" />
<param index="0" name="state" type="FBXState" />
<param index="1" name="root" type="Node" />
<description>
Performs any cleanup or finalization tasks after importing a node.
</description>
</method>
<method name="_import_post_parse" qualifiers="virtual">
<return type="int" enum="Error" />
<param index="0" name="state" type="FBXState" />
<description>
Performs any post-processing tasks after parsing an imported node.
</description>
</method>
<method name="_import_preflight" qualifiers="virtual">
<return type="int" enum="Error" />
<param index="0" name="state" type="FBXState" />
<param index="1" name="extensions" type="PackedStringArray" />
<description>
Performs initial checks and setup before importing a node.
</description>
</method>
</methods>
</class>
25 changes: 25 additions & 0 deletions modules/fbx/doc_classes/FBXMesh.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="FBXMesh" inherits="Resource" is_experimental="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
FBXMesh represents an FBX Mesh.
</brief_description>
<description>
FBXMesh handles 3D mesh data imported from FBX files. It includes properties for blend channels, blend weights, instance materials, and the mesh itself.
</description>
<tutorials>
</tutorials>
<members>
<member name="blend_channels" type="PackedInt32Array" setter="set_blend_channels" getter="get_blend_channels" default="PackedInt32Array()">
An array of integers representing the blend channels of the mesh.
</member>
<member name="blend_weights" type="PackedFloat32Array" setter="set_blend_weights" getter="get_blend_weights" default="PackedFloat32Array()">
An array of floats representing the blend weights of the mesh.
</member>
<member name="instance_materials" type="Material[]" setter="set_instance_materials" getter="get_instance_materials" default="[]">
An array of Material objects representing the materials used in the mesh.
</member>
<member name="mesh" type="ImporterMesh" setter="set_mesh" getter="get_mesh">
The [ImporterMesh] object representing the mesh itself.
</member>
</members>
</class>
70 changes: 70 additions & 0 deletions modules/fbx/doc_classes/FBXNode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="FBXNode" inherits="Resource" is_experimental="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
FBXNode represents an FBX Node.
</brief_description>
<description>
The FBXNode class handles 3D node data imported from FBX files. It includes methods for getting and setting additional data, mesh, and properties for children, height, parent, position, rotation, scale, skeleton, skin, and transform.
</description>
<tutorials>
</tutorials>
<methods>
<method name="get_additional_data">
<return type="Variant" />
<param index="0" name="extension_name" type="StringName" />
<description>
Returns the additional data associated with the given extension name.
</description>
</method>
<method name="get_mesh">
<return type="int" />
<description>
Returns the mesh index of the node.
</description>
</method>
<method name="set_additional_data">
<return type="void" />
<param index="0" name="extension_name" type="StringName" />
<param index="1" name="additional_data" type="Variant" />
<description>
Sets the additional data associated with the given extension name.
</description>
</method>
<method name="set_mesh">
<return type="void" />
<param index="0" name="mesh" type="int" />
<description>
Sets the mesh index of the node.
</description>
</method>
</methods>
<members>
<member name="children" type="PackedInt32Array" setter="set_children" getter="get_children" default="PackedInt32Array()">
An array of integers representing the children nodes of this node.
</member>
<member name="height" type="int" setter="set_height" getter="get_height" default="-1">
The height of the node.
</member>
<member name="parent" type="int" setter="set_parent" getter="get_parent" default="-1">
The parent node ID of this node.
</member>
<member name="position" type="Vector3" setter="set_position" getter="get_position" default="Vector3(0, 0, 0)">
The position of the node in 3D space.
</member>
<member name="rotation" type="Quaternion" setter="set_rotation" getter="get_rotation" default="Quaternion(0, 0, 0, 1)">
The rotation of the node in 3D space.
</member>
<member name="scale" type="Vector3" setter="set_scale" getter="get_scale" default="Vector3(1, 1, 1)">
The scale of the node in 3D space.
</member>
<member name="skeleton" type="int" setter="set_skeleton" getter="get_skeleton" default="-1">
The skeleton index associated with this node.
</member>
<member name="skin" type="int" setter="set_skin" getter="get_skin" default="-1">
The skin index associated with this node.
</member>
<member name="xform" type="Transform3D" setter="set_xform" getter="get_xform" default="Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)">
The transform of the node in 3D space.
</member>
</members>
</class>
66 changes: 66 additions & 0 deletions modules/fbx/doc_classes/FBXSkeleton.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="FBXSkeleton" inherits="Resource" is_experimental="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
FBXSkeleton represents a skeleton in an FBX file.
</brief_description>
<description>
The FBXSkeleton class handles skeleton data imported from FBX files. It includes methods for getting and setting bone attachments, godot bone nodes, unique names, and properties for joints and roots.
</description>
<tutorials>
</tutorials>
<methods>
<method name="get_bone_attachment">
<return type="BoneAttachment3D" />
<param index="0" name="idx" type="int" />
<description>
Gets the BoneAttachment3D object at the given index.
</description>
</method>
<method name="get_bone_attachment_count">
<return type="int" />
<description>
Gets the count of bone attachments.
</description>
</method>
<method name="get_godot_bone_node">
<return type="Dictionary" />
<description>
Gets a dictionary representing the Godot bone node.
</description>
</method>
<method name="get_godot_skeleton">
<return type="Skeleton3D" />
<description>
Gets the Skeleton3D object representing the Godot skeleton.
</description>
</method>
<method name="get_unique_names">
<return type="String[]" />
<description>
Gets an array of unique names.
</description>
</method>
<method name="set_godot_bone_node">
<return type="void" />
<param index="0" name="godot_bone_node" type="Dictionary" />
<description>
Sets the Godot bone node with the given dictionary.
</description>
</method>
<method name="set_unique_names">
<return type="void" />
<param index="0" name="unique_names" type="String[]" />
<description>
Sets the unique names with the given array of strings.
</description>
</method>
</methods>
<members>
<member name="joints" type="PackedInt32Array" setter="set_joints" getter="get_joints" default="PackedInt32Array()">
An array of integers representing the joints in the skeleton.
</member>
<member name="roots" type="PackedInt32Array" setter="set_roots" getter="get_roots" default="PackedInt32Array()">
An array of integers representing the root joints in the skeleton.
</member>
</members>
</class>
Loading

0 comments on commit 48afc09

Please sign in to comment.