summaryrefslogtreecommitdiff
path: root/modules/gltf
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gltf')
-rw-r--r--modules/gltf/README.md11
-rw-r--r--modules/gltf/SCsub4
-rw-r--r--modules/gltf/doc_classes/GLTFCamera.xml41
-rw-r--r--modules/gltf/doc_classes/GLTFDocument.xml38
-rw-r--r--modules/gltf/doc_classes/GLTFDocumentExtension.xml28
-rw-r--r--modules/gltf/doc_classes/GLTFLight.xml31
-rw-r--r--modules/gltf/doc_classes/GLTFMesh.xml2
-rw-r--r--modules/gltf/doc_classes/GLTFSkeleton.xml8
-rw-r--r--modules/gltf/doc_classes/GLTFSkin.xml8
-rw-r--r--modules/gltf/doc_classes/GLTFSpecGloss.xml8
-rw-r--r--modules/gltf/doc_classes/GLTFState.xml70
-rw-r--r--modules/gltf/editor/editor_scene_importer_blend.cpp24
-rw-r--r--modules/gltf/editor/editor_scene_importer_fbx.cpp2
-rw-r--r--modules/gltf/editor/editor_scene_importer_gltf.cpp3
-rw-r--r--modules/gltf/extensions/gltf_light.cpp (renamed from modules/gltf/gltf_light.cpp)120
-rw-r--r--modules/gltf/extensions/gltf_light.h (renamed from modules/gltf/gltf_light.h)9
-rw-r--r--modules/gltf/extensions/gltf_spec_gloss.cpp (renamed from modules/gltf/gltf_spec_gloss.cpp)0
-rw-r--r--modules/gltf/extensions/gltf_spec_gloss.h (renamed from modules/gltf/gltf_spec_gloss.h)6
-rw-r--r--modules/gltf/gltf_camera.cpp47
-rw-r--r--modules/gltf/gltf_defines.h87
-rw-r--r--modules/gltf/gltf_document.cpp385
-rw-r--r--modules/gltf/gltf_document.h96
-rw-r--r--modules/gltf/gltf_document_extension.h3
-rw-r--r--modules/gltf/gltf_document_extension_convert_importer_mesh.h9
-rw-r--r--modules/gltf/gltf_state.cpp143
-rw-r--r--modules/gltf/gltf_state.h93
-rw-r--r--modules/gltf/gltf_template_convert.h94
-rw-r--r--modules/gltf/register_types.cpp52
-rw-r--r--modules/gltf/structures/gltf_accessor.cpp (renamed from modules/gltf/gltf_accessor.cpp)6
-rw-r--r--modules/gltf/structures/gltf_accessor.h (renamed from modules/gltf/gltf_accessor.h)5
-rw-r--r--modules/gltf/structures/gltf_animation.cpp (renamed from modules/gltf/gltf_animation.cpp)0
-rw-r--r--modules/gltf/structures/gltf_animation.h (renamed from modules/gltf/gltf_animation.h)1
-rw-r--r--modules/gltf/structures/gltf_buffer_view.cpp (renamed from modules/gltf/gltf_buffer_view.cpp)2
-rw-r--r--modules/gltf/structures/gltf_buffer_view.h (renamed from modules/gltf/gltf_buffer_view.h)3
-rw-r--r--modules/gltf/structures/gltf_camera.cpp132
-rw-r--r--modules/gltf/structures/gltf_camera.h (renamed from modules/gltf/gltf_camera.h)34
-rw-r--r--modules/gltf/structures/gltf_mesh.cpp (renamed from modules/gltf/gltf_mesh.cpp)4
-rw-r--r--modules/gltf/structures/gltf_mesh.h (renamed from modules/gltf/gltf_mesh.h)6
-rw-r--r--modules/gltf/structures/gltf_node.cpp (renamed from modules/gltf/gltf_node.cpp)0
-rw-r--r--modules/gltf/structures/gltf_node.h (renamed from modules/gltf/gltf_node.h)3
-rw-r--r--modules/gltf/structures/gltf_skeleton.cpp (renamed from modules/gltf/gltf_skeleton.cpp)15
-rw-r--r--modules/gltf/structures/gltf_skeleton.h (renamed from modules/gltf/gltf_skeleton.h)7
-rw-r--r--modules/gltf/structures/gltf_skin.cpp (renamed from modules/gltf/gltf_skin.cpp)16
-rw-r--r--modules/gltf/structures/gltf_skin.h (renamed from modules/gltf/gltf_skin.h)10
-rw-r--r--modules/gltf/structures/gltf_texture.cpp (renamed from modules/gltf/gltf_texture.cpp)0
-rw-r--r--modules/gltf/structures/gltf_texture.h (renamed from modules/gltf/gltf_texture.h)2
46 files changed, 976 insertions, 692 deletions
diff --git a/modules/gltf/README.md b/modules/gltf/README.md
new file mode 100644
index 0000000000..5d8966b201
--- /dev/null
+++ b/modules/gltf/README.md
@@ -0,0 +1,11 @@
+# Godot GLTF import and export module
+
+In a nutshell, the GLTF module works like this:
+
+* The [`structures/`](structures/) folder contains GLTF structures, the
+ small pieces that make up a GLTF file, represented as C++ classes.
+* The [`extensions/`](extensions/) folder contains GLTF extensions, which
+ are optional features that build on top of the base GLTF spec.
+* [`GLTFState`](gltf_state.h) holds collections of structures and extensions.
+* [`GLTFDocument`](gltf_document.h) operates on GLTFState and its elements.
+* The [`editor/`](editor/) folder uses GLTFDocument to import and export 3D models.
diff --git a/modules/gltf/SCsub b/modules/gltf/SCsub
index 3379404a00..71f3ba58d9 100644
--- a/modules/gltf/SCsub
+++ b/modules/gltf/SCsub
@@ -5,7 +5,9 @@ Import("env_modules")
env_gltf = env_modules.Clone()
-# Godot's own source files
+# Godot source files
env_gltf.add_source_files(env.modules_sources, "*.cpp")
+env_gltf.add_source_files(env.modules_sources, "extensions/*.cpp")
+env_gltf.add_source_files(env.modules_sources, "structures/*.cpp")
if env["tools"]:
env_gltf.add_source_files(env.modules_sources, "editor/*.cpp")
diff --git a/modules/gltf/doc_classes/GLTFCamera.xml b/modules/gltf/doc_classes/GLTFCamera.xml
index 9b9eff6141..49efaa1564 100644
--- a/modules/gltf/doc_classes/GLTFCamera.xml
+++ b/modules/gltf/doc_classes/GLTFCamera.xml
@@ -1,19 +1,58 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="GLTFCamera" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ Represents a GLTF camera.
</brief_description>
<description>
+ Represents a camera as defined by the base GLTF spec.
</description>
<tutorials>
+ <link title="GLTF camera detailed specification">https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-camera</link>
+ <link title="GLTF camera spec and example file">https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_015_SimpleCameras.md</link>
</tutorials>
+ <methods>
+ <method name="from_dictionary" qualifiers="static">
+ <return type="GLTFCamera" />
+ <param index="0" name="dictionary" type="Dictionary" />
+ <description>
+ Creates a new GLTFCamera instance by parsing the given [Dictionary].
+ </description>
+ </method>
+ <method name="from_node" qualifiers="static">
+ <return type="GLTFCamera" />
+ <param index="0" name="camera_node" type="Camera3D" />
+ <description>
+ Create a new GLTFCamera instance from the given Godot [Camera3D] node.
+ </description>
+ </method>
+ <method name="to_dictionary" qualifiers="const">
+ <return type="Dictionary" />
+ <description>
+ Serializes this GLTFCamera instance into a [Dictionary].
+ </description>
+ </method>
+ <method name="to_node" qualifiers="const">
+ <return type="Camera3D" />
+ <description>
+ Converts this GLTFCamera instance into a Godot [Camera3D] node.
+ </description>
+ </method>
+ </methods>
<members>
<member name="depth_far" type="float" setter="set_depth_far" getter="get_depth_far" default="4000.0">
+ The distance to the far culling boundary for this camera relative to its local Z axis, in meters. This maps to GLTF's [code]zfar[/code] property.
</member>
<member name="depth_near" type="float" setter="set_depth_near" getter="get_depth_near" default="0.05">
+ The distance to the near culling boundary for this camera relative to its local Z axis, in meters. This maps to GLTF's [code]znear[/code] property.
</member>
- <member name="fov_size" type="float" setter="set_fov_size" getter="get_fov_size" default="75.0">
+ <member name="fov" type="float" setter="set_fov" getter="get_fov" default="1.309">
+ The FOV of the camera. This class and GLTF define the camera FOV in radians, while Godot uses degrees. This maps to GLTF's [code]yfov[/code] property. This value is only used for perspective cameras, when [member perspective] is true.
</member>
<member name="perspective" type="bool" setter="set_perspective" getter="get_perspective" default="true">
+ Whether or not the camera is in perspective mode. If false, the camera is in orthographic/orthogonal mode. This maps to GLTF's camera [code]type[/code] property. See [member Camera3D.projection] and the GLTF spec for more information.
+ </member>
+ <member name="size_mag" type="float" setter="set_size_mag" getter="get_size_mag" default="0.5">
+ The size of the camera. This class and GLTF define the camera size magnitude as a radius in meters, while Godot defines it as a diameter in meters. This maps to GLTF's [code]ymag[/code] property. This value is only used for orthographic/orthogonal cameras, when [member perspective] is false.
</member>
</members>
</class>
diff --git a/modules/gltf/doc_classes/GLTFDocument.xml b/modules/gltf/doc_classes/GLTFDocument.xml
index cb0e3b6754..3cd0f5c0f9 100644
--- a/modules/gltf/doc_classes/GLTFDocument.xml
+++ b/modules/gltf/doc_classes/GLTFDocument.xml
@@ -10,50 +10,50 @@
<methods>
<method name="append_from_buffer">
<return type="int" enum="Error" />
- <argument index="0" name="bytes" type="PackedByteArray" />
- <argument index="1" name="base_path" type="String" />
- <argument index="2" name="state" type="GLTFState" />
- <argument index="3" name="flags" type="int" default="0" />
- <argument index="4" name="bake_fps" type="int" default="30" />
+ <param index="0" name="bytes" type="PackedByteArray" />
+ <param index="1" name="base_path" type="String" />
+ <param index="2" name="state" type="GLTFState" />
+ <param index="3" name="flags" type="int" default="0" />
+ <param index="4" name="bake_fps" type="int" default="30" />
<description>
</description>
</method>
<method name="append_from_file">
<return type="int" enum="Error" />
- <argument index="0" name="path" type="String" />
- <argument index="1" name="state" type="GLTFState" />
- <argument index="2" name="flags" type="int" default="0" />
- <argument index="3" name="bake_fps" type="int" default="30" />
- <argument index="4" name="base_path" type="String" default="&quot;&quot;" />
+ <param index="0" name="path" type="String" />
+ <param index="1" name="state" type="GLTFState" />
+ <param index="2" name="flags" type="int" default="0" />
+ <param index="3" name="bake_fps" type="int" default="30" />
+ <param index="4" name="base_path" type="String" default="&quot;&quot;" />
<description>
</description>
</method>
<method name="append_from_scene">
<return type="int" enum="Error" />
- <argument index="0" name="node" type="Node" />
- <argument index="1" name="state" type="GLTFState" />
- <argument index="2" name="flags" type="int" default="0" />
- <argument index="3" name="bake_fps" type="int" default="30" />
+ <param index="0" name="node" type="Node" />
+ <param index="1" name="state" type="GLTFState" />
+ <param index="2" name="flags" type="int" default="0" />
+ <param index="3" name="bake_fps" type="int" default="30" />
<description>
</description>
</method>
<method name="generate_buffer">
<return type="PackedByteArray" />
- <argument index="0" name="state" type="GLTFState" />
+ <param index="0" name="state" type="GLTFState" />
<description>
</description>
</method>
<method name="generate_scene">
<return type="Node" />
- <argument index="0" name="state" type="GLTFState" />
- <argument index="1" name="bake_fps" type="int" default="30" />
+ <param index="0" name="state" type="GLTFState" />
+ <param index="1" name="bake_fps" type="int" default="30" />
<description>
</description>
</method>
<method name="write_to_filesystem">
<return type="int" enum="Error" />
- <argument index="0" name="state" type="GLTFState" />
- <argument index="1" name="path" type="String" />
+ <param index="0" name="state" type="GLTFState" />
+ <param index="1" name="path" type="String" />
<description>
</description>
</method>
diff --git a/modules/gltf/doc_classes/GLTFDocumentExtension.xml b/modules/gltf/doc_classes/GLTFDocumentExtension.xml
index 3c28546ad7..d2a9022445 100644
--- a/modules/gltf/doc_classes/GLTFDocumentExtension.xml
+++ b/modules/gltf/doc_classes/GLTFDocumentExtension.xml
@@ -9,50 +9,50 @@
<methods>
<method name="_export_node" qualifiers="virtual">
<return type="int" />
- <argument index="0" name="state" type="GLTFState" />
- <argument index="1" name="gltf_node" type="GLTFNode" />
- <argument index="2" name="json" type="Dictionary" />
- <argument index="3" name="node" type="Node" />
+ <param index="0" name="state" type="GLTFState" />
+ <param index="1" name="gltf_node" type="GLTFNode" />
+ <param index="2" name="json" type="Dictionary" />
+ <param index="3" name="node" type="Node" />
<description>
</description>
</method>
<method name="_export_post" qualifiers="virtual">
<return type="int" />
- <argument index="0" name="state" type="GLTFState" />
+ <param index="0" name="state" type="GLTFState" />
<description>
</description>
</method>
<method name="_export_preflight" qualifiers="virtual">
<return type="int" />
- <argument index="0" name="root" type="Node" />
+ <param index="0" name="root" type="Node" />
<description>
</description>
</method>
<method name="_import_node" qualifiers="virtual">
<return type="int" />
- <argument index="0" name="state" type="GLTFState" />
- <argument index="1" name="gltf_node" type="GLTFNode" />
- <argument index="2" name="json" type="Dictionary" />
- <argument index="3" name="node" type="Node" />
+ <param index="0" name="state" type="GLTFState" />
+ <param index="1" name="gltf_node" type="GLTFNode" />
+ <param index="2" name="json" type="Dictionary" />
+ <param index="3" name="node" type="Node" />
<description>
</description>
</method>
<method name="_import_post" qualifiers="virtual">
<return type="int" />
- <argument index="0" name="state" type="GLTFState" />
- <argument index="1" name="root" type="Node" />
+ <param index="0" name="state" type="GLTFState" />
+ <param index="1" name="root" type="Node" />
<description>
</description>
</method>
<method name="_import_post_parse" qualifiers="virtual">
<return type="int" />
- <argument index="0" name="state" type="GLTFState" />
+ <param index="0" name="state" type="GLTFState" />
<description>
</description>
</method>
<method name="_import_preflight" qualifiers="virtual">
<return type="int" />
- <argument index="0" name="state" type="GLTFState" />
+ <param index="0" name="state" type="GLTFState" />
<description>
</description>
</method>
diff --git a/modules/gltf/doc_classes/GLTFLight.xml b/modules/gltf/doc_classes/GLTFLight.xml
index 354cd48a06..7fd59e14bc 100644
--- a/modules/gltf/doc_classes/GLTFLight.xml
+++ b/modules/gltf/doc_classes/GLTFLight.xml
@@ -1,11 +1,42 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="GLTFLight" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ Represents a GLTF light.
</brief_description>
<description>
+ Represents a light as defined by the [code]KHR_lights_punctual[/code] GLTF extension.
</description>
<tutorials>
+ <link title="KHR_lights_punctual GLTF extension spec">https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual</link>
</tutorials>
+ <methods>
+ <method name="from_dictionary" qualifiers="static">
+ <return type="GLTFLight" />
+ <param index="0" name="dictionary" type="Dictionary" />
+ <description>
+ Creates a new GLTFLight instance by parsing the given [Dictionary].
+ </description>
+ </method>
+ <method name="from_node" qualifiers="static">
+ <return type="GLTFLight" />
+ <param index="0" name="light_node" type="Light3D" />
+ <description>
+ Create a new GLTFLight instance from the given Godot [Light3D] node.
+ </description>
+ </method>
+ <method name="to_dictionary" qualifiers="const">
+ <return type="Dictionary" />
+ <description>
+ Serializes this GLTFLight instance into a [Dictionary].
+ </description>
+ </method>
+ <method name="to_node" qualifiers="const">
+ <return type="Light3D" />
+ <description>
+ Converts this GLTFLight instance into a Godot [Light3D] node.
+ </description>
+ </method>
+ </methods>
<members>
<member name="color" type="Color" setter="set_color" getter="get_color" default="Color(1, 1, 1, 1)">
The [Color] of the light. Defaults to white. A black color causes the light to have no effect.
diff --git a/modules/gltf/doc_classes/GLTFMesh.xml b/modules/gltf/doc_classes/GLTFMesh.xml
index bac351cc20..4d2df872ea 100644
--- a/modules/gltf/doc_classes/GLTFMesh.xml
+++ b/modules/gltf/doc_classes/GLTFMesh.xml
@@ -9,7 +9,7 @@
<members>
<member name="blend_weights" type="PackedFloat32Array" setter="set_blend_weights" getter="get_blend_weights" default="PackedFloat32Array()">
</member>
- <member name="instance_materials" type="Array" setter="set_instance_materials" getter="get_instance_materials" default="[]">
+ <member name="instance_materials" type="Material[]" setter="set_instance_materials" getter="get_instance_materials" default="[]">
</member>
<member name="mesh" type="ImporterMesh" setter="set_mesh" getter="get_mesh">
</member>
diff --git a/modules/gltf/doc_classes/GLTFSkeleton.xml b/modules/gltf/doc_classes/GLTFSkeleton.xml
index dad985e886..d6ec09f113 100644
--- a/modules/gltf/doc_classes/GLTFSkeleton.xml
+++ b/modules/gltf/doc_classes/GLTFSkeleton.xml
@@ -9,7 +9,7 @@
<methods>
<method name="get_bone_attachment">
<return type="BoneAttachment3D" />
- <argument index="0" name="idx" type="int" />
+ <param index="0" name="idx" type="int" />
<description>
</description>
</method>
@@ -29,19 +29,19 @@
</description>
</method>
<method name="get_unique_names">
- <return type="Array" />
+ <return type="String[]" />
<description>
</description>
</method>
<method name="set_godot_bone_node">
<return type="void" />
- <argument index="0" name="godot_bone_node" type="Dictionary" />
+ <param index="0" name="godot_bone_node" type="Dictionary" />
<description>
</description>
</method>
<method name="set_unique_names">
<return type="void" />
- <argument index="0" name="unique_names" type="Array" />
+ <param index="0" name="unique_names" type="String[]" />
<description>
</description>
</method>
diff --git a/modules/gltf/doc_classes/GLTFSkin.xml b/modules/gltf/doc_classes/GLTFSkin.xml
index b6a2bdb957..4de32857b5 100644
--- a/modules/gltf/doc_classes/GLTFSkin.xml
+++ b/modules/gltf/doc_classes/GLTFSkin.xml
@@ -8,7 +8,7 @@
</tutorials>
<methods>
<method name="get_inverse_binds">
- <return type="Array" />
+ <return type="Transform3D[]" />
<description>
</description>
</method>
@@ -24,19 +24,19 @@
</method>
<method name="set_inverse_binds">
<return type="void" />
- <argument index="0" name="inverse_binds" type="Array" />
+ <param index="0" name="inverse_binds" type="Transform3D[]" />
<description>
</description>
</method>
<method name="set_joint_i_to_bone_i">
<return type="void" />
- <argument index="0" name="joint_i_to_bone_i" type="Dictionary" />
+ <param index="0" name="joint_i_to_bone_i" type="Dictionary" />
<description>
</description>
</method>
<method name="set_joint_i_to_name">
<return type="void" />
- <argument index="0" name="joint_i_to_name" type="Dictionary" />
+ <param index="0" name="joint_i_to_name" type="Dictionary" />
<description>
</description>
</method>
diff --git a/modules/gltf/doc_classes/GLTFSpecGloss.xml b/modules/gltf/doc_classes/GLTFSpecGloss.xml
index 8433cf8dd7..8882e48257 100644
--- a/modules/gltf/doc_classes/GLTFSpecGloss.xml
+++ b/modules/gltf/doc_classes/GLTFSpecGloss.xml
@@ -1,21 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="GLTFSpecGloss" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
+ Archived GLTF extension for specular/glossy materials.
</brief_description>
<description>
+ KHR_materials_pbrSpecularGlossiness is an archived GLTF extension. This means that it is deprecated and not recommended for new files. However, it is still supported for loading old files.
</description>
<tutorials>
+ <link title="KHR_materials_pbrSpecularGlossiness GLTF extension spec">https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness</link>
</tutorials>
<members>
<member name="diffuse_factor" type="Color" setter="set_diffuse_factor" getter="get_diffuse_factor" default="Color(1, 1, 1, 1)">
+ The reflected diffuse factor of the material.
</member>
<member name="diffuse_img" type="Image" setter="set_diffuse_img" getter="get_diffuse_img">
+ The diffuse texture.
</member>
<member name="gloss_factor" type="float" setter="set_gloss_factor" getter="get_gloss_factor" default="1.0">
+ The glossiness or smoothness of the material.
</member>
<member name="spec_gloss_img" type="Image" setter="set_spec_gloss_img" getter="get_spec_gloss_img">
+ The specular-glossiness texture.
</member>
<member name="specular_factor" type="Color" setter="set_specular_factor" getter="get_specular_factor" default="Color(1, 1, 1, 1)">
+ The specular RGB color of the material. The alpha channel is unused.
</member>
</members>
</class>
diff --git a/modules/gltf/doc_classes/GLTFState.xml b/modules/gltf/doc_classes/GLTFState.xml
index 44a1723563..1dbd89aed8 100644
--- a/modules/gltf/doc_classes/GLTFState.xml
+++ b/modules/gltf/doc_classes/GLTFState.xml
@@ -8,65 +8,65 @@
</tutorials>
<methods>
<method name="get_accessors">
- <return type="Array" />
+ <return type="GLTFAccessor[]" />
<description>
</description>
</method>
<method name="get_animation_player">
<return type="AnimationPlayer" />
- <argument index="0" name="idx" type="int" />
+ <param index="0" name="idx" type="int" />
<description>
</description>
</method>
<method name="get_animation_players_count">
<return type="int" />
- <argument index="0" name="idx" type="int" />
+ <param index="0" name="idx" type="int" />
<description>
</description>
</method>
<method name="get_animations">
- <return type="Array" />
+ <return type="GLTFAnimation[]" />
<description>
</description>
</method>
<method name="get_buffer_views">
- <return type="Array" />
+ <return type="GLTFBufferView[]" />
<description>
</description>
</method>
<method name="get_cameras">
- <return type="Array" />
+ <return type="GLTFCamera[]" />
<description>
</description>
</method>
<method name="get_images">
- <return type="Array" />
+ <return type="Texture2D[]" />
<description>
</description>
</method>
<method name="get_lights">
- <return type="Array" />
+ <return type="GLTFLight[]" />
<description>
</description>
</method>
<method name="get_materials">
- <return type="Array" />
+ <return type="BaseMaterial3D[]" />
<description>
</description>
</method>
<method name="get_meshes">
- <return type="Array" />
+ <return type="GLTFMesh[]" />
<description>
</description>
</method>
<method name="get_nodes">
- <return type="Array" />
+ <return type="GLTFNode[]" />
<description>
</description>
</method>
<method name="get_scene_node">
<return type="Node" />
- <argument index="0" name="idx" type="int" />
+ <param index="0" name="idx" type="int" />
<description>
</description>
</method>
@@ -76,117 +76,117 @@
</description>
</method>
<method name="get_skeletons">
- <return type="Array" />
+ <return type="GLTFSkeleton[]" />
<description>
</description>
</method>
<method name="get_skins">
- <return type="Array" />
+ <return type="GLTFSkin[]" />
<description>
</description>
</method>
<method name="get_textures">
- <return type="Array" />
+ <return type="GLTFTexture[]" />
<description>
</description>
</method>
<method name="get_unique_animation_names">
- <return type="Array" />
+ <return type="String[]" />
<description>
</description>
</method>
<method name="get_unique_names">
- <return type="Array" />
+ <return type="String[]" />
<description>
</description>
</method>
<method name="set_accessors">
<return type="void" />
- <argument index="0" name="accessors" type="Array" />
+ <param index="0" name="accessors" type="GLTFAccessor[]" />
<description>
</description>
</method>
<method name="set_animations">
<return type="void" />
- <argument index="0" name="animations" type="Array" />
+ <param index="0" name="animations" type="GLTFAnimation[]" />
<description>
</description>
</method>
<method name="set_buffer_views">
<return type="void" />
- <argument index="0" name="buffer_views" type="Array" />
+ <param index="0" name="buffer_views" type="GLTFBufferView[]" />
<description>
</description>
</method>
<method name="set_cameras">
<return type="void" />
- <argument index="0" name="cameras" type="Array" />
+ <param index="0" name="cameras" type="GLTFCamera[]" />
<description>
</description>
</method>
<method name="set_images">
<return type="void" />
- <argument index="0" name="images" type="Array" />
+ <param index="0" name="images" type="Texture2D[]" />
<description>
</description>
</method>
<method name="set_lights">
<return type="void" />
- <argument index="0" name="lights" type="Array" />
+ <param index="0" name="lights" type="GLTFLight[]" />
<description>
</description>
</method>
<method name="set_materials">
<return type="void" />
- <argument index="0" name="materials" type="Array" />
+ <param index="0" name="materials" type="BaseMaterial3D[]" />
<description>
</description>
</method>
<method name="set_meshes">
<return type="void" />
- <argument index="0" name="meshes" type="Array" />
+ <param index="0" name="meshes" type="GLTFMesh[]" />
<description>
</description>
</method>
<method name="set_nodes">
<return type="void" />
- <argument index="0" name="nodes" type="Array" />
+ <param index="0" name="nodes" type="GLTFNode[]" />
<description>
</description>
</method>
<method name="set_skeleton_to_node">
<return type="void" />
- <argument index="0" name="skeleton_to_node" type="Dictionary" />
+ <param index="0" name="skeleton_to_node" type="Dictionary" />
<description>
</description>
</method>
<method name="set_skeletons">
<return type="void" />
- <argument index="0" name="skeletons" type="Array" />
+ <param index="0" name="skeletons" type="GLTFSkeleton[]" />
<description>
</description>
</method>
<method name="set_skins">
<return type="void" />
- <argument index="0" name="skins" type="Array" />
+ <param index="0" name="skins" type="GLTFSkin[]" />
<description>
</description>
</method>
<method name="set_textures">
<return type="void" />
- <argument index="0" name="textures" type="Array" />
+ <param index="0" name="textures" type="GLTFTexture[]" />
<description>
</description>
</method>
<method name="set_unique_animation_names">
<return type="void" />
- <argument index="0" name="unique_animation_names" type="Array" />
+ <param index="0" name="unique_animation_names" type="String[]" />
<description>
</description>
</method>
<method name="set_unique_names">
<return type="void" />
- <argument index="0" name="unique_names" type="Array" />
+ <param index="0" name="unique_names" type="String[]" />
<description>
</description>
</method>
@@ -194,7 +194,9 @@
<members>
<member name="base_path" type="String" setter="set_base_path" getter="get_base_path" default="&quot;&quot;">
</member>
- <member name="buffers" type="Array" setter="set_buffers" getter="get_buffers" default="[]">
+ <member name="buffers" type="PackedByteArray[]" setter="set_buffers" getter="get_buffers" default="[]">
+ </member>
+ <member name="create_animations" type="bool" setter="set_create_animations" getter="get_create_animations" default="true">
</member>
<member name="glb_data" type="PackedByteArray" setter="set_glb_data" getter="get_glb_data" default="PackedByteArray()">
</member>
@@ -204,7 +206,7 @@
</member>
<member name="minor_version" type="int" setter="set_minor_version" getter="get_minor_version" default="0">
</member>
- <member name="root_nodes" type="Array" setter="set_root_nodes" getter="get_root_nodes" default="[]">
+ <member name="root_nodes" type="PackedInt32Array" setter="set_root_nodes" getter="get_root_nodes" default="PackedInt32Array()">
</member>
<member name="scene_name" type="String" setter="set_scene_name" getter="get_scene_name" default="&quot;&quot;">
</member>
diff --git a/modules/gltf/editor/editor_scene_importer_blend.cpp b/modules/gltf/editor/editor_scene_importer_blend.cpp
index 676862ea5a..ab52761e17 100644
--- a/modules/gltf/editor/editor_scene_importer_blend.cpp
+++ b/modules/gltf/editor/editor_scene_importer_blend.cpp
@@ -64,7 +64,7 @@ Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_
// Escape paths to be valid Python strings to embed in the script.
const String source_global = ProjectSettings::get_singleton()->globalize_path(p_path).c_escape();
- const String sink = ProjectSettings::get_singleton()->get_imported_files_path().plus_file(
+ const String sink = ProjectSettings::get_singleton()->get_imported_files_path().path_join(
vformat("%s-%s.gltf", p_path.get_file().get_basename(), p_path.md5_text()));
const String sink_global = ProjectSettings::get_singleton()->globalize_path(sink).c_escape();
@@ -193,9 +193,9 @@ Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_
String blender_path = EDITOR_GET("filesystem/import/blender/blender3_path");
#ifdef WINDOWS_ENABLED
- blender_path = blender_path.plus_file("blender.exe");
+ blender_path = blender_path.path_join("blender.exe");
#else
- blender_path = blender_path.plus_file("blender");
+ blender_path = blender_path.path_join("blender");
#endif
List<String> args;
@@ -287,14 +287,14 @@ void EditorSceneFormatImporterBlend::get_import_options(const String &p_path, Li
static bool _test_blender_path(const String &p_path, String *r_err = nullptr) {
String path = p_path;
#ifdef WINDOWS_ENABLED
- path = path.plus_file("blender.exe");
+ path = path.path_join("blender.exe");
#else
- path = path.plus_file("blender");
+ path = path.path_join("blender");
#endif
-#if defined(OSX_ENABLED)
+#if defined(MACOS_ENABLED)
if (!FileAccess::exists(path)) {
- path = path.plus_file("Blender");
+ path = path.path_join("Blender");
}
#endif
@@ -449,9 +449,9 @@ bool EditorFileSystemImportFormatSupportQueryBlend::query() {
EditorNode::get_singleton()->get_gui_base()->add_child(configure_blender_dialog);
- configure_blender_dialog->get_ok_button()->set_text(TTR("Confirm Path"));
- configure_blender_dialog->get_cancel_button()->set_text(TTR("Disable '.blend' Import"));
- configure_blender_dialog->get_cancel_button()->set_tooltip(TTR("Disables Blender '.blend' files import for this project. Can be re-enabled in Project Settings."));
+ configure_blender_dialog->set_ok_button_text(TTR("Confirm Path"));
+ configure_blender_dialog->set_cancel_button_text(TTR("Disable '.blend' Import"));
+ configure_blender_dialog->get_cancel_button()->set_tooltip_text(TTR("Disables Blender '.blend' files import for this project. Can be re-enabled in Project Settings."));
configure_blender_dialog->connect("confirmed", callable_mp(this, &EditorFileSystemImportFormatSupportQueryBlend::_path_confirmed));
browse_dialog = memnew(EditorFileDialog);
@@ -468,7 +468,7 @@ bool EditorFileSystemImportFormatSupportQueryBlend::query() {
// Autodetect
auto_detected_path = "";
-#if defined(OSX_ENABLED)
+#if defined(MACOS_ENABLED)
{
Vector<String> mdfind_paths;
@@ -485,7 +485,7 @@ bool EditorFileSystemImportFormatSupportQueryBlend::query() {
bool found = false;
for (const String &path : mdfind_paths) {
- found = _autodetect_path(path.plus_file("Contents/MacOS"));
+ found = _autodetect_path(path.path_join("Contents/MacOS"));
if (found) {
break;
}
diff --git a/modules/gltf/editor/editor_scene_importer_fbx.cpp b/modules/gltf/editor/editor_scene_importer_fbx.cpp
index faad2d315d..017a44cccf 100644
--- a/modules/gltf/editor/editor_scene_importer_fbx.cpp
+++ b/modules/gltf/editor/editor_scene_importer_fbx.cpp
@@ -57,7 +57,7 @@ Node *EditorSceneFormatImporterFBX::import_scene(const String &p_path, uint32_t
// enclosed in double quotes by OS::execute(), so we only need to escape those.
// `c_escape_multiline()` seems to do this (escapes `\` and `"` only).
const String source_global = ProjectSettings::get_singleton()->globalize_path(p_path).c_escape_multiline();
- const String sink = ProjectSettings::get_singleton()->get_imported_files_path().plus_file(
+ const String sink = ProjectSettings::get_singleton()->get_imported_files_path().path_join(
vformat("%s-%s.glb", p_path.get_file().get_basename(), p_path.md5_text()));
const String sink_global = ProjectSettings::get_singleton()->globalize_path(sink).c_escape_multiline();
diff --git a/modules/gltf/editor/editor_scene_importer_gltf.cpp b/modules/gltf/editor/editor_scene_importer_gltf.cpp
index 3fadec5167..161808aade 100644
--- a/modules/gltf/editor/editor_scene_importer_gltf.cpp
+++ b/modules/gltf/editor/editor_scene_importer_gltf.cpp
@@ -60,6 +60,9 @@ Node *EditorSceneFormatImporterGLTF::import_scene(const String &p_path, uint32_t
}
return nullptr;
}
+ if (p_options.has("animation/import")) {
+ state->set_create_animations(bool(p_options["animation/import"]));
+ }
return doc->generate_scene(state, p_bake_fps);
}
diff --git a/modules/gltf/gltf_light.cpp b/modules/gltf/extensions/gltf_light.cpp
index af21a4e804..6923c765cb 100644
--- a/modules/gltf/gltf_light.cpp
+++ b/modules/gltf/extensions/gltf_light.cpp
@@ -31,6 +31,12 @@
#include "gltf_light.h"
void GLTFLight::_bind_methods() {
+ ClassDB::bind_static_method("GLTFLight", D_METHOD("from_node", "light_node"), &GLTFLight::from_node);
+ ClassDB::bind_method(D_METHOD("to_node"), &GLTFLight::to_node);
+
+ ClassDB::bind_static_method("GLTFLight", D_METHOD("from_dictionary", "dictionary"), &GLTFLight::from_dictionary);
+ ClassDB::bind_method(D_METHOD("to_dictionary"), &GLTFLight::to_dictionary);
+
ClassDB::bind_method(D_METHOD("get_color"), &GLTFLight::get_color);
ClassDB::bind_method(D_METHOD("set_color", "color"), &GLTFLight::set_color);
ClassDB::bind_method(D_METHOD("get_intensity"), &GLTFLight::get_intensity);
@@ -99,3 +105,117 @@ float GLTFLight::get_outer_cone_angle() {
void GLTFLight::set_outer_cone_angle(float p_outer_cone_angle) {
outer_cone_angle = p_outer_cone_angle;
}
+
+Ref<GLTFLight> GLTFLight::from_node(const Light3D *p_light) {
+ Ref<GLTFLight> l;
+ l.instantiate();
+ ERR_FAIL_COND_V_MSG(!p_light, l, "Tried to create a GLTFLight from a Light3D node, but the given node was null.");
+ l->color = p_light->get_color();
+ if (cast_to<DirectionalLight3D>(p_light)) {
+ l->light_type = "directional";
+ const DirectionalLight3D *light = cast_to<const DirectionalLight3D>(p_light);
+ l->intensity = light->get_param(DirectionalLight3D::PARAM_ENERGY);
+ l->range = FLT_MAX; // Range for directional lights is infinite in Godot.
+ } else if (cast_to<const OmniLight3D>(p_light)) {
+ l->light_type = "point";
+ const OmniLight3D *light = cast_to<const OmniLight3D>(p_light);
+ l->range = light->get_param(OmniLight3D::PARAM_RANGE);
+ l->intensity = light->get_param(OmniLight3D::PARAM_ENERGY);
+ } else if (cast_to<const SpotLight3D>(p_light)) {
+ l->light_type = "spot";
+ const SpotLight3D *light = cast_to<const SpotLight3D>(p_light);
+ l->range = light->get_param(SpotLight3D::PARAM_RANGE);
+ l->intensity = light->get_param(SpotLight3D::PARAM_ENERGY);
+ l->outer_cone_angle = Math::deg_to_rad(light->get_param(SpotLight3D::PARAM_SPOT_ANGLE));
+ // This equation is the inverse of the import equation (which has a desmos link).
+ float angle_ratio = 1 - (0.2 / (0.1 + light->get_param(SpotLight3D::PARAM_SPOT_ATTENUATION)));
+ angle_ratio = MAX(0, angle_ratio);
+ l->inner_cone_angle = l->outer_cone_angle * angle_ratio;
+ }
+ return l;
+}
+
+Light3D *GLTFLight::to_node() const {
+ if (light_type == "directional") {
+ DirectionalLight3D *light = memnew(DirectionalLight3D);
+ light->set_param(Light3D::PARAM_ENERGY, intensity);
+ light->set_color(color);
+ return light;
+ }
+ const float range = CLAMP(this->range, 0, 4096);
+ if (light_type == "point") {
+ OmniLight3D *light = memnew(OmniLight3D);
+ light->set_param(OmniLight3D::PARAM_ENERGY, intensity);
+ light->set_param(OmniLight3D::PARAM_RANGE, range);
+ light->set_color(color);
+ return light;
+ }
+ if (light_type == "spot") {
+ SpotLight3D *light = memnew(SpotLight3D);
+ light->set_param(SpotLight3D::PARAM_ENERGY, intensity);
+ light->set_param(SpotLight3D::PARAM_RANGE, range);
+ light->set_param(SpotLight3D::PARAM_SPOT_ANGLE, Math::rad_to_deg(outer_cone_angle));
+ light->set_color(color);
+ // Line of best fit derived from guessing, see https://www.desmos.com/calculator/biiflubp8b
+ // The points in desmos are not exact, except for (1, infinity).
+ float angle_ratio = inner_cone_angle / outer_cone_angle;
+ float angle_attenuation = 0.2 / (1 - angle_ratio) - 0.1;
+ light->set_param(SpotLight3D::PARAM_SPOT_ATTENUATION, angle_attenuation);
+ return light;
+ }
+ return memnew(Light3D);
+}
+
+Ref<GLTFLight> GLTFLight::from_dictionary(const Dictionary p_dictionary) {
+ ERR_FAIL_COND_V_MSG(!p_dictionary.has("type"), Ref<GLTFLight>(), "Failed to parse GLTF light, missing required field 'type'.");
+ Ref<GLTFLight> light;
+ light.instantiate();
+ const String &type = p_dictionary["type"];
+ light->light_type = type;
+
+ if (p_dictionary.has("color")) {
+ const Array &arr = p_dictionary["color"];
+ if (arr.size() == 3) {
+ light->color = Color(arr[0], arr[1], arr[2]).linear_to_srgb();
+ } else {
+ ERR_PRINT("Error parsing GLTF light: The color must have exactly 3 numbers.");
+ }
+ }
+ if (p_dictionary.has("intensity")) {
+ light->intensity = p_dictionary["intensity"];
+ }
+ if (p_dictionary.has("range")) {
+ light->range = p_dictionary["range"];
+ }
+ if (type == "spot") {
+ const Dictionary &spot = p_dictionary["spot"];
+ light->inner_cone_angle = spot["innerConeAngle"];
+ light->outer_cone_angle = spot["outerConeAngle"];
+ if (light->inner_cone_angle >= light->outer_cone_angle) {
+ ERR_PRINT("Error parsing GLTF light: The inner angle must be smaller than the outer angle.");
+ }
+ } else if (type != "point" && type != "directional") {
+ ERR_PRINT("Error parsing GLTF light: Light type '" + type + "' is unknown.");
+ }
+ return light;
+}
+
+Dictionary GLTFLight::to_dictionary() const {
+ Dictionary d;
+ Array color_array;
+ color_array.resize(3);
+ color_array[0] = color.r;
+ color_array[1] = color.g;
+ color_array[2] = color.b;
+ d["color"] = color_array;
+ d["type"] = light_type;
+ if (light_type == "spot") {
+ Dictionary spot_dict;
+ spot_dict["innerConeAngle"] = inner_cone_angle;
+ spot_dict["outerConeAngle"] = outer_cone_angle;
+ d["spot"] = spot_dict;
+ }
+ d["intensity"] = intensity;
+ d["range"] = range;
+ return d;
+}
diff --git a/modules/gltf/gltf_light.h b/modules/gltf/extensions/gltf_light.h
index 25e0835a33..04980e144c 100644
--- a/modules/gltf/gltf_light.h
+++ b/modules/gltf/extensions/gltf_light.h
@@ -33,6 +33,9 @@
#include "core/config/engine.h"
#include "core/io/resource.h"
+#include "scene/3d/light_3d.h"
+
+// https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual
class GLTFLight : public Resource {
GDCLASS(GLTFLight, Resource)
@@ -67,6 +70,12 @@ public:
float get_outer_cone_angle();
void set_outer_cone_angle(float p_outer_cone_angle);
+
+ static Ref<GLTFLight> from_node(const Light3D *p_light);
+ Light3D *to_node() const;
+
+ static Ref<GLTFLight> from_dictionary(const Dictionary p_dictionary);
+ Dictionary to_dictionary() const;
};
#endif // GLTF_LIGHT_H
diff --git a/modules/gltf/gltf_spec_gloss.cpp b/modules/gltf/extensions/gltf_spec_gloss.cpp
index 83af91bfcc..83af91bfcc 100644
--- a/modules/gltf/gltf_spec_gloss.cpp
+++ b/modules/gltf/extensions/gltf_spec_gloss.cpp
diff --git a/modules/gltf/gltf_spec_gloss.h b/modules/gltf/extensions/gltf_spec_gloss.h
index f8a431bdce..2b4d3ee609 100644
--- a/modules/gltf/gltf_spec_gloss.h
+++ b/modules/gltf/extensions/gltf_spec_gloss.h
@@ -34,6 +34,11 @@
#include "core/io/image.h"
#include "core/io/resource.h"
+// KHR_materials_pbrSpecularGlossiness is an archived GLTF extension.
+// This means that it is deprecated and not recommended for new files.
+// However, it is still supported for loading old files.
+// https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness
+
class GLTFSpecGloss : public Resource {
GDCLASS(GLTFSpecGloss, Resource);
friend class GLTFDocument;
@@ -64,4 +69,5 @@ public:
Ref<Image> get_spec_gloss_img();
void set_spec_gloss_img(Ref<Image> p_spec_gloss_img);
};
+
#endif // GLTF_SPEC_GLOSS_H
diff --git a/modules/gltf/gltf_camera.cpp b/modules/gltf/gltf_camera.cpp
deleted file mode 100644
index f3ea6a1c4c..0000000000
--- a/modules/gltf/gltf_camera.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/*************************************************************************/
-/* gltf_camera.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#include "gltf_camera.h"
-
-void GLTFCamera::_bind_methods() {
- ClassDB::bind_method(D_METHOD("get_perspective"), &GLTFCamera::get_perspective);
- ClassDB::bind_method(D_METHOD("set_perspective", "perspective"), &GLTFCamera::set_perspective);
- ClassDB::bind_method(D_METHOD("get_fov_size"), &GLTFCamera::get_fov_size);
- ClassDB::bind_method(D_METHOD("set_fov_size", "fov_size"), &GLTFCamera::set_fov_size);
- ClassDB::bind_method(D_METHOD("get_depth_far"), &GLTFCamera::get_depth_far);
- ClassDB::bind_method(D_METHOD("set_depth_far", "zdepth_far"), &GLTFCamera::set_depth_far);
- ClassDB::bind_method(D_METHOD("get_depth_near"), &GLTFCamera::get_depth_near);
- ClassDB::bind_method(D_METHOD("set_depth_near", "zdepth_near"), &GLTFCamera::set_depth_near);
-
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "perspective"), "set_perspective", "get_perspective"); // bool
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fov_size"), "set_fov_size", "get_fov_size"); // float
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth_far"), "set_depth_far", "get_depth_far"); // float
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth_near"), "set_depth_near", "get_depth_near"); // float
-}
diff --git a/modules/gltf/gltf_defines.h b/modules/gltf/gltf_defines.h
new file mode 100644
index 0000000000..c20c87f798
--- /dev/null
+++ b/modules/gltf/gltf_defines.h
@@ -0,0 +1,87 @@
+/*************************************************************************/
+/* gltf_defines.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef GLTF_DEFINES_H
+#define GLTF_DEFINES_H
+
+// This file should only be included by other headers.
+
+// Godot classes used by GLTF headers.
+class BoneAttachment3D;
+class CSGShape3D;
+class DirectionalLight3D;
+class GridMap;
+class Light3D;
+class MultiMeshInstance3D;
+class Skeleton3D;
+class Skin;
+
+// GLTF classes.
+struct GLTFAccessor;
+class GLTFAnimation;
+class GLTFBufferView;
+class GLTFCamera;
+class GLTFDocument;
+class GLTFDocumentExtension;
+class GLTFLight;
+class GLTFMesh;
+class GLTFNode;
+class GLTFSkeleton;
+class GLTFSkin;
+class GLTFSpecGloss;
+class GLTFState;
+class GLTFTexture;
+
+// GLTF index aliases.
+using GLTFAccessorIndex = int;
+using GLTFAnimationIndex = int;
+using GLTFBufferIndex = int;
+using GLTFBufferViewIndex = int;
+using GLTFCameraIndex = int;
+using GLTFImageIndex = int;
+using GLTFMaterialIndex = int;
+using GLTFMeshIndex = int;
+using GLTFLightIndex = int;
+using GLTFNodeIndex = int;
+using GLTFSkeletonIndex = int;
+using GLTFSkinIndex = int;
+using GLTFTextureIndex = int;
+
+enum GLTFType {
+ TYPE_SCALAR,
+ TYPE_VEC2,
+ TYPE_VEC3,
+ TYPE_VEC4,
+ TYPE_MAT2,
+ TYPE_MAT3,
+ TYPE_MAT4,
+};
+
+#endif // GLTF_DEFINES_H
diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp
index babdc9f33b..f5730e7137 100644
--- a/modules/gltf/gltf_document.cpp
+++ b/modules/gltf/gltf_document.cpp
@@ -30,19 +30,10 @@
#include "gltf_document.h"
-#include "gltf_accessor.h"
-#include "gltf_animation.h"
-#include "gltf_camera.h"
+#include "extensions/gltf_spec_gloss.h"
#include "gltf_document_extension.h"
#include "gltf_document_extension_convert_importer_mesh.h"
-#include "gltf_light.h"
-#include "gltf_mesh.h"
-#include "gltf_node.h"
-#include "gltf_skeleton.h"
-#include "gltf_skin.h"
-#include "gltf_spec_gloss.h"
#include "gltf_state.h"
-#include "gltf_texture.h"
#include "core/crypto/crypto_core.h"
#include "core/error/error_macros.h"
@@ -59,7 +50,6 @@
#include "core/version.h"
#include "drivers/png/png_driver_common.h"
#include "scene/2d/node_2d.h"
-#include "scene/3d/camera_3d.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/multimesh_instance_3d.h"
#include "scene/3d/node_3d.h"
@@ -230,15 +220,21 @@ Error GLTFDocument::_serialize(Ref<GLTFState> state, const String &p_path) {
}
Error GLTFDocument::_serialize_extensions(Ref<GLTFState> state) const {
- const String texture_transform = "KHR_texture_transform";
- const String punctual_lights = "KHR_lights_punctual";
Array extensions_used;
- extensions_used.push_back(punctual_lights);
- extensions_used.push_back(texture_transform);
- state->json["extensionsUsed"] = extensions_used;
Array extensions_required;
- extensions_required.push_back(texture_transform);
- state->json["extensionsRequired"] = extensions_required;
+ if (!state->lights.is_empty()) {
+ extensions_used.push_back("KHR_lights_punctual");
+ }
+ if (state->use_khr_texture_transform) {
+ extensions_used.push_back("KHR_texture_transform");
+ extensions_required.push_back("KHR_texture_transform");
+ }
+ if (!extensions_used.is_empty()) {
+ state->json["extensionsUsed"] = extensions_used;
+ }
+ if (!extensions_required.is_empty()) {
+ state->json["extensionsRequired"] = extensions_required;
+ }
return OK;
}
@@ -439,7 +435,7 @@ Error GLTFDocument::_serialize_nodes(Ref<GLTFState> state) {
node["scale"] = _vec3_to_arr(n->scale);
}
- if (!n->position.is_equal_approx(Vector3())) {
+ if (!n->position.is_zero_approx()) {
node["translation"] = _vec3_to_arr(n->position);
}
if (n->children.size()) {
@@ -790,7 +786,7 @@ Error GLTFDocument::_parse_buffers(Ref<GLTFState> state, const String &p_base_pa
} else { // Relative path to an external image file.
ERR_FAIL_COND_V(p_base_path.is_empty(), ERR_INVALID_PARAMETER);
uri = uri.uri_decode();
- uri = p_base_path.plus_file(uri).replace("\\", "/"); // Fix for Windows.
+ uri = p_base_path.path_join(uri).replace("\\", "/"); // Fix for Windows.
buffer_data = FileAccess::get_file_as_array(uri);
ERR_FAIL_COND_V_MSG(buffer.size() == 0, ERR_PARSE_ERROR, "glTF: Couldn't load binary file as an array: " + uri);
}
@@ -934,58 +930,58 @@ Error GLTFDocument::_encode_accessors(Ref<GLTFState> state) {
return OK;
}
-String GLTFDocument::_get_accessor_type_name(const GLTFDocument::GLTFType p_type) {
- if (p_type == GLTFDocument::TYPE_SCALAR) {
+String GLTFDocument::_get_accessor_type_name(const GLTFType p_type) {
+ if (p_type == GLTFType::TYPE_SCALAR) {
return "SCALAR";
}
- if (p_type == GLTFDocument::TYPE_VEC2) {
+ if (p_type == GLTFType::TYPE_VEC2) {
return "VEC2";
}
- if (p_type == GLTFDocument::TYPE_VEC3) {
+ if (p_type == GLTFType::TYPE_VEC3) {
return "VEC3";
}
- if (p_type == GLTFDocument::TYPE_VEC4) {
+ if (p_type == GLTFType::TYPE_VEC4) {
return "VEC4";
}
- if (p_type == GLTFDocument::TYPE_MAT2) {
+ if (p_type == GLTFType::TYPE_MAT2) {
return "MAT2";
}
- if (p_type == GLTFDocument::TYPE_MAT3) {
+ if (p_type == GLTFType::TYPE_MAT3) {
return "MAT3";
}
- if (p_type == GLTFDocument::TYPE_MAT4) {
+ if (p_type == GLTFType::TYPE_MAT4) {
return "MAT4";
}
ERR_FAIL_V("SCALAR");
}
-GLTFDocument::GLTFType GLTFDocument::_get_type_from_str(const String &p_string) {
+GLTFType GLTFDocument::_get_type_from_str(const String &p_string) {
if (p_string == "SCALAR") {
- return GLTFDocument::TYPE_SCALAR;
+ return GLTFType::TYPE_SCALAR;
}
if (p_string == "VEC2") {
- return GLTFDocument::TYPE_VEC2;
+ return GLTFType::TYPE_VEC2;
}
if (p_string == "VEC3") {
- return GLTFDocument::TYPE_VEC3;
+ return GLTFType::TYPE_VEC3;
}
if (p_string == "VEC4") {
- return GLTFDocument::TYPE_VEC4;
+ return GLTFType::TYPE_VEC4;
}
if (p_string == "MAT2") {
- return GLTFDocument::TYPE_MAT2;
+ return GLTFType::TYPE_MAT2;
}
if (p_string == "MAT3") {
- return GLTFDocument::TYPE_MAT3;
+ return GLTFType::TYPE_MAT3;
}
if (p_string == "MAT4") {
- return GLTFDocument::TYPE_MAT4;
+ return GLTFType::TYPE_MAT4;
}
- ERR_FAIL_V(GLTFDocument::TYPE_SCALAR);
+ ERR_FAIL_V(GLTFType::TYPE_SCALAR);
}
Error GLTFDocument::_parse_accessors(Ref<GLTFState> state) {
@@ -1536,7 +1532,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_ints(Ref<GLTFState> state, c
accessor.instantiate();
GLTFBufferIndex buffer_view_i;
int64_t size = state->buffers[0].size();
- const GLTFDocument::GLTFType type = GLTFDocument::TYPE_SCALAR;
+ const GLTFType type = GLTFType::TYPE_SCALAR;
const int component_type = GLTFDocument::COMPONENT_TYPE_INT;
accessor->max = type_max;
@@ -1620,7 +1616,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec2(Ref<GLTFState> state, c
accessor.instantiate();
GLTFBufferIndex buffer_view_i;
int64_t size = state->buffers[0].size();
- const GLTFDocument::GLTFType type = GLTFDocument::TYPE_VEC2;
+ const GLTFType type = GLTFType::TYPE_VEC2;
const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT;
accessor->max = type_max;
@@ -1669,7 +1665,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_color(Ref<GLTFState> state,
accessor.instantiate();
GLTFBufferIndex buffer_view_i;
int64_t size = state->buffers[0].size();
- const GLTFDocument::GLTFType type = GLTFDocument::TYPE_VEC4;
+ const GLTFType type = GLTFType::TYPE_VEC4;
const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT;
accessor->max = type_max;
@@ -1734,7 +1730,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_weights(Ref<GLTFState> state
accessor.instantiate();
GLTFBufferIndex buffer_view_i;
int64_t size = state->buffers[0].size();
- const GLTFDocument::GLTFType type = GLTFDocument::TYPE_VEC4;
+ const GLTFType type = GLTFType::TYPE_VEC4;
const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT;
accessor->max = type_max;
@@ -1781,7 +1777,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_joints(Ref<GLTFState> state,
accessor.instantiate();
GLTFBufferIndex buffer_view_i;
int64_t size = state->buffers[0].size();
- const GLTFDocument::GLTFType type = GLTFDocument::TYPE_VEC4;
+ const GLTFType type = GLTFType::TYPE_VEC4;
const int component_type = GLTFDocument::COMPONENT_TYPE_UNSIGNED_SHORT;
accessor->max = type_max;
@@ -1830,7 +1826,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_quaternions(Ref<GLTFState> s
accessor.instantiate();
GLTFBufferIndex buffer_view_i;
int64_t size = state->buffers[0].size();
- const GLTFDocument::GLTFType type = GLTFDocument::TYPE_VEC4;
+ const GLTFType type = GLTFType::TYPE_VEC4;
const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT;
accessor->max = type_max;
@@ -1895,7 +1891,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_floats(Ref<GLTFState> state,
accessor.instantiate();
GLTFBufferIndex buffer_view_i;
int64_t size = state->buffers[0].size();
- const GLTFDocument::GLTFType type = GLTFDocument::TYPE_SCALAR;
+ const GLTFType type = GLTFType::TYPE_SCALAR;
const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT;
accessor->max = type_max;
@@ -1941,7 +1937,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec3(Ref<GLTFState> state, c
accessor.instantiate();
GLTFBufferIndex buffer_view_i;
int64_t size = state->buffers[0].size();
- const GLTFDocument::GLTFType type = GLTFDocument::TYPE_VEC3;
+ const GLTFType type = GLTFType::TYPE_VEC3;
const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT;
accessor->max = type_max;
@@ -2009,7 +2005,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_xform(Ref<GLTFState> state,
accessor.instantiate();
GLTFBufferIndex buffer_view_i;
int64_t size = state->buffers[0].size();
- const GLTFDocument::GLTFType type = GLTFDocument::TYPE_MAT4;
+ const GLTFType type = GLTFType::TYPE_MAT4;
const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT;
accessor->max = type_max;
@@ -2677,7 +2673,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) {
} else if (a.has("JOINTS_0") && a.has("JOINTS_1")) {
PackedInt32Array joints_0 = _decode_accessor_as_ints(state, a["JOINTS_0"], true);
PackedInt32Array joints_1 = _decode_accessor_as_ints(state, a["JOINTS_1"], true);
- ERR_FAIL_COND_V(joints_0.size() != joints_0.size(), ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(joints_0.size() != joints_1.size(), ERR_INVALID_DATA);
int32_t weight_8_count = JOINT_GROUP_SIZE * 2;
Vector<int> joints;
joints.resize(vertex_num * weight_8_count);
@@ -3043,8 +3039,8 @@ Error GLTFDocument::_serialize_images(Ref<GLTFState> state, const String &p_path
if (!da->dir_exists(new_texture_dir)) {
da->make_dir(new_texture_dir);
}
- image->save_png(new_texture_dir.plus_file(name));
- d["uri"] = texture_dir.plus_file(name).uri_encode();
+ image->save_png(new_texture_dir.path_join(name));
+ d["uri"] = texture_dir.path_join(name).uri_encode();
}
images.push_back(d);
}
@@ -3122,7 +3118,7 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_pat
} else { // Relative path to an external image file.
ERR_FAIL_COND_V(p_base_path.is_empty(), ERR_INVALID_PARAMETER);
uri = uri.uri_decode();
- uri = p_base_path.plus_file(uri).replace("\\", "/"); // Fix for Windows.
+ uri = p_base_path.path_join(uri).replace("\\", "/"); // Fix for Windows.
// ResourceLoader will rely on the file extension to use the relevant loader.
// The spec says that if mimeType is defined, it should take precedence (e.g.
// there could be a `.png` image which is actually JPEG), but there's no easy
@@ -3305,7 +3301,11 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
}
if (gltf_texture_index != -1) {
bct["index"] = gltf_texture_index;
- bct["extensions"] = _serialize_texture_transform_uv1(material);
+ Dictionary extensions = _serialize_texture_transform_uv1(material);
+ if (!extensions.is_empty()) {
+ bct["extensions"] = extensions;
+ state->use_khr_texture_transform = true;
+ }
mr["baseColorTexture"] = bct;
}
}
@@ -3436,7 +3436,11 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
}
if (has_roughness || has_metalness) {
mrt["index"] = orm_texture_index;
- mrt["extensions"] = _serialize_texture_transform_uv1(material);
+ Dictionary extensions = _serialize_texture_transform_uv1(material);
+ if (!extensions.is_empty()) {
+ mrt["extensions"] = extensions;
+ state->use_khr_texture_transform = true;
+ }
mr["metallicRoughnessTexture"] = mrt;
}
}
@@ -4525,34 +4529,12 @@ void GLTFDocument::_remove_duplicate_skins(Ref<GLTFState> state) {
}
Error GLTFDocument::_serialize_lights(Ref<GLTFState> state) {
+ if (state->lights.is_empty()) {
+ return OK;
+ }
Array lights;
for (GLTFLightIndex i = 0; i < state->lights.size(); i++) {
- Dictionary d;
- Ref<GLTFLight> light = state->lights[i];
- Array color;
- color.resize(3);
- color[0] = light->color.r;
- color[1] = light->color.g;
- color[2] = light->color.b;
- d["color"] = color;
- d["type"] = light->light_type;
- if (light->light_type == "spot") {
- Dictionary s;
- float inner_cone_angle = light->inner_cone_angle;
- s["innerConeAngle"] = inner_cone_angle;
- float outer_cone_angle = light->outer_cone_angle;
- s["outerConeAngle"] = outer_cone_angle;
- d["spot"] = s;
- }
- float intensity = light->intensity;
- d["intensity"] = intensity;
- float range = light->range;
- d["range"] = range;
- lights.push_back(d);
- }
-
- if (!state->lights.size()) {
- return OK;
+ lights.push_back(state->lights[i]->to_dictionary());
}
Dictionary extensions;
@@ -4574,28 +4556,7 @@ Error GLTFDocument::_serialize_cameras(Ref<GLTFState> state) {
Array cameras;
cameras.resize(state->cameras.size());
for (GLTFCameraIndex i = 0; i < state->cameras.size(); i++) {
- Dictionary d;
-
- Ref<GLTFCamera> camera = state->cameras[i];
-
- if (camera->get_perspective() == false) {
- Dictionary og;
- og["ymag"] = Math::deg2rad(camera->get_fov_size());
- og["xmag"] = Math::deg2rad(camera->get_fov_size());
- og["zfar"] = camera->get_depth_far();
- og["znear"] = camera->get_depth_near();
- d["orthographic"] = og;
- d["type"] = "orthographic";
- } else if (camera->get_perspective()) {
- Dictionary ppt;
- // GLTF spec is in radians, Godot's camera is in degrees.
- ppt["yfov"] = Math::deg2rad(camera->get_fov_size());
- ppt["zfar"] = camera->get_depth_far();
- ppt["znear"] = camera->get_depth_near();
- d["perspective"] = ppt;
- d["type"] = "perspective";
- }
- cameras[i] = d;
+ cameras[i] = state->cameras[i]->to_dictionary();
}
if (!state->cameras.size()) {
@@ -4625,35 +4586,10 @@ Error GLTFDocument::_parse_lights(Ref<GLTFState> state) {
const Array &lights = lights_punctual["lights"];
for (GLTFLightIndex light_i = 0; light_i < lights.size(); light_i++) {
- const Dictionary &d = lights[light_i];
-
- Ref<GLTFLight> light;
- light.instantiate();
- ERR_FAIL_COND_V(!d.has("type"), ERR_PARSE_ERROR);
- const String &type = d["type"];
- light->light_type = type;
-
- if (d.has("color")) {
- const Array &arr = d["color"];
- ERR_FAIL_COND_V(arr.size() != 3, ERR_PARSE_ERROR);
- const Color c = Color(arr[0], arr[1], arr[2]).linear_to_srgb();
- light->color = c;
+ Ref<GLTFLight> light = GLTFLight::from_dictionary(lights[light_i]);
+ if (light.is_null()) {
+ return Error::ERR_PARSE_ERROR;
}
- if (d.has("intensity")) {
- light->intensity = d["intensity"];
- }
- if (d.has("range")) {
- light->range = d["range"];
- }
- if (type == "spot") {
- const Dictionary &spot = d["spot"];
- light->inner_cone_angle = spot["innerConeAngle"];
- light->outer_cone_angle = spot["outerConeAngle"];
- ERR_CONTINUE_MSG(light->inner_cone_angle >= light->outer_cone_angle, "The inner angle must be smaller than the outer angle.");
- } else if (type != "point" && type != "directional") {
- ERR_CONTINUE_MSG(true, "Light type is unknown.");
- }
-
state->lights.push_back(light);
}
@@ -4670,39 +4606,7 @@ Error GLTFDocument::_parse_cameras(Ref<GLTFState> state) {
const Array cameras = state->json["cameras"];
for (GLTFCameraIndex i = 0; i < cameras.size(); i++) {
- const Dictionary &d = cameras[i];
-
- Ref<GLTFCamera> camera;
- camera.instantiate();
- ERR_FAIL_COND_V(!d.has("type"), ERR_PARSE_ERROR);
- const String &type = d["type"];
- if (type == "orthographic") {
- camera->set_perspective(false);
- if (d.has("orthographic")) {
- const Dictionary &og = d["orthographic"];
- // GLTF spec is in radians, Godot's camera is in degrees.
- camera->set_fov_size(Math::rad2deg(real_t(og["ymag"])));
- camera->set_depth_far(og["zfar"]);
- camera->set_depth_near(og["znear"]);
- } else {
- camera->set_fov_size(10);
- }
- } else if (type == "perspective") {
- camera->set_perspective(true);
- if (d.has("perspective")) {
- const Dictionary &ppt = d["perspective"];
- // GLTF spec is in radians, Godot's camera is in degrees.
- camera->set_fov_size(Math::rad2deg(real_t(ppt["yfov"])));
- camera->set_depth_far(ppt["zfar"]);
- camera->set_depth_near(ppt["znear"]);
- } else {
- camera->set_fov_size(10);
- }
- } else {
- ERR_FAIL_V_MSG(ERR_PARSE_ERROR, "Camera3D should be in 'orthographic' or 'perspective'");
- }
-
- state->cameras.push_back(camera);
+ state->cameras.push_back(GLTFCamera::from_dictionary(cameras[i]));
}
print_verbose("glTF: Total cameras: " + itos(state->cameras.size()));
@@ -4934,7 +4838,8 @@ Error GLTFDocument::_parse_animations(Ref<GLTFState> state) {
if (d.has("name")) {
const String name = d["name"];
- if (name.begins_with("loop") || name.ends_with("loop") || name.begins_with("cycle") || name.ends_with("cycle")) {
+ const String name_lower = name.to_lower();
+ if (name_lower.begins_with("loop") || name_lower.ends_with("loop") || name_lower.begins_with("cycle") || name_lower.ends_with("cycle")) {
animation->set_loop(true);
}
animation->set_name(_gen_unique_animation_name(state, name));
@@ -5102,7 +5007,7 @@ GLTFMeshIndex GLTFDocument::_convert_mesh_to_gltf(Ref<GLTFState> state, MeshInst
Ref<GLTFMesh> gltf_mesh;
gltf_mesh.instantiate();
- Array instance_materials;
+ TypedArray<Material> instance_materials;
for (int32_t surface_i = 0; surface_i < current_mesh->get_surface_count(); surface_i++) {
Ref<Material> mat = current_mesh->get_surface_material(surface_i);
if (p_mesh_instance->get_surface_override_material(surface_i).is_valid()) {
@@ -5149,45 +5054,7 @@ Node3D *GLTFDocument::_generate_light(Ref<GLTFState> state, const GLTFNodeIndex
print_verbose("glTF: Creating light for: " + gltf_node->get_name());
Ref<GLTFLight> l = state->lights[gltf_node->light];
-
- float intensity = l->intensity;
- if (intensity > 10) {
- // GLTF spec has the default around 1, but Blender defaults lights to 100.
- // The only sane way to handle this is to check where it came from and
- // handle it accordingly. If it's over 10, it probably came from Blender.
- intensity /= 100;
- }
-
- if (l->light_type == "directional") {
- DirectionalLight3D *light = memnew(DirectionalLight3D);
- light->set_param(Light3D::PARAM_ENERGY, intensity);
- light->set_color(l->color);
- return light;
- }
-
- const float range = CLAMP(l->range, 0, 4096);
- if (l->light_type == "point") {
- OmniLight3D *light = memnew(OmniLight3D);
- light->set_param(OmniLight3D::PARAM_ENERGY, intensity);
- light->set_param(OmniLight3D::PARAM_RANGE, range);
- light->set_color(l->color);
- return light;
- }
- if (l->light_type == "spot") {
- SpotLight3D *light = memnew(SpotLight3D);
- light->set_param(SpotLight3D::PARAM_ENERGY, intensity);
- light->set_param(SpotLight3D::PARAM_RANGE, range);
- light->set_param(SpotLight3D::PARAM_SPOT_ANGLE, Math::rad2deg(l->outer_cone_angle));
- light->set_color(l->color);
-
- // Line of best fit derived from guessing, see https://www.desmos.com/calculator/biiflubp8b
- // The points in desmos are not exact, except for (1, infinity).
- float angle_ratio = l->inner_cone_angle / l->outer_cone_angle;
- float angle_attenuation = 0.2 / (1 - angle_ratio) - 0.1;
- light->set_param(SpotLight3D::PARAM_SPOT_ATTENUATION, angle_attenuation);
- return light;
- }
- return memnew(Node3D);
+ return l->to_node();
}
Camera3D *GLTFDocument::_generate_camera(Ref<GLTFState> state, const GLTFNodeIndex node_index) {
@@ -5195,31 +5062,16 @@ Camera3D *GLTFDocument::_generate_camera(Ref<GLTFState> state, const GLTFNodeInd
ERR_FAIL_INDEX_V(gltf_node->camera, state->cameras.size(), nullptr);
- Camera3D *camera = memnew(Camera3D);
print_verbose("glTF: Creating camera for: " + gltf_node->get_name());
Ref<GLTFCamera> c = state->cameras[gltf_node->camera];
- if (c->get_perspective()) {
- camera->set_perspective(c->get_fov_size(), c->get_depth_near(), c->get_depth_far());
- } else {
- camera->set_orthogonal(c->get_fov_size(), c->get_depth_near(), c->get_depth_far());
- }
-
- return camera;
+ return c->to_node();
}
GLTFCameraIndex GLTFDocument::_convert_camera(Ref<GLTFState> state, Camera3D *p_camera) {
print_verbose("glTF: Converting camera: " + p_camera->get_name());
- Ref<GLTFCamera> c;
- c.instantiate();
-
- if (p_camera->get_projection() == Camera3D::Projection::PROJECTION_PERSPECTIVE) {
- c->set_perspective(true);
- }
- c->set_fov_size(p_camera->get_fov());
- c->set_depth_far(p_camera->get_far());
- c->set_depth_near(p_camera->get_near());
+ Ref<GLTFCamera> c = GLTFCamera::from_node(p_camera);
GLTFCameraIndex camera_index = state->cameras.size();
state->cameras.push_back(c);
return camera_index;
@@ -5228,31 +5080,7 @@ GLTFCameraIndex GLTFDocument::_convert_camera(Ref<GLTFState> state, Camera3D *p_
GLTFLightIndex GLTFDocument::_convert_light(Ref<GLTFState> state, Light3D *p_light) {
print_verbose("glTF: Converting light: " + p_light->get_name());
- Ref<GLTFLight> l;
- l.instantiate();
- l->color = p_light->get_color();
- if (cast_to<DirectionalLight3D>(p_light)) {
- l->light_type = "directional";
- DirectionalLight3D *light = cast_to<DirectionalLight3D>(p_light);
- l->intensity = light->get_param(DirectionalLight3D::PARAM_ENERGY);
- l->range = FLT_MAX; // Range for directional lights is infinite in Godot.
- } else if (cast_to<OmniLight3D>(p_light)) {
- l->light_type = "point";
- OmniLight3D *light = cast_to<OmniLight3D>(p_light);
- l->range = light->get_param(OmniLight3D::PARAM_RANGE);
- l->intensity = light->get_param(OmniLight3D::PARAM_ENERGY);
- } else if (cast_to<SpotLight3D>(p_light)) {
- l->light_type = "spot";
- SpotLight3D *light = cast_to<SpotLight3D>(p_light);
- l->range = light->get_param(SpotLight3D::PARAM_RANGE);
- l->intensity = light->get_param(SpotLight3D::PARAM_ENERGY);
- l->outer_cone_angle = Math::deg2rad(light->get_param(SpotLight3D::PARAM_SPOT_ANGLE));
-
- // This equation is the inverse of the import equation (which has a desmos link).
- float angle_ratio = 1 - (0.2 / (0.1 + light->get_param(SpotLight3D::PARAM_SPOT_ATTENUATION)));
- angle_ratio = MAX(0, angle_ratio);
- l->inner_cone_angle = l->outer_cone_angle * angle_ratio;
- }
+ Ref<GLTFLight> l = GLTFLight::from_node(p_light);
GLTFLightIndex light_index = state->lights.size();
state->lights.push_back(l);
@@ -5437,13 +5265,13 @@ void GLTFDocument::_convert_grid_map_to_gltf(GridMap *p_grid_map, GLTFNodeIndex
int32_t cell = p_grid_map->get_cell_item(
Vector3(cell_location.x, cell_location.y, cell_location.z));
Transform3D cell_xform;
- cell_xform.basis.set_orthogonal_index(
+ cell_xform.basis = p_grid_map->get_basis_with_orthogonal_index(
p_grid_map->get_cell_item_orientation(
Vector3(cell_location.x, cell_location.y, cell_location.z)));
cell_xform.basis.scale(Vector3(p_grid_map->get_cell_scale(),
p_grid_map->get_cell_scale(),
p_grid_map->get_cell_scale()));
- cell_xform.set_origin(p_grid_map->map_to_world(
+ cell_xform.set_origin(p_grid_map->map_to_local(
Vector3(cell_location.x, cell_location.y, cell_location.z)));
Ref<GLTFMesh> gltf_mesh;
gltf_mesh.instantiate();
@@ -6651,45 +6479,48 @@ Error GLTFDocument::_parse(Ref<GLTFState> state, String p_path, Ref<FileAccess>
return OK;
}
-Dictionary GLTFDocument::_serialize_texture_transform_uv2(Ref<BaseMaterial3D> p_material) {
- Dictionary extension;
- Ref<BaseMaterial3D> mat = p_material;
- if (mat.is_valid()) {
- Dictionary texture_transform;
+Dictionary _serialize_texture_transform_uv(Vector2 p_offset, Vector2 p_scale) {
+ Dictionary texture_transform;
+ bool is_offset = p_offset != Vector2(0.0, 0.0);
+ if (is_offset) {
Array offset;
offset.resize(2);
- offset[0] = mat->get_uv2_offset().x;
- offset[1] = mat->get_uv2_offset().y;
+ offset[0] = p_offset.x;
+ offset[1] = p_offset.y;
texture_transform["offset"] = offset;
+ }
+ bool is_scaled = p_scale != Vector2(1.0, 1.0);
+ if (is_scaled) {
Array scale;
scale.resize(2);
- scale[0] = mat->get_uv2_scale().x;
- scale[1] = mat->get_uv2_scale().y;
+ scale[0] = p_scale.x;
+ scale[1] = p_scale.y;
texture_transform["scale"] = scale;
- // Godot doesn't support texture rotation
+ }
+ Dictionary extension;
+ // Note: Godot doesn't support texture rotation.
+ if (is_offset || is_scaled) {
extension["KHR_texture_transform"] = texture_transform;
}
return extension;
}
Dictionary GLTFDocument::_serialize_texture_transform_uv1(Ref<BaseMaterial3D> p_material) {
- Dictionary extension;
if (p_material.is_valid()) {
- Dictionary texture_transform;
- Array offset;
- offset.resize(2);
- offset[0] = p_material->get_uv1_offset().x;
- offset[1] = p_material->get_uv1_offset().y;
- texture_transform["offset"] = offset;
- Array scale;
- scale.resize(2);
- scale[0] = p_material->get_uv1_scale().x;
- scale[1] = p_material->get_uv1_scale().y;
- texture_transform["scale"] = scale;
- // Godot doesn't support texture rotation
- extension["KHR_texture_transform"] = texture_transform;
+ Vector3 offset = p_material->get_uv1_offset();
+ Vector3 scale = p_material->get_uv1_scale();
+ return _serialize_texture_transform_uv(Vector2(offset.x, offset.y), Vector2(scale.x, scale.y));
}
- return extension;
+ return Dictionary();
+}
+
+Dictionary GLTFDocument::_serialize_texture_transform_uv2(Ref<BaseMaterial3D> p_material) {
+ if (p_material.is_valid()) {
+ Vector3 offset = p_material->get_uv2_offset();
+ Vector3 scale = p_material->get_uv2_scale();
+ return _serialize_texture_transform_uv(Vector2(offset.x, offset.y), Vector2(scale.x, scale.y));
+ }
+ return Dictionary();
}
Error GLTFDocument::_serialize_version(Ref<GLTFState> state) {
@@ -6891,7 +6722,7 @@ Node *GLTFDocument::generate_scene(Ref<GLTFState> state, int32_t p_bake_fps) {
Node *root = gltf_root_node->get_parent();
ERR_FAIL_NULL_V(root, nullptr);
_process_mesh_instances(state, root);
- if (state->animations.size()) {
+ if (state->get_create_animations() && state->animations.size()) {
AnimationPlayer *ap = memnew(AnimationPlayer);
root->add_child(ap, true);
ap->set_owner(root);
@@ -6929,15 +6760,6 @@ Error GLTFDocument::append_from_scene(Node *p_node, Ref<GLTFState> state, uint32
state->use_named_skin_binds = p_flags & GLTF_IMPORT_USE_NAMED_SKIN_BINDS;
state->discard_meshes_and_materials = p_flags & GLTF_IMPORT_DISCARD_MESHES_AND_MATERIALS;
- _convert_scene_node(state, p_node, -1, -1);
- if (!state->buffers.size()) {
- state->buffers.push_back(Vector<uint8_t>());
- }
- for (int32_t ext_i = 0; ext_i < document_extensions.size(); ext_i++) {
- Ref<GLTFDocumentExtension> ext = document_extensions[ext_i];
- ERR_CONTINUE(ext.is_null());
- }
-
for (int32_t ext_i = 0; ext_i < document_extensions.size(); ext_i++) {
Ref<GLTFDocumentExtension> ext = document_extensions[ext_i];
ERR_CONTINUE(ext.is_null());
@@ -6948,7 +6770,6 @@ Error GLTFDocument::append_from_scene(Node *p_node, Ref<GLTFState> state, uint32
if (!state->buffers.size()) {
state->buffers.push_back(Vector<uint8_t>());
}
-
return OK;
}
diff --git a/modules/gltf/gltf_document.h b/modules/gltf/gltf_document.h
index 2f61210ff9..36a2f94a4e 100644
--- a/modules/gltf/gltf_document.h
+++ b/modules/gltf/gltf_document.h
@@ -31,48 +31,19 @@
#ifndef GLTF_DOCUMENT_H
#define GLTF_DOCUMENT_H
-#include "gltf_animation.h"
+#include "gltf_defines.h"
+#include "structures/gltf_animation.h"
#include "scene/3d/bone_attachment_3d.h"
#include "scene/3d/importer_mesh_instance_3d.h"
-#include "scene/3d/light_3d.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/animation/animation_player.h"
#include "scene/resources/material.h"
#include "modules/modules_enabled.gen.h" // For csg, gridmap.
-#include <cstdint>
-
-class GLTFState;
-class GLTFSkin;
-class GLTFNode;
-class GLTFSpecGloss;
-class GLTFSkeleton;
-class CSGShape3D;
-class GridMap;
-class MultiMeshInstance3D;
-class GLTFDocumentExtension;
-
-using GLTFAccessorIndex = int;
-using GLTFAnimationIndex = int;
-using GLTFBufferIndex = int;
-using GLTFBufferViewIndex = int;
-using GLTFCameraIndex = int;
-using GLTFImageIndex = int;
-using GLTFMaterialIndex = int;
-using GLTFMeshIndex = int;
-using GLTFLightIndex = int;
-using GLTFNodeIndex = int;
-using GLTFSkeletonIndex = int;
-using GLTFSkinIndex = int;
-using GLTFTextureIndex = int;
-
class GLTFDocument : public Resource {
GDCLASS(GLTFDocument, Resource);
- friend class GLTFState;
- friend class GLTFSkin;
- friend class GLTFSkeleton;
TypedArray<GLTFDocumentExtension> document_extensions;
private:
@@ -81,15 +52,6 @@ private:
public:
GLTFDocument();
const int32_t JOINT_GROUP_SIZE = 4;
- enum GLTFType {
- TYPE_SCALAR,
- TYPE_VEC2,
- TYPE_VEC3,
- TYPE_VEC4,
- TYPE_MAT2,
- TYPE_MAT3,
- TYPE_MAT4,
- };
enum {
ARRAY_BUFFER = 34962,
@@ -118,58 +80,6 @@ public:
TypedArray<GLTFDocumentExtension> get_extensions() const;
private:
- template <class T>
- static Array to_array(const Vector<T> &p_inp) {
- Array ret;
- for (int i = 0; i < p_inp.size(); i++) {
- ret.push_back(p_inp[i]);
- }
- return ret;
- }
-
- template <class T>
- static Array to_array(const HashSet<T> &p_inp) {
- Array ret;
- typename HashSet<T>::Iterator elem = p_inp.begin();
- while (elem) {
- ret.push_back(*elem);
- ++elem;
- }
- return ret;
- }
-
- template <class T>
- static void set_from_array(Vector<T> &r_out, const Array &p_inp) {
- r_out.clear();
- for (int i = 0; i < p_inp.size(); i++) {
- r_out.push_back(p_inp[i]);
- }
- }
-
- template <class T>
- static void set_from_array(HashSet<T> &r_out, const Array &p_inp) {
- r_out.clear();
- for (int i = 0; i < p_inp.size(); i++) {
- r_out.insert(p_inp[i]);
- }
- }
- template <class K, class V>
- static Dictionary to_dict(const HashMap<K, V> &p_inp) {
- Dictionary ret;
- for (const KeyValue<K, V> &E : p_inp) {
- ret[E.key] = E.value;
- }
- return ret;
- }
-
- template <class K, class V>
- static void set_from_dict(HashMap<K, V> &r_out, const Dictionary &p_inp) {
- r_out.clear();
- Array keys = p_inp.keys();
- for (int i = 0; i < keys.size(); i++) {
- r_out[keys[i]] = p_inp[keys[i]];
- }
- }
void _build_parent_hierachy(Ref<GLTFState> state);
double _filter_number(double p_float);
String _get_component_type_name(const uint32_t p_component);
@@ -177,7 +87,7 @@ private:
Error _parse_scenes(Ref<GLTFState> state);
Error _parse_nodes(Ref<GLTFState> state);
String _get_type_name(const GLTFType p_component);
- String _get_accessor_type_name(const GLTFDocument::GLTFType p_type);
+ String _get_accessor_type_name(const GLTFType p_type);
String _gen_unique_name(Ref<GLTFState> state, const String &p_name);
String _sanitize_animation_name(const String &name);
String _gen_unique_animation_name(Ref<GLTFState> state, const String &p_name);
diff --git a/modules/gltf/gltf_document_extension.h b/modules/gltf/gltf_document_extension.h
index 556f79e887..0ef9109584 100644
--- a/modules/gltf/gltf_document_extension.h
+++ b/modules/gltf/gltf_document_extension.h
@@ -31,9 +31,8 @@
#ifndef GLTF_DOCUMENT_EXTENSION_H
#define GLTF_DOCUMENT_EXTENSION_H
-#include "gltf_accessor.h"
-#include "gltf_node.h"
#include "gltf_state.h"
+#include "structures/gltf_node.h"
class GLTFDocumentExtension : public Resource {
GDCLASS(GLTFDocumentExtension, Resource);
diff --git a/modules/gltf/gltf_document_extension_convert_importer_mesh.h b/modules/gltf/gltf_document_extension_convert_importer_mesh.h
index 4c9e42a00f..00e664e73f 100644
--- a/modules/gltf/gltf_document_extension_convert_importer_mesh.h
+++ b/modules/gltf/gltf_document_extension_convert_importer_mesh.h
@@ -28,8 +28,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef GLTF_EXTENSION_EDITOR_H
-#define GLTF_EXTENSION_EDITOR_H
+#ifndef GLTF_DOCUMENT_EXTENSION_CONVERT_IMPORTER_MESH_H
+#define GLTF_DOCUMENT_EXTENSION_CONVERT_IMPORTER_MESH_H
#include "gltf_document_extension.h"
@@ -37,8 +37,6 @@
#include "scene/3d/mesh_instance_3d.h"
#include "scene/resources/importer_mesh.h"
-class GLTFDocumentExtension;
-class GLTFDocument;
class GLTFDocumentExtensionConvertImporterMesh : public GLTFDocumentExtension {
GDCLASS(GLTFDocumentExtensionConvertImporterMesh, GLTFDocumentExtension);
@@ -48,4 +46,5 @@ protected:
public:
Error import_post(Ref<GLTFState> p_state, Node *p_root) override;
};
-#endif // GLTF_EXTENSION_EDITOR_H
+
+#endif // GLTF_DOCUMENT_EXTENSION_CONVERT_IMPORTER_MESH_H
diff --git a/modules/gltf/gltf_state.cpp b/modules/gltf/gltf_state.cpp
index 989fa476c2..85bac446cc 100644
--- a/modules/gltf/gltf_state.cpp
+++ b/modules/gltf/gltf_state.cpp
@@ -79,6 +79,8 @@ void GLTFState::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_skeletons", "skeletons"), &GLTFState::set_skeletons);
ClassDB::bind_method(D_METHOD("get_skeleton_to_node"), &GLTFState::get_skeleton_to_node);
ClassDB::bind_method(D_METHOD("set_skeleton_to_node", "skeleton_to_node"), &GLTFState::set_skeleton_to_node);
+ ClassDB::bind_method(D_METHOD("get_create_animations"), &GLTFState::get_create_animations);
+ ClassDB::bind_method(D_METHOD("set_create_animations", "create_animations"), &GLTFState::set_create_animations);
ClassDB::bind_method(D_METHOD("get_animations"), &GLTFState::get_animations);
ClassDB::bind_method(D_METHOD("set_animations", "animations"), &GLTFState::set_animations);
ClassDB::bind_method(D_METHOD("get_scene_node", "idx"), &GLTFState::get_scene_node);
@@ -106,6 +108,7 @@ void GLTFState::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "unique_animation_names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_unique_animation_names", "get_unique_animation_names"); // Set<String>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "skeletons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skeletons", "get_skeletons"); // Vector<Ref<GLTFSkeleton>>
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "skeleton_to_node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skeleton_to_node", "get_skeleton_to_node"); // RBMap<GLTFSkeletonIndex,
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "create_animations"), "set_create_animations", "get_create_animations"); // bool
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "animations", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_animations", "get_animations"); // Vector<Ref<GLTFAnimation>>
}
@@ -149,52 +152,52 @@ void GLTFState::set_use_named_skin_binds(bool p_use_named_skin_binds) {
use_named_skin_binds = p_use_named_skin_binds;
}
-Array GLTFState::get_nodes() {
- return GLTFDocument::to_array(nodes);
+TypedArray<GLTFNode> GLTFState::get_nodes() {
+ return GLTFTemplateConvert::to_array(nodes);
}
-void GLTFState::set_nodes(Array p_nodes) {
- GLTFDocument::set_from_array(nodes, p_nodes);
+void GLTFState::set_nodes(TypedArray<GLTFNode> p_nodes) {
+ GLTFTemplateConvert::set_from_array(nodes, p_nodes);
}
-Array GLTFState::get_buffers() {
- return GLTFDocument::to_array(buffers);
+TypedArray<PackedByteArray> GLTFState::get_buffers() {
+ return GLTFTemplateConvert::to_array(buffers);
}
-void GLTFState::set_buffers(Array p_buffers) {
- GLTFDocument::set_from_array(buffers, p_buffers);
+void GLTFState::set_buffers(TypedArray<PackedByteArray> p_buffers) {
+ GLTFTemplateConvert::set_from_array(buffers, p_buffers);
}
-Array GLTFState::get_buffer_views() {
- return GLTFDocument::to_array(buffer_views);
+TypedArray<GLTFBufferView> GLTFState::get_buffer_views() {
+ return GLTFTemplateConvert::to_array(buffer_views);
}
-void GLTFState::set_buffer_views(Array p_buffer_views) {
- GLTFDocument::set_from_array(buffer_views, p_buffer_views);
+void GLTFState::set_buffer_views(TypedArray<GLTFBufferView> p_buffer_views) {
+ GLTFTemplateConvert::set_from_array(buffer_views, p_buffer_views);
}
-Array GLTFState::get_accessors() {
- return GLTFDocument::to_array(accessors);
+TypedArray<GLTFAccessor> GLTFState::get_accessors() {
+ return GLTFTemplateConvert::to_array(accessors);
}
-void GLTFState::set_accessors(Array p_accessors) {
- GLTFDocument::set_from_array(accessors, p_accessors);
+void GLTFState::set_accessors(TypedArray<GLTFAccessor> p_accessors) {
+ GLTFTemplateConvert::set_from_array(accessors, p_accessors);
}
-Array GLTFState::get_meshes() {
- return GLTFDocument::to_array(meshes);
+TypedArray<GLTFMesh> GLTFState::get_meshes() {
+ return GLTFTemplateConvert::to_array(meshes);
}
-void GLTFState::set_meshes(Array p_meshes) {
- GLTFDocument::set_from_array(meshes, p_meshes);
+void GLTFState::set_meshes(TypedArray<GLTFMesh> p_meshes) {
+ GLTFTemplateConvert::set_from_array(meshes, p_meshes);
}
-Array GLTFState::get_materials() {
- return GLTFDocument::to_array(materials);
+TypedArray<BaseMaterial3D> GLTFState::get_materials() {
+ return GLTFTemplateConvert::to_array(materials);
}
-void GLTFState::set_materials(Array p_materials) {
- GLTFDocument::set_from_array(materials, p_materials);
+void GLTFState::set_materials(TypedArray<BaseMaterial3D> p_materials) {
+ GLTFTemplateConvert::set_from_array(materials, p_materials);
}
String GLTFState::get_scene_name() {
@@ -205,92 +208,100 @@ void GLTFState::set_scene_name(String p_scene_name) {
scene_name = p_scene_name;
}
-Array GLTFState::get_root_nodes() {
- return GLTFDocument::to_array(root_nodes);
+PackedInt32Array GLTFState::get_root_nodes() {
+ return root_nodes;
}
-void GLTFState::set_root_nodes(Array p_root_nodes) {
- GLTFDocument::set_from_array(root_nodes, p_root_nodes);
+void GLTFState::set_root_nodes(PackedInt32Array p_root_nodes) {
+ root_nodes = p_root_nodes;
}
-Array GLTFState::get_textures() {
- return GLTFDocument::to_array(textures);
+TypedArray<GLTFTexture> GLTFState::get_textures() {
+ return GLTFTemplateConvert::to_array(textures);
}
-void GLTFState::set_textures(Array p_textures) {
- GLTFDocument::set_from_array(textures, p_textures);
+void GLTFState::set_textures(TypedArray<GLTFTexture> p_textures) {
+ GLTFTemplateConvert::set_from_array(textures, p_textures);
}
-Array GLTFState::get_images() {
- return GLTFDocument::to_array(images);
+TypedArray<Texture2D> GLTFState::get_images() {
+ return GLTFTemplateConvert::to_array(images);
}
-void GLTFState::set_images(Array p_images) {
- GLTFDocument::set_from_array(images, p_images);
+void GLTFState::set_images(TypedArray<Texture2D> p_images) {
+ GLTFTemplateConvert::set_from_array(images, p_images);
}
-Array GLTFState::get_skins() {
- return GLTFDocument::to_array(skins);
+TypedArray<GLTFSkin> GLTFState::get_skins() {
+ return GLTFTemplateConvert::to_array(skins);
}
-void GLTFState::set_skins(Array p_skins) {
- GLTFDocument::set_from_array(skins, p_skins);
+void GLTFState::set_skins(TypedArray<GLTFSkin> p_skins) {
+ GLTFTemplateConvert::set_from_array(skins, p_skins);
}
-Array GLTFState::get_cameras() {
- return GLTFDocument::to_array(cameras);
+TypedArray<GLTFCamera> GLTFState::get_cameras() {
+ return GLTFTemplateConvert::to_array(cameras);
}
-void GLTFState::set_cameras(Array p_cameras) {
- GLTFDocument::set_from_array(cameras, p_cameras);
+void GLTFState::set_cameras(TypedArray<GLTFCamera> p_cameras) {
+ GLTFTemplateConvert::set_from_array(cameras, p_cameras);
}
-Array GLTFState::get_lights() {
- return GLTFDocument::to_array(lights);
+TypedArray<GLTFLight> GLTFState::get_lights() {
+ return GLTFTemplateConvert::to_array(lights);
}
-void GLTFState::set_lights(Array p_lights) {
- GLTFDocument::set_from_array(lights, p_lights);
+void GLTFState::set_lights(TypedArray<GLTFLight> p_lights) {
+ GLTFTemplateConvert::set_from_array(lights, p_lights);
}
-Array GLTFState::get_unique_names() {
- return GLTFDocument::to_array(unique_names);
+TypedArray<String> GLTFState::get_unique_names() {
+ return GLTFTemplateConvert::to_array(unique_names);
}
-void GLTFState::set_unique_names(Array p_unique_names) {
- GLTFDocument::set_from_array(unique_names, p_unique_names);
+void GLTFState::set_unique_names(TypedArray<String> p_unique_names) {
+ GLTFTemplateConvert::set_from_array(unique_names, p_unique_names);
}
-Array GLTFState::get_unique_animation_names() {
- return GLTFDocument::to_array(unique_animation_names);
+TypedArray<String> GLTFState::get_unique_animation_names() {
+ return GLTFTemplateConvert::to_array(unique_animation_names);
}
-void GLTFState::set_unique_animation_names(Array p_unique_animation_names) {
- GLTFDocument::set_from_array(unique_animation_names, p_unique_animation_names);
+void GLTFState::set_unique_animation_names(TypedArray<String> p_unique_animation_names) {
+ GLTFTemplateConvert::set_from_array(unique_animation_names, p_unique_animation_names);
}
-Array GLTFState::get_skeletons() {
- return GLTFDocument::to_array(skeletons);
+TypedArray<GLTFSkeleton> GLTFState::get_skeletons() {
+ return GLTFTemplateConvert::to_array(skeletons);
}
-void GLTFState::set_skeletons(Array p_skeletons) {
- GLTFDocument::set_from_array(skeletons, p_skeletons);
+void GLTFState::set_skeletons(TypedArray<GLTFSkeleton> p_skeletons) {
+ GLTFTemplateConvert::set_from_array(skeletons, p_skeletons);
}
Dictionary GLTFState::get_skeleton_to_node() {
- return GLTFDocument::to_dict(skeleton_to_node);
+ return GLTFTemplateConvert::to_dict(skeleton_to_node);
}
void GLTFState::set_skeleton_to_node(Dictionary p_skeleton_to_node) {
- GLTFDocument::set_from_dict(skeleton_to_node, p_skeleton_to_node);
+ GLTFTemplateConvert::set_from_dict(skeleton_to_node, p_skeleton_to_node);
}
-Array GLTFState::get_animations() {
- return GLTFDocument::to_array(animations);
+bool GLTFState::get_create_animations() {
+ return create_animations;
}
-void GLTFState::set_animations(Array p_animations) {
- GLTFDocument::set_from_array(animations, p_animations);
+void GLTFState::set_create_animations(bool p_create_animations) {
+ create_animations = p_create_animations;
+}
+
+TypedArray<GLTFAnimation> GLTFState::get_animations() {
+ return GLTFTemplateConvert::to_array(animations);
+}
+
+void GLTFState::set_animations(TypedArray<GLTFAnimation> p_animations) {
+ GLTFTemplateConvert::set_from_array(animations, p_animations);
}
Node *GLTFState::get_scene_node(GLTFNodeIndex idx) {
diff --git a/modules/gltf/gltf_state.h b/modules/gltf/gltf_state.h
index 2fdef19038..6b2d1ca228 100644
--- a/modules/gltf/gltf_state.h
+++ b/modules/gltf/gltf_state.h
@@ -31,18 +31,17 @@
#ifndef GLTF_STATE_H
#define GLTF_STATE_H
-#include "gltf_accessor.h"
-#include "gltf_animation.h"
-#include "gltf_buffer_view.h"
-#include "gltf_camera.h"
-#include "gltf_document.h"
-#include "gltf_document_extension.h"
-#include "gltf_light.h"
-#include "gltf_mesh.h"
-#include "gltf_node.h"
-#include "gltf_skeleton.h"
-#include "gltf_skin.h"
-#include "gltf_texture.h"
+#include "extensions/gltf_light.h"
+#include "gltf_template_convert.h"
+#include "structures/gltf_accessor.h"
+#include "structures/gltf_animation.h"
+#include "structures/gltf_buffer_view.h"
+#include "structures/gltf_camera.h"
+#include "structures/gltf_mesh.h"
+#include "structures/gltf_node.h"
+#include "structures/gltf_skeleton.h"
+#include "structures/gltf_skin.h"
+#include "structures/gltf_texture.h"
#include "core/templates/rb_map.h"
#include "scene/animation/animation_player.h"
@@ -60,7 +59,9 @@ class GLTFState : public Resource {
Vector<uint8_t> glb_data;
bool use_named_skin_binds = false;
+ bool use_khr_texture_transform = false;
bool discard_meshes_and_materials = false;
+ bool create_animations = true;
Vector<Ref<GLTFNode>> nodes;
Vector<Vector<uint8_t>> buffers;
@@ -114,23 +115,23 @@ public:
bool get_discard_meshes_and_materials();
void set_discard_meshes_and_materials(bool p_discard_meshes_and_materials);
- Array get_nodes();
- void set_nodes(Array p_nodes);
+ TypedArray<GLTFNode> get_nodes();
+ void set_nodes(TypedArray<GLTFNode> p_nodes);
- Array get_buffers();
- void set_buffers(Array p_buffers);
+ TypedArray<PackedByteArray> get_buffers();
+ void set_buffers(TypedArray<PackedByteArray> p_buffers);
- Array get_buffer_views();
- void set_buffer_views(Array p_buffer_views);
+ TypedArray<GLTFBufferView> get_buffer_views();
+ void set_buffer_views(TypedArray<GLTFBufferView> p_buffer_views);
- Array get_accessors();
- void set_accessors(Array p_accessors);
+ TypedArray<GLTFAccessor> get_accessors();
+ void set_accessors(TypedArray<GLTFAccessor> p_accessors);
- Array get_meshes();
- void set_meshes(Array p_meshes);
+ TypedArray<GLTFMesh> get_meshes();
+ void set_meshes(TypedArray<GLTFMesh> p_meshes);
- Array get_materials();
- void set_materials(Array p_materials);
+ TypedArray<BaseMaterial3D> get_materials();
+ void set_materials(TypedArray<BaseMaterial3D> p_materials);
String get_scene_name();
void set_scene_name(String p_scene_name);
@@ -138,38 +139,41 @@ public:
String get_base_path();
void set_base_path(String p_base_path);
- Array get_root_nodes();
- void set_root_nodes(Array p_root_nodes);
+ PackedInt32Array get_root_nodes();
+ void set_root_nodes(PackedInt32Array p_root_nodes);
- Array get_textures();
- void set_textures(Array p_textures);
+ TypedArray<GLTFTexture> get_textures();
+ void set_textures(TypedArray<GLTFTexture> p_textures);
- Array get_images();
- void set_images(Array p_images);
+ TypedArray<Texture2D> get_images();
+ void set_images(TypedArray<Texture2D> p_images);
- Array get_skins();
- void set_skins(Array p_skins);
+ TypedArray<GLTFSkin> get_skins();
+ void set_skins(TypedArray<GLTFSkin> p_skins);
- Array get_cameras();
- void set_cameras(Array p_cameras);
+ TypedArray<GLTFCamera> get_cameras();
+ void set_cameras(TypedArray<GLTFCamera> p_cameras);
- Array get_lights();
- void set_lights(Array p_lights);
+ TypedArray<GLTFLight> get_lights();
+ void set_lights(TypedArray<GLTFLight> p_lights);
- Array get_unique_names();
- void set_unique_names(Array p_unique_names);
+ TypedArray<String> get_unique_names();
+ void set_unique_names(TypedArray<String> p_unique_names);
- Array get_unique_animation_names();
- void set_unique_animation_names(Array p_unique_names);
+ TypedArray<String> get_unique_animation_names();
+ void set_unique_animation_names(TypedArray<String> p_unique_names);
- Array get_skeletons();
- void set_skeletons(Array p_skeletons);
+ TypedArray<GLTFSkeleton> get_skeletons();
+ void set_skeletons(TypedArray<GLTFSkeleton> p_skeletons);
Dictionary get_skeleton_to_node();
void set_skeleton_to_node(Dictionary p_skeleton_to_node);
- Array get_animations();
- void set_animations(Array p_animations);
+ bool get_create_animations();
+ void set_create_animations(bool p_create_animations);
+
+ TypedArray<GLTFAnimation> get_animations();
+ void set_animations(TypedArray<GLTFAnimation> p_animations);
Node *get_scene_node(GLTFNodeIndex idx);
@@ -192,4 +196,5 @@ public:
// this->material_cache = p_material_cache;
//}
};
+
#endif // GLTF_STATE_H
diff --git a/modules/gltf/gltf_template_convert.h b/modules/gltf/gltf_template_convert.h
new file mode 100644
index 0000000000..8a4b595c9f
--- /dev/null
+++ b/modules/gltf/gltf_template_convert.h
@@ -0,0 +1,94 @@
+/*************************************************************************/
+/* gltf_template_convert.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef GLTF_TEMPLATE_CONVERT_H
+#define GLTF_TEMPLATE_CONVERT_H
+
+#include "core/templates/hash_set.h"
+#include "core/variant/array.h"
+#include "core/variant/dictionary.h"
+
+namespace GLTFTemplateConvert {
+template <class T>
+static Array to_array(const Vector<T> &p_inp) {
+ Array ret;
+ for (int i = 0; i < p_inp.size(); i++) {
+ ret.push_back(p_inp[i]);
+ }
+ return ret;
+}
+
+template <class T>
+static TypedArray<T> to_array(const HashSet<T> &p_inp) {
+ TypedArray<T> ret;
+ typename HashSet<T>::Iterator elem = p_inp.begin();
+ while (elem) {
+ ret.push_back(*elem);
+ ++elem;
+ }
+ return ret;
+}
+
+template <class T>
+static void set_from_array(Vector<T> &r_out, const Array &p_inp) {
+ r_out.clear();
+ for (int i = 0; i < p_inp.size(); i++) {
+ r_out.push_back(p_inp[i]);
+ }
+}
+
+template <class T>
+static void set_from_array(HashSet<T> &r_out, const TypedArray<T> &p_inp) {
+ r_out.clear();
+ for (int i = 0; i < p_inp.size(); i++) {
+ r_out.insert(p_inp[i]);
+ }
+}
+
+template <class K, class V>
+static Dictionary to_dict(const HashMap<K, V> &p_inp) {
+ Dictionary ret;
+ for (const KeyValue<K, V> &E : p_inp) {
+ ret[E.key] = E.value;
+ }
+ return ret;
+}
+
+template <class K, class V>
+static void set_from_dict(HashMap<K, V> &r_out, const Dictionary &p_inp) {
+ r_out.clear();
+ Array keys = p_inp.keys();
+ for (int i = 0; i < keys.size(); i++) {
+ r_out[keys[i]] = p_inp[keys[i]];
+ }
+}
+} //namespace GLTFTemplateConvert
+
+#endif // GLTF_TEMPLATE_CONVERT_H
diff --git a/modules/gltf/register_types.cpp b/modules/gltf/register_types.cpp
index b8bac79584..6e7f7d6fed 100644
--- a/modules/gltf/register_types.cpp
+++ b/modules/gltf/register_types.cpp
@@ -32,21 +32,21 @@
#ifndef _3D_DISABLED
-#include "gltf_accessor.h"
-#include "gltf_animation.h"
-#include "gltf_buffer_view.h"
-#include "gltf_camera.h"
+#include "extensions/gltf_light.h"
+#include "extensions/gltf_spec_gloss.h"
#include "gltf_document.h"
#include "gltf_document_extension.h"
#include "gltf_document_extension_convert_importer_mesh.h"
-#include "gltf_light.h"
-#include "gltf_mesh.h"
-#include "gltf_node.h"
-#include "gltf_skeleton.h"
-#include "gltf_skin.h"
-#include "gltf_spec_gloss.h"
#include "gltf_state.h"
-#include "gltf_texture.h"
+#include "structures/gltf_accessor.h"
+#include "structures/gltf_animation.h"
+#include "structures/gltf_buffer_view.h"
+#include "structures/gltf_camera.h"
+#include "structures/gltf_mesh.h"
+#include "structures/gltf_node.h"
+#include "structures/gltf_skeleton.h"
+#include "structures/gltf_skin.h"
+#include "structures/gltf_texture.h"
#ifdef TOOLS_ENABLED
#include "core/config/project_settings.h"
@@ -66,17 +66,24 @@ static void _editor_init() {
bool blend_enabled = GLOBAL_GET("filesystem/import/blender/enabled");
// Defined here because EditorSettings doesn't exist in `register_gltf_types` yet.
- EDITOR_DEF_RST("filesystem/import/blender/blender3_path", "");
+ String blender3_path = EDITOR_DEF_RST("filesystem/import/blender/blender3_path", "");
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,
"filesystem/import/blender/blender3_path", PROPERTY_HINT_GLOBAL_DIR));
if (blend_enabled) {
- Ref<EditorSceneFormatImporterBlend> importer;
- importer.instantiate();
- ResourceImporterScene::add_importer(importer);
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ if (blender3_path.is_empty()) {
+ WARN_PRINT("Blend file import is enabled in the project settings, but no Blender path is configured in the editor settings. Blend files will not be imported.");
+ } else if (!da->dir_exists(blender3_path)) {
+ WARN_PRINT("Blend file import is enabled, but the Blender path doesn't point to an accessible directory. Blend files will not be imported.");
+ } else {
+ Ref<EditorSceneFormatImporterBlend> importer;
+ importer.instantiate();
+ ResourceImporterScene::add_importer(importer);
- Ref<EditorFileSystemImportFormatSupportQueryBlend> blend_import_query;
- blend_import_query.instantiate();
- EditorFileSystem::get_singleton()->add_import_format_support_query(blend_import_query);
+ Ref<EditorFileSystemImportFormatSupportQueryBlend> blend_import_query;
+ blend_import_query.instantiate();
+ EditorFileSystem::get_singleton()->add_import_format_support_query(blend_import_query);
+ }
}
// FBX to glTF importer.
@@ -89,9 +96,9 @@ static void _editor_init() {
if (fbx_enabled) {
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
if (fbx2gltf_path.is_empty()) {
- WARN_PRINT("FBX file import is enabled, but no FBX2glTF path is configured. FBX files will not be imported.");
+ WARN_PRINT("FBX file import is enabled in the project settings, but no FBX2glTF path is configured in the editor settings. FBX files will not be imported.");
} else if (!da->file_exists(fbx2gltf_path)) {
- WARN_PRINT("FBX file import is enabled, but the FBX2glTF path doesn't point to a valid FBX2glTF executable. FBX files will not be imported.");
+ WARN_PRINT("FBX file import is enabled, but the FBX2glTF path doesn't point to an accessible file. FBX files will not be imported.");
} else {
Ref<EditorSceneFormatImporterFBX> importer;
importer.instantiate();
@@ -135,6 +142,11 @@ void initialize_gltf_module(ModuleInitializationLevel p_level) {
GLOBAL_DEF_RST("filesystem/import/fbx/enabled", true);
GDREGISTER_CLASS(EditorSceneFormatImporterBlend);
GDREGISTER_CLASS(EditorSceneFormatImporterFBX);
+ // Can't (a priori) run external app on these platforms.
+ GLOBAL_DEF_RST("filesystem/import/blender/enabled.android", false);
+ GLOBAL_DEF_RST("filesystem/import/blender/enabled.web", false);
+ GLOBAL_DEF_RST("filesystem/import/fbx/enabled.android", false);
+ GLOBAL_DEF_RST("filesystem/import/fbx/enabled.web", false);
ClassDB::set_current_api(prev_api);
EditorNode::add_init_callback(_editor_init);
diff --git a/modules/gltf/gltf_accessor.cpp b/modules/gltf/structures/gltf_accessor.cpp
index 1daf2f90a7..1b8911fe72 100644
--- a/modules/gltf/gltf_accessor.cpp
+++ b/modules/gltf/structures/gltf_accessor.cpp
@@ -30,8 +30,6 @@
#include "gltf_accessor.h"
-#include "gltf_document_extension.h"
-
void GLTFAccessor::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_buffer_view"), &GLTFAccessor::get_buffer_view);
ClassDB::bind_method(D_METHOD("set_buffer_view", "buffer_view"), &GLTFAccessor::set_buffer_view);
@@ -67,7 +65,7 @@ void GLTFAccessor::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "component_type"), "set_component_type", "get_component_type"); // int
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "normalized"), "set_normalized", "get_normalized"); // bool
ADD_PROPERTY(PropertyInfo(Variant::INT, "count"), "set_count", "get_count"); // int
- ADD_PROPERTY(PropertyInfo(Variant::INT, "type"), "set_type", "get_type"); // GLTFDocument::GLTFType
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "type"), "set_type", "get_type"); // GLTFType
ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT64_ARRAY, "min"), "set_min", "get_min"); // Vector<real_t>
ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT64_ARRAY, "max"), "set_max", "get_max"); // Vector<real_t>
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_count"), "set_sparse_count", "get_sparse_count"); // int
@@ -123,7 +121,7 @@ int GLTFAccessor::get_type() {
}
void GLTFAccessor::set_type(int p_type) {
- type = (GLTFDocument::GLTFType)p_type; // TODO: Register enum
+ type = (GLTFType)p_type; // TODO: Register enum
}
Vector<double> GLTFAccessor::get_min() {
diff --git a/modules/gltf/gltf_accessor.h b/modules/gltf/structures/gltf_accessor.h
index f412dc2c7f..bfb71d57fe 100644
--- a/modules/gltf/gltf_accessor.h
+++ b/modules/gltf/structures/gltf_accessor.h
@@ -33,7 +33,7 @@
#include "core/io/resource.h"
-#include "gltf_document.h"
+#include "../gltf_defines.h"
struct GLTFAccessor : public Resource {
GDCLASS(GLTFAccessor, Resource);
@@ -45,7 +45,7 @@ private:
int component_type = 0;
bool normalized = false;
int count = 0;
- GLTFDocument::GLTFType type = GLTFDocument::TYPE_SCALAR;
+ GLTFType type = GLTFType::TYPE_SCALAR;
Vector<double> min;
Vector<double> max;
int sparse_count = 0;
@@ -101,4 +101,5 @@ public:
int get_sparse_values_byte_offset();
void set_sparse_values_byte_offset(int p_sparse_values_byte_offset);
};
+
#endif // GLTF_ACCESSOR_H
diff --git a/modules/gltf/gltf_animation.cpp b/modules/gltf/structures/gltf_animation.cpp
index e598c870ab..e598c870ab 100644
--- a/modules/gltf/gltf_animation.cpp
+++ b/modules/gltf/structures/gltf_animation.cpp
diff --git a/modules/gltf/gltf_animation.h b/modules/gltf/structures/gltf_animation.h
index 8688ddb937..3777f579f6 100644
--- a/modules/gltf/gltf_animation.h
+++ b/modules/gltf/structures/gltf_animation.h
@@ -71,4 +71,5 @@ private:
bool loop = false;
HashMap<int, Track> tracks;
};
+
#endif // GLTF_ANIMATION_H
diff --git a/modules/gltf/gltf_buffer_view.cpp b/modules/gltf/structures/gltf_buffer_view.cpp
index fc467367c6..ba19ed8628 100644
--- a/modules/gltf/gltf_buffer_view.cpp
+++ b/modules/gltf/structures/gltf_buffer_view.cpp
@@ -30,7 +30,7 @@
#include "gltf_buffer_view.h"
-#include "gltf_document_extension.h"
+#include "../gltf_document_extension.h"
void GLTFBufferView::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_buffer"), &GLTFBufferView::get_buffer);
diff --git a/modules/gltf/gltf_buffer_view.h b/modules/gltf/structures/gltf_buffer_view.h
index 560d56f35c..b1f500de25 100644
--- a/modules/gltf/gltf_buffer_view.h
+++ b/modules/gltf/structures/gltf_buffer_view.h
@@ -31,8 +31,8 @@
#ifndef GLTF_BUFFER_VIEW_H
#define GLTF_BUFFER_VIEW_H
+#include "../gltf_defines.h"
#include "core/io/resource.h"
-#include "gltf_document.h"
class GLTFBufferView : public Resource {
GDCLASS(GLTFBufferView, Resource);
@@ -65,4 +65,5 @@ public:
void set_indices(bool p_indices);
// matrices need to be transformed to this
};
+
#endif // GLTF_BUFFER_VIEW_H
diff --git a/modules/gltf/structures/gltf_camera.cpp b/modules/gltf/structures/gltf_camera.cpp
new file mode 100644
index 0000000000..212b9b80c8
--- /dev/null
+++ b/modules/gltf/structures/gltf_camera.cpp
@@ -0,0 +1,132 @@
+/*************************************************************************/
+/* gltf_camera.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "gltf_camera.h"
+
+void GLTFCamera::_bind_methods() {
+ ClassDB::bind_static_method("GLTFCamera", D_METHOD("from_node", "camera_node"), &GLTFCamera::from_node);
+ ClassDB::bind_method(D_METHOD("to_node"), &GLTFCamera::to_node);
+
+ ClassDB::bind_static_method("GLTFCamera", D_METHOD("from_dictionary", "dictionary"), &GLTFCamera::from_dictionary);
+ ClassDB::bind_method(D_METHOD("to_dictionary"), &GLTFCamera::to_dictionary);
+
+ ClassDB::bind_method(D_METHOD("get_perspective"), &GLTFCamera::get_perspective);
+ ClassDB::bind_method(D_METHOD("set_perspective", "perspective"), &GLTFCamera::set_perspective);
+ ClassDB::bind_method(D_METHOD("get_fov"), &GLTFCamera::get_fov);
+ ClassDB::bind_method(D_METHOD("set_fov", "fov"), &GLTFCamera::set_fov);
+ ClassDB::bind_method(D_METHOD("get_size_mag"), &GLTFCamera::get_size_mag);
+ ClassDB::bind_method(D_METHOD("set_size_mag", "size_mag"), &GLTFCamera::set_size_mag);
+ ClassDB::bind_method(D_METHOD("get_depth_far"), &GLTFCamera::get_depth_far);
+ ClassDB::bind_method(D_METHOD("set_depth_far", "zdepth_far"), &GLTFCamera::set_depth_far);
+ ClassDB::bind_method(D_METHOD("get_depth_near"), &GLTFCamera::get_depth_near);
+ ClassDB::bind_method(D_METHOD("set_depth_near", "zdepth_near"), &GLTFCamera::set_depth_near);
+
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "perspective"), "set_perspective", "get_perspective");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fov"), "set_fov", "get_fov");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_mag"), "set_size_mag", "get_size_mag");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth_far"), "set_depth_far", "get_depth_far");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth_near"), "set_depth_near", "get_depth_near");
+}
+
+Ref<GLTFCamera> GLTFCamera::from_node(const Camera3D *p_camera) {
+ Ref<GLTFCamera> c;
+ c.instantiate();
+ ERR_FAIL_COND_V_MSG(!p_camera, c, "Tried to create a GLTFCamera from a Camera3D node, but the given node was null.");
+ c->set_perspective(p_camera->get_projection() == Camera3D::ProjectionType::PROJECTION_PERSPECTIVE);
+ // GLTF spec (yfov) is in radians, Godot's camera (fov) is in degrees.
+ c->set_fov(Math::deg_to_rad(p_camera->get_fov()));
+ // GLTF spec (xmag and ymag) is a radius in meters, Godot's camera (size) is a diameter in meters.
+ c->set_size_mag(p_camera->get_size() * 0.5f);
+ c->set_depth_far(p_camera->get_far());
+ c->set_depth_near(p_camera->get_near());
+ return c;
+}
+
+Camera3D *GLTFCamera::to_node() const {
+ Camera3D *camera = memnew(Camera3D);
+ camera->set_projection(perspective ? Camera3D::PROJECTION_PERSPECTIVE : Camera3D::PROJECTION_ORTHOGONAL);
+ // GLTF spec (yfov) is in radians, Godot's camera (fov) is in degrees.
+ camera->set_fov(Math::rad_to_deg(fov));
+ // GLTF spec (xmag and ymag) is a radius in meters, Godot's camera (size) is a diameter in meters.
+ camera->set_size(size_mag * 2.0f);
+ camera->set_near(depth_near);
+ camera->set_far(depth_far);
+ return camera;
+}
+
+Ref<GLTFCamera> GLTFCamera::from_dictionary(const Dictionary p_dictionary) {
+ ERR_FAIL_COND_V_MSG(!p_dictionary.has("type"), Ref<GLTFCamera>(), "Failed to parse GLTF camera, missing required field 'type'.");
+ Ref<GLTFCamera> camera;
+ camera.instantiate();
+ const String &type = p_dictionary["type"];
+ if (type == "perspective") {
+ camera->set_perspective(true);
+ if (p_dictionary.has("perspective")) {
+ const Dictionary &persp = p_dictionary["perspective"];
+ camera->set_fov(persp["yfov"]);
+ if (persp.has("zfar")) {
+ camera->set_depth_far(persp["zfar"]);
+ }
+ camera->set_depth_near(persp["znear"]);
+ }
+ } else if (type == "orthographic") {
+ camera->set_perspective(false);
+ if (p_dictionary.has("orthographic")) {
+ const Dictionary &ortho = p_dictionary["orthographic"];
+ camera->set_size_mag(ortho["ymag"]);
+ camera->set_depth_far(ortho["zfar"]);
+ camera->set_depth_near(ortho["znear"]);
+ }
+ } else {
+ ERR_PRINT("Error parsing GLTF camera: Camera type '" + type + "' is unknown, should be perspective or orthographic.");
+ }
+ return camera;
+}
+
+Dictionary GLTFCamera::to_dictionary() const {
+ Dictionary d;
+ if (perspective) {
+ Dictionary persp;
+ persp["yfov"] = fov;
+ persp["zfar"] = depth_far;
+ persp["znear"] = depth_near;
+ d["perspective"] = persp;
+ d["type"] = "perspective";
+ } else {
+ Dictionary ortho;
+ ortho["ymag"] = size_mag;
+ ortho["xmag"] = size_mag;
+ ortho["zfar"] = depth_far;
+ ortho["znear"] = depth_near;
+ d["orthographic"] = ortho;
+ d["type"] = "orthographic";
+ }
+ return d;
+}
diff --git a/modules/gltf/gltf_camera.h b/modules/gltf/structures/gltf_camera.h
index c696d4cc6b..50ae10e17a 100644
--- a/modules/gltf/gltf_camera.h
+++ b/modules/gltf/structures/gltf_camera.h
@@ -32,15 +32,22 @@
#define GLTF_CAMERA_H
#include "core/io/resource.h"
+#include "scene/3d/camera_3d.h"
+
+// Reference and test file:
+// https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_015_SimpleCameras.md
class GLTFCamera : public Resource {
GDCLASS(GLTFCamera, Resource);
private:
+ // GLTF has no default camera values, they should always be specified in
+ // the GLTF file. Here we default to Godot's default camera settings.
bool perspective = true;
- float fov_size = 75.0;
- float depth_far = 4000.0;
- float depth_near = 0.05;
+ real_t fov = Math::deg_to_rad(75.0);
+ real_t size_mag = 0.5;
+ real_t depth_far = 4000.0;
+ real_t depth_near = 0.05;
protected:
static void _bind_methods();
@@ -48,11 +55,20 @@ protected:
public:
bool get_perspective() const { return perspective; }
void set_perspective(bool p_val) { perspective = p_val; }
- float get_fov_size() const { return fov_size; }
- void set_fov_size(float p_val) { fov_size = p_val; }
- float get_depth_far() const { return depth_far; }
- void set_depth_far(float p_val) { depth_far = p_val; }
- float get_depth_near() const { return depth_near; }
- void set_depth_near(float p_val) { depth_near = p_val; }
+ real_t get_fov() const { return fov; }
+ void set_fov(real_t p_val) { fov = p_val; }
+ real_t get_size_mag() const { return size_mag; }
+ void set_size_mag(real_t p_val) { size_mag = p_val; }
+ real_t get_depth_far() const { return depth_far; }
+ void set_depth_far(real_t p_val) { depth_far = p_val; }
+ real_t get_depth_near() const { return depth_near; }
+ void set_depth_near(real_t p_val) { depth_near = p_val; }
+
+ static Ref<GLTFCamera> from_node(const Camera3D *p_light);
+ Camera3D *to_node() const;
+
+ static Ref<GLTFCamera> from_dictionary(const Dictionary p_dictionary);
+ Dictionary to_dictionary() const;
};
+
#endif // GLTF_CAMERA_H
diff --git a/modules/gltf/gltf_mesh.cpp b/modules/gltf/structures/gltf_mesh.cpp
index 3add8304b1..3893f56626 100644
--- a/modules/gltf/gltf_mesh.cpp
+++ b/modules/gltf/structures/gltf_mesh.cpp
@@ -53,11 +53,11 @@ void GLTFMesh::set_mesh(Ref<ImporterMesh> p_mesh) {
mesh = p_mesh;
}
-Array GLTFMesh::get_instance_materials() {
+TypedArray<Material> GLTFMesh::get_instance_materials() {
return instance_materials;
}
-void GLTFMesh::set_instance_materials(Array p_instance_materials) {
+void GLTFMesh::set_instance_materials(TypedArray<Material> p_instance_materials) {
instance_materials = p_instance_materials;
}
diff --git a/modules/gltf/gltf_mesh.h b/modules/gltf/structures/gltf_mesh.h
index dc26120b48..2fa37fd727 100644
--- a/modules/gltf/gltf_mesh.h
+++ b/modules/gltf/structures/gltf_mesh.h
@@ -42,7 +42,7 @@ class GLTFMesh : public Resource {
private:
Ref<ImporterMesh> mesh;
Vector<float> blend_weights;
- Array instance_materials;
+ TypedArray<Material> instance_materials;
protected:
static void _bind_methods();
@@ -52,8 +52,8 @@ public:
void set_mesh(Ref<ImporterMesh> p_mesh);
Vector<float> get_blend_weights();
void set_blend_weights(Vector<float> p_blend_weights);
- Array get_instance_materials();
- void set_instance_materials(Array p_instance_materials);
+ TypedArray<Material> get_instance_materials();
+ void set_instance_materials(TypedArray<Material> p_instance_materials);
};
#endif // GLTF_MESH_H
diff --git a/modules/gltf/gltf_node.cpp b/modules/gltf/structures/gltf_node.cpp
index 86280603fa..86280603fa 100644
--- a/modules/gltf/gltf_node.cpp
+++ b/modules/gltf/structures/gltf_node.cpp
diff --git a/modules/gltf/gltf_node.h b/modules/gltf/structures/gltf_node.h
index 929ad3eca0..1a57ea32e2 100644
--- a/modules/gltf/gltf_node.h
+++ b/modules/gltf/structures/gltf_node.h
@@ -31,8 +31,8 @@
#ifndef GLTF_NODE_H
#define GLTF_NODE_H
+#include "../gltf_defines.h"
#include "core/io/resource.h"
-#include "gltf_document.h"
class GLTFNode : public Resource {
GDCLASS(GLTFNode, Resource);
@@ -97,4 +97,5 @@ public:
GLTFLightIndex get_light();
void set_light(GLTFLightIndex p_light);
};
+
#endif // GLTF_NODE_H
diff --git a/modules/gltf/gltf_skeleton.cpp b/modules/gltf/structures/gltf_skeleton.cpp
index b813f39a27..0073357eda 100644
--- a/modules/gltf/gltf_skeleton.cpp
+++ b/modules/gltf/structures/gltf_skeleton.cpp
@@ -30,6 +30,9 @@
#include "gltf_skeleton.h"
+#include "../gltf_template_convert.h"
+#include "scene/3d/bone_attachment_3d.h"
+
void GLTFSkeleton::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_joints"), &GLTFSkeleton::get_joints);
ClassDB::bind_method(D_METHOD("set_joints", "joints"), &GLTFSkeleton::set_joints);
@@ -69,20 +72,20 @@ Skeleton3D *GLTFSkeleton::get_godot_skeleton() {
return godot_skeleton;
}
-Array GLTFSkeleton::get_unique_names() {
- return GLTFDocument::to_array(unique_names);
+TypedArray<String> GLTFSkeleton::get_unique_names() {
+ return GLTFTemplateConvert::to_array(unique_names);
}
-void GLTFSkeleton::set_unique_names(Array p_unique_names) {
- GLTFDocument::set_from_array(unique_names, p_unique_names);
+void GLTFSkeleton::set_unique_names(TypedArray<String> p_unique_names) {
+ GLTFTemplateConvert::set_from_array(unique_names, p_unique_names);
}
Dictionary GLTFSkeleton::get_godot_bone_node() {
- return GLTFDocument::to_dict(godot_bone_node);
+ return GLTFTemplateConvert::to_dict(godot_bone_node);
}
void GLTFSkeleton::set_godot_bone_node(Dictionary p_indict) {
- GLTFDocument::set_from_dict(godot_bone_node, p_indict);
+ GLTFTemplateConvert::set_from_dict(godot_bone_node, p_indict);
}
BoneAttachment3D *GLTFSkeleton::get_bone_attachment(int idx) {
diff --git a/modules/gltf/gltf_skeleton.h b/modules/gltf/structures/gltf_skeleton.h
index 92ee6e6234..0f20b493b6 100644
--- a/modules/gltf/gltf_skeleton.h
+++ b/modules/gltf/structures/gltf_skeleton.h
@@ -31,8 +31,8 @@
#ifndef GLTF_SKELETON_H
#define GLTF_SKELETON_H
+#include "../gltf_defines.h"
#include "core/io/resource.h"
-#include "gltf_document.h"
class GLTFSkeleton : public Resource {
GDCLASS(GLTFSkeleton, Resource);
@@ -75,8 +75,8 @@ public:
// this->godot_skeleton = p_godot_skeleton;
// }
- Array get_unique_names();
- void set_unique_names(Array p_unique_names);
+ TypedArray<String> get_unique_names();
+ void set_unique_names(TypedArray<String> p_unique_names);
//RBMap<int32_t, GLTFNodeIndex> get_godot_bone_node() {
// return this->godot_bone_node;
@@ -98,4 +98,5 @@ public:
int32_t get_bone_attachment_count();
};
+
#endif // GLTF_SKELETON_H
diff --git a/modules/gltf/gltf_skin.cpp b/modules/gltf/structures/gltf_skin.cpp
index e8005aa0c1..9717a66048 100644
--- a/modules/gltf/gltf_skin.cpp
+++ b/modules/gltf/structures/gltf_skin.cpp
@@ -30,6 +30,10 @@
#include "gltf_skin.h"
+#include "../gltf_template_convert.h"
+#include "core/variant/typed_array.h"
+#include "scene/resources/skin.h"
+
void GLTFSkin::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_skin_root"), &GLTFSkin::get_skin_root);
ClassDB::bind_method(D_METHOD("set_skin_root", "skin_root"), &GLTFSkin::set_skin_root);
@@ -80,12 +84,12 @@ void GLTFSkin::set_joints_original(Vector<GLTFNodeIndex> p_joints_original) {
joints_original = p_joints_original;
}
-Array GLTFSkin::get_inverse_binds() {
- return GLTFDocument::to_array(inverse_binds);
+TypedArray<Transform3D> GLTFSkin::get_inverse_binds() {
+ return GLTFTemplateConvert::to_array(inverse_binds);
}
-void GLTFSkin::set_inverse_binds(Array p_inverse_binds) {
- GLTFDocument::set_from_array(inverse_binds, p_inverse_binds);
+void GLTFSkin::set_inverse_binds(TypedArray<Transform3D> p_inverse_binds) {
+ GLTFTemplateConvert::set_from_array(inverse_binds, p_inverse_binds);
}
Vector<GLTFNodeIndex> GLTFSkin::get_joints() {
@@ -121,11 +125,11 @@ void GLTFSkin::set_skeleton(int p_skeleton) {
}
Dictionary GLTFSkin::get_joint_i_to_bone_i() {
- return GLTFDocument::to_dict(joint_i_to_bone_i);
+ return GLTFTemplateConvert::to_dict(joint_i_to_bone_i);
}
void GLTFSkin::set_joint_i_to_bone_i(Dictionary p_joint_i_to_bone_i) {
- GLTFDocument::set_from_dict(joint_i_to_bone_i, p_joint_i_to_bone_i);
+ GLTFTemplateConvert::set_from_dict(joint_i_to_bone_i, p_joint_i_to_bone_i);
}
Dictionary GLTFSkin::get_joint_i_to_name() {
diff --git a/modules/gltf/gltf_skin.h b/modules/gltf/structures/gltf_skin.h
index d946324756..1a4d54b380 100644
--- a/modules/gltf/gltf_skin.h
+++ b/modules/gltf/structures/gltf_skin.h
@@ -31,8 +31,11 @@
#ifndef GLTF_SKIN_H
#define GLTF_SKIN_H
+#include "../gltf_defines.h"
#include "core/io/resource.h"
-#include "gltf_document.h"
+
+template <typename T>
+class TypedArray;
class GLTFSkin : public Resource {
GDCLASS(GLTFSkin, Resource);
@@ -82,8 +85,8 @@ public:
Vector<GLTFNodeIndex> get_joints_original();
void set_joints_original(Vector<GLTFNodeIndex> p_joints_original);
- Array get_inverse_binds();
- void set_inverse_binds(Array p_inverse_binds);
+ TypedArray<Transform3D> get_inverse_binds();
+ void set_inverse_binds(TypedArray<Transform3D> p_inverse_binds);
Vector<GLTFNodeIndex> get_joints();
void set_joints(Vector<GLTFNodeIndex> p_joints);
@@ -106,4 +109,5 @@ public:
Ref<Skin> get_godot_skin();
void set_godot_skin(Ref<Skin> p_godot_skin);
};
+
#endif // GLTF_SKIN_H
diff --git a/modules/gltf/gltf_texture.cpp b/modules/gltf/structures/gltf_texture.cpp
index 2a21cb3df8..2a21cb3df8 100644
--- a/modules/gltf/gltf_texture.cpp
+++ b/modules/gltf/structures/gltf_texture.cpp
diff --git a/modules/gltf/gltf_texture.h b/modules/gltf/structures/gltf_texture.h
index 54dd61f9a5..b1d12dddfa 100644
--- a/modules/gltf/gltf_texture.h
+++ b/modules/gltf/structures/gltf_texture.h
@@ -31,8 +31,8 @@
#ifndef GLTF_TEXTURE_H
#define GLTF_TEXTURE_H
+#include "../gltf_defines.h"
#include "core/io/resource.h"
-#include "gltf_document.h"
class GLTFTexture : public Resource {
GDCLASS(GLTFTexture, Resource);