mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-22 17:17:17 +01:00
Replaced the gltf modlue to the one in godot4. It's currently disabled by default while it can't be built.
This commit is contained in:
parent
f8ac4e5708
commit
7c4416503e
11
modules/gltf/README.md
Normal file
11
modules/gltf/README.md
Normal file
@ -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.
|
@ -5,5 +5,10 @@ Import("env_modules")
|
||||
|
||||
env_gltf = env_modules.Clone()
|
||||
|
||||
# Pandemonium'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")
|
||||
|
@ -1,5 +1,8 @@
|
||||
|
||||
|
||||
def can_build(env, platform):
|
||||
return env["tools"] and not env["disable_3d"]
|
||||
#return not env["disable_3d"]
|
||||
return False
|
||||
|
||||
|
||||
def configure(env):
|
||||
@ -8,12 +11,16 @@ def configure(env):
|
||||
|
||||
def get_doc_classes():
|
||||
return [
|
||||
"EditorSceneImporterGLTF",
|
||||
"EditorSceneFormatImporterBlend",
|
||||
"EditorSceneFormatImporterFBX",
|
||||
"EditorSceneFormatImporterGLTF",
|
||||
"GLTFAccessor",
|
||||
"GLTFAnimation",
|
||||
"GLTFBufferView",
|
||||
"GLTFCamera",
|
||||
"GLTFDocument",
|
||||
"GLTFDocumentExtension",
|
||||
"GLTFDocumentExtensionConvertImporterMesh",
|
||||
"GLTFLight",
|
||||
"GLTFMesh",
|
||||
"GLTFNode",
|
||||
@ -22,7 +29,6 @@ def get_doc_classes():
|
||||
"GLTFSpecGloss",
|
||||
"GLTFState",
|
||||
"GLTFTexture",
|
||||
"PackedSceneGLTF",
|
||||
]
|
||||
|
||||
|
||||
|
15
modules/gltf/doc_classes/EditorSceneFormatImporterBlend.xml
Normal file
15
modules/gltf/doc_classes/EditorSceneFormatImporterBlend.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="EditorSceneFormatImporterBlend" inherits="EditorSceneFormatImporter" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
Importer for Blender's [code].blend[/code] scene file format.
|
||||
</brief_description>
|
||||
<description>
|
||||
Imports Blender scenes in the [code].blend[/code] file format through the glTF 2.0 3D import pipeline. This importer requires Blender to be installed by the user, so that it can be used to export the scene as glTF 2.0.
|
||||
The location of the Blender binary is set via the [code]filesystem/import/blender/blender3_path[/code] editor setting.
|
||||
This importer is only used if [member ProjectSettings.filesystem/import/blender/enabled] is enabled, otherwise [code].blend[/code] files present in the project folder are not imported.
|
||||
Blend import requires Blender 3.0.
|
||||
Internally, the EditorSceneFormatImporterBlend uses the Blender glTF "Use Original" mode to reference external textures.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
</class>
|
13
modules/gltf/doc_classes/EditorSceneFormatImporterFBX.xml
Normal file
13
modules/gltf/doc_classes/EditorSceneFormatImporterFBX.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="EditorSceneFormatImporterFBX" inherits="EditorSceneFormatImporter" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
Importer for the [code].fbx[/code] scene file format.
|
||||
</brief_description>
|
||||
<description>
|
||||
Imports Autodesk FBX 3D scenes by way of converting them to glTF 2.0 using the FBX2glTF command line tool.
|
||||
The location of the FBX2glTF binary is set via the [code]filesystem/import/fbx/fbx2gltf_path[/code] editor setting.
|
||||
This importer is only used if [member ProjectSettings.filesystem/import/fbx/enabled] is enabled, otherwise [code].fbx[/code] files present in the project folder are not imported.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
</class>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="EditorSceneFormatImporterGLTF" inherits="EditorSceneFormatImporter" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
</class>
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="EditorSceneImporterGLTF" inherits="EditorSceneImporter" version="3.5">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [EditorSceneImporterGLTF] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,14 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFAccessor" inherits="Resource" version="3.5">
|
||||
<class name="GLTFAccessor" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFAccessor] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="buffer_view" type="int" setter="set_buffer_view" getter="get_buffer_view" default="0">
|
||||
</member>
|
||||
@ -18,9 +15,9 @@
|
||||
</member>
|
||||
<member name="count" type="int" setter="set_count" getter="get_count" default="0">
|
||||
</member>
|
||||
<member name="max" type="PoolRealArray" setter="set_max" getter="get_max" default="PoolRealArray( )">
|
||||
<member name="max" type="PackedFloat64Array" setter="set_max" getter="get_max" default="PackedFloat64Array()">
|
||||
</member>
|
||||
<member name="min" type="PoolRealArray" setter="set_min" getter="get_min" default="PoolRealArray( )">
|
||||
<member name="min" type="PackedFloat64Array" setter="set_min" getter="get_min" default="PackedFloat64Array()">
|
||||
</member>
|
||||
<member name="normalized" type="bool" setter="set_normalized" getter="get_normalized" default="false">
|
||||
</member>
|
||||
@ -39,6 +36,4 @@
|
||||
<member name="type" type="int" setter="set_type" getter="get_type" default="0">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,18 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFAnimation" inherits="Resource" version="3.5">
|
||||
<class name="GLTFAnimation" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFAnimation] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="loop" type="bool" setter="set_loop" getter="get_loop" default="false">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,14 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFBufferView" inherits="Resource" version="3.5">
|
||||
<class name="GLTFBufferView" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFBufferView] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="buffer" type="int" setter="set_buffer" getter="get_buffer" default="-1">
|
||||
</member>
|
||||
@ -21,6 +18,4 @@
|
||||
<member name="indices" type="bool" setter="set_indices" getter="get_indices" default="false">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,24 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFCamera" inherits="Resource" version="3.5">
|
||||
<class name="GLTFCamera" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFCamera] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="depth_far" type="float" setter="set_depth_far" getter="get_depth_far" default="4000.0">
|
||||
</member>
|
||||
<member name="depth_near" type="float" setter="set_depth_near" getter="get_depth_near" default="0.05">
|
||||
</member>
|
||||
<member name="fov_size" type="float" setter="set_fov_size" getter="get_fov_size" default="75.0">
|
||||
</member>
|
||||
<member name="perspective" type="bool" setter="set_perspective" getter="get_perspective" default="true">
|
||||
</member>
|
||||
<member name="zfar" type="float" setter="set_zfar" getter="get_zfar" default="4000.0">
|
||||
</member>
|
||||
<member name="znear" type="float" setter="set_znear" getter="get_znear" default="0.05">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,14 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFDocument" inherits="Resource" version="3.5">
|
||||
<class name="GLTFDocument" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFDocument] within a script will cause an error in an exported project.
|
||||
Append a glTF2 3d format from a file, buffer or scene and then write to the filesystem, buffer or scene.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<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" />
|
||||
<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="""" />
|
||||
<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" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="generate_buffer">
|
||||
<return type="PackedByteArray" />
|
||||
<argument 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" />
|
||||
<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" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<constants>
|
||||
</constants>
|
||||
<members>
|
||||
<member name="extensions" type="GLTFDocumentExtension[]" setter="set_extensions" getter="get_extensions" default="[]">
|
||||
</member>
|
||||
</members>
|
||||
</class>
|
||||
|
60
modules/gltf/doc_classes/GLTFDocumentExtension.xml
Normal file
60
modules/gltf/doc_classes/GLTFDocumentExtension.xml
Normal file
@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFDocumentExtension" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<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" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="_export_post" qualifiers="virtual">
|
||||
<return type="int" />
|
||||
<argument 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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="_import_post_parse" qualifiers="virtual">
|
||||
<return type="int" />
|
||||
<argument 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" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
</class>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFDocumentExtensionConvertImporterMesh" inherits="GLTFDocumentExtension" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
</class>
|
@ -1,36 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFLight" inherits="Resource" version="3.5">
|
||||
<class name="GLTFLight" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFLight] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="color" type="Color" setter="set_color" getter="get_color" default="Color( 1, 1, 1, 1 )">
|
||||
<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.
|
||||
</member>
|
||||
<member name="inner_cone_angle" type="float" setter="set_inner_cone_angle" getter="get_inner_cone_angle" default="0.0">
|
||||
The inner angle of the cone in a spotlight. Must be less than or equal to the outer cone angle.
|
||||
Within this angle, the light is at full brightness. Between the inner and outer cone angles, there is a transition from full brightness to zero brightness. When creating a Pandemonium [SpotLight], the ratio between the inner and outer cone angles is used to calculate the attenuation of the light.
|
||||
Within this angle, the light is at full brightness. Between the inner and outer cone angles, there is a transition from full brightness to zero brightness. When creating a Godot [SpotLight3D], the ratio between the inner and outer cone angles is used to calculate the attenuation of the light.
|
||||
</member>
|
||||
<member name="intensity" type="float" setter="set_intensity" getter="get_intensity" default="1.0">
|
||||
The intensity of the light. This is expressed in candelas (lumens per steradian) for point and spot lights, and lux (lumens per m²) for directional lights. When creating a Pandemonium light, this value is converted to a unitless multiplier.
|
||||
The intensity of the light. This is expressed in candelas (lumens per steradian) for point and spot lights, and lux (lumens per m²) for directional lights. When creating a Godot light, this value is converted to a unitless multiplier.
|
||||
</member>
|
||||
<member name="light_type" type="String" setter="set_light_type" getter="get_light_type" default="""">
|
||||
The type of the light. The values accepted by Godot are "point", "spot", and "directional", which correspond to Godot's [OmniLight3D], [SpotLight3D], and [DirectionalLight3D] respectively.
|
||||
</member>
|
||||
<member name="outer_cone_angle" type="float" setter="set_outer_cone_angle" getter="get_outer_cone_angle" default="0.785398">
|
||||
The outer angle of the cone in a spotlight. Must be greater than or equal to the inner angle.
|
||||
At this angle, the light drops off to zero brightness. Between the inner and outer cone angles, there is a transition from full brightness to zero brightness. If this angle is a half turn, then the spotlight emits in all directions. When creating a Pandemonium [SpotLight], the outer cone angle is used as the angle of the spotlight.
|
||||
At this angle, the light drops off to zero brightness. Between the inner and outer cone angles, there is a transition from full brightness to zero brightness. If this angle is a half turn, then the spotlight emits in all directions. When creating a Godot [SpotLight3D], the outer cone angle is used as the angle of the spotlight.
|
||||
</member>
|
||||
<member name="range" type="float" setter="set_range" getter="get_range" default="inf">
|
||||
The range of the light, beyond which the light has no effect. GLTF lights with no range defined behave like physical lights (which have infinite range). When creating a Pandemonium light, the range is clamped to 4096.
|
||||
</member>
|
||||
<member name="type" type="String" setter="set_type" getter="get_type" default="""">
|
||||
The type of the light. The values accepted by Pandemonium are "point", "spot", and "directional", which correspond to Pandemonium's [OmniLight], [SpotLight], and [DirectionalLight] respectively.
|
||||
The range of the light, beyond which the light has no effect. GLTF lights with no range defined behave like physical lights (which have infinite range). When creating a Godot light, the range is clamped to 4096.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,22 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFMesh" inherits="Resource" version="3.5">
|
||||
<class name="GLTFMesh" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFMesh] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="blend_weights" type="PoolRealArray" setter="set_blend_weights" getter="get_blend_weights" default="PoolRealArray( )">
|
||||
<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="Array" setter="set_instance_materials" getter="get_instance_materials" default="[]">
|
||||
</member>
|
||||
<member name="mesh" type="ArrayMesh" setter="set_mesh" getter="get_mesh">
|
||||
<member name="mesh" type="ImporterMesh" setter="set_mesh" getter="get_mesh">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,18 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFNode" inherits="Resource" version="3.5">
|
||||
<class name="GLTFNode" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFNode] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="camera" type="int" setter="set_camera" getter="get_camera" default="-1">
|
||||
</member>
|
||||
<member name="children" type="PoolIntArray" setter="set_children" getter="get_children" default="PoolIntArray( )">
|
||||
<member name="children" type="PackedInt32Array" setter="set_children" getter="get_children" default="PackedInt32Array()">
|
||||
</member>
|
||||
<member name="height" type="int" setter="set_height" getter="get_height" default="-1">
|
||||
</member>
|
||||
@ -24,19 +21,17 @@
|
||||
</member>
|
||||
<member name="parent" type="int" setter="set_parent" getter="get_parent" default="-1">
|
||||
</member>
|
||||
<member name="rotation" type="Quat" setter="set_rotation" getter="get_rotation" default="Quat( 0, 0, 0, 1 )">
|
||||
<member name="position" type="Vector3" setter="set_position" getter="get_position" default="Vector3(0, 0, 0)">
|
||||
</member>
|
||||
<member name="scale" type="Vector3" setter="set_scale" getter="get_scale" default="Vector3( 1, 1, 1 )">
|
||||
<member name="rotation" type="Quaternion" setter="set_rotation" getter="get_rotation" default="Quaternion(0, 0, 0, 1)">
|
||||
</member>
|
||||
<member name="scale" type="Vector3" setter="set_scale" getter="get_scale" default="Vector3(1, 1, 1)">
|
||||
</member>
|
||||
<member name="skeleton" type="int" setter="set_skeleton" getter="get_skeleton" default="-1">
|
||||
</member>
|
||||
<member name="skin" type="int" setter="set_skin" getter="get_skin" default="-1">
|
||||
</member>
|
||||
<member name="translation" type="Vector3" setter="set_translation" getter="get_translation" default="Vector3( 0, 0, 0 )">
|
||||
</member>
|
||||
<member name="xform" type="Transform" setter="set_xform" getter="get_xform" default="Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )">
|
||||
<member name="xform" type="Transform3D" setter="set_xform" getter="get_xform" default="Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,15 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFSkeleton" inherits="Resource" version="3.5">
|
||||
<class name="GLTFSkeleton" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFSkeleton] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="get_bone_attachment">
|
||||
<return type="BoneAttachment" />
|
||||
<return type="BoneAttachment3D" />
|
||||
<argument index="0" name="idx" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
@ -19,13 +18,13 @@
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_pandemonium_bone_node">
|
||||
<method name="get_godot_bone_node">
|
||||
<return type="Dictionary" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_pandemonium_skeleton">
|
||||
<return type="Skeleton" />
|
||||
<method name="get_godot_skeleton">
|
||||
<return type="Skeleton3D" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
@ -34,9 +33,9 @@
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_pandemonium_bone_node">
|
||||
<method name="set_godot_bone_node">
|
||||
<return type="void" />
|
||||
<argument index="0" name="pandemonium_bone_node" type="Dictionary" />
|
||||
<argument index="0" name="godot_bone_node" type="Dictionary" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
@ -48,11 +47,9 @@
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="joints" type="PoolIntArray" setter="set_joints" getter="get_joints" default="PoolIntArray( )">
|
||||
<member name="joints" type="PackedInt32Array" setter="set_joints" getter="get_joints" default="PackedInt32Array()">
|
||||
</member>
|
||||
<member name="roots" type="PoolIntArray" setter="set_roots" getter="get_roots" default="PoolIntArray( )">
|
||||
<member name="roots" type="PackedInt32Array" setter="set_roots" getter="get_roots" default="PackedInt32Array()">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFSkin" inherits="Resource" version="3.5">
|
||||
<class name="GLTFSkin" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
@ -42,21 +42,19 @@
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="joints" type="PoolIntArray" setter="set_joints" getter="get_joints" default="PoolIntArray( )">
|
||||
<member name="godot_skin" type="Skin" setter="set_godot_skin" getter="get_godot_skin">
|
||||
</member>
|
||||
<member name="joints_original" type="PoolIntArray" setter="set_joints_original" getter="get_joints_original" default="PoolIntArray( )">
|
||||
<member name="joints" type="PackedInt32Array" setter="set_joints" getter="get_joints" default="PackedInt32Array()">
|
||||
</member>
|
||||
<member name="non_joints" type="PoolIntArray" setter="set_non_joints" getter="get_non_joints" default="PoolIntArray( )">
|
||||
<member name="joints_original" type="PackedInt32Array" setter="set_joints_original" getter="get_joints_original" default="PackedInt32Array()">
|
||||
</member>
|
||||
<member name="pandemonium_skin" type="Skin" setter="set_pandemonium_skin" getter="get_pandemonium_skin">
|
||||
<member name="non_joints" type="PackedInt32Array" setter="set_non_joints" getter="get_non_joints" default="PackedInt32Array()">
|
||||
</member>
|
||||
<member name="roots" type="PoolIntArray" setter="set_roots" getter="get_roots" default="PoolIntArray( )">
|
||||
<member name="roots" type="PackedInt32Array" setter="set_roots" getter="get_roots" default="PackedInt32Array()">
|
||||
</member>
|
||||
<member name="skeleton" type="int" setter="set_skeleton" getter="get_skeleton" default="-1">
|
||||
</member>
|
||||
<member name="skin_root" type="int" setter="set_skin_root" getter="get_skin_root" default="-1">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,16 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFSpecGloss" inherits="Resource" version="3.5">
|
||||
<class name="GLTFSpecGloss" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFSpecGloss] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="diffuse_factor" type="Color" setter="set_diffuse_factor" getter="get_diffuse_factor" default="Color( 1, 1, 1, 1 )">
|
||||
<member name="diffuse_factor" type="Color" setter="set_diffuse_factor" getter="get_diffuse_factor" default="Color(1, 1, 1, 1)">
|
||||
</member>
|
||||
<member name="diffuse_img" type="Image" setter="set_diffuse_img" getter="get_diffuse_img">
|
||||
</member>
|
||||
@ -18,9 +15,7 @@
|
||||
</member>
|
||||
<member name="spec_gloss_img" type="Image" setter="set_spec_gloss_img" getter="get_spec_gloss_img">
|
||||
</member>
|
||||
<member name="specular_factor" type="Color" setter="set_specular_factor" getter="get_specular_factor" default="Color( 1, 1, 1, 1 )">
|
||||
<member name="specular_factor" type="Color" setter="set_specular_factor" getter="get_specular_factor" default="Color(1, 1, 1, 1)">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,9 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFState" inherits="Resource" version="3.5">
|
||||
<class name="GLTFState" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFState] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
@ -193,9 +192,11 @@
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="buffers" type="Array" setter="set_buffers" getter="get_buffers" default="[ ]">
|
||||
<member name="base_path" type="String" setter="set_base_path" getter="get_base_path" default="""">
|
||||
</member>
|
||||
<member name="glb_data" type="PoolByteArray" setter="set_glb_data" getter="get_glb_data" default="PoolByteArray( )">
|
||||
<member name="buffers" type="Array" setter="set_buffers" getter="get_buffers" default="[]">
|
||||
</member>
|
||||
<member name="glb_data" type="PackedByteArray" setter="set_glb_data" getter="get_glb_data" default="PackedByteArray()">
|
||||
</member>
|
||||
<member name="json" type="Dictionary" setter="set_json" getter="get_json" default="{}">
|
||||
</member>
|
||||
@ -203,13 +204,11 @@
|
||||
</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="Array" setter="set_root_nodes" getter="get_root_nodes" default="[]">
|
||||
</member>
|
||||
<member name="scene_name" type="String" setter="set_scene_name" getter="get_scene_name" default="""">
|
||||
</member>
|
||||
<member name="use_named_skin_binds" type="bool" setter="set_use_named_skin_binds" getter="get_use_named_skin_binds" default="false">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,18 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFTexture" inherits="Resource" version="3.5">
|
||||
<class name="GLTFTexture" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFTexture] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="src_image" type="int" setter="set_src_image" getter="get_src_image" default="0">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,46 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="PackedSceneGLTF" inherits="PackedScene" version="3.5">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [PackedSceneGLTF] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="export_gltf">
|
||||
<return type="int" enum="Error" />
|
||||
<argument index="0" name="node" type="Node" />
|
||||
<argument index="1" name="path" type="String" />
|
||||
<argument index="2" name="flags" type="int" default="0" />
|
||||
<argument index="3" name="bake_fps" type="float" default="1000.0" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="import_gltf_scene">
|
||||
<return type="Node" />
|
||||
<argument index="0" name="path" type="String" />
|
||||
<argument index="1" name="flags" type="int" default="0" />
|
||||
<argument index="2" name="bake_fps" type="float" default="1000.0" />
|
||||
<argument index="3" name="compress_flags" type="int" default="2194432" />
|
||||
<argument index="4" name="state" type="GLTFState" default="null" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="pack_gltf">
|
||||
<return type="void" />
|
||||
<argument index="0" name="path" type="String" />
|
||||
<argument index="1" name="flags" type="int" default="0" />
|
||||
<argument index="2" name="bake_fps" type="float" default="1000.0" />
|
||||
<argument index="3" name="compress_flags" type="int" default="2194432" />
|
||||
<argument index="4" name="state" type="GLTFState" default="null" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="_bundled" type="Dictionary" setter="_set_bundled_scene" getter="_get_bundled_scene" overrides="PackedScene" default="{"conn_count": 0,"conns": PoolIntArray( ),"editable_instances": [ ],"names": PoolStringArray( ),"node_count": 0,"node_paths": [ ],"nodes": PoolIntArray( ),"variants": [ ],"version": 2}" />
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -32,9 +32,18 @@
|
||||
|
||||
#include "editor_scene_exporter_gltf_plugin.h"
|
||||
|
||||
#include "../gltf_document.h"
|
||||
#include "../gltf_state.h"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/error/error_list.h"
|
||||
#include "core/object/object.h"
|
||||
#include "core/templates/vector.h"
|
||||
#include "editor/editor_file_dialog.h"
|
||||
#include "editor/editor_file_system.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "scene/3d/mesh_instance_3d.h"
|
||||
#include "scene/gui/check_box.h"
|
||||
#include "scene/main/node.h"
|
||||
|
||||
String SceneExporterGLTFPlugin::get_name() const {
|
||||
@ -45,50 +54,58 @@ bool SceneExporterGLTFPlugin::has_main_screen() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
SceneExporterGLTFPlugin::SceneExporterGLTFPlugin(EditorNode *p_node) {
|
||||
editor = p_node;
|
||||
convert_gltf2.instance();
|
||||
SceneExporterGLTFPlugin::SceneExporterGLTFPlugin() {
|
||||
file_export_lib = memnew(EditorFileDialog);
|
||||
editor->get_gui_base()->add_child(file_export_lib);
|
||||
file_export_lib->connect("file_selected", this, "_gltf2_dialog_action");
|
||||
EditorNode::get_singleton()->get_gui_base()->add_child(file_export_lib);
|
||||
file_export_lib->connect("file_selected", callable_mp(this, &SceneExporterGLTFPlugin::_gltf2_dialog_action));
|
||||
file_export_lib->set_title(TTR("Export Library"));
|
||||
file_export_lib->set_mode(EditorFileDialog::MODE_SAVE_FILE);
|
||||
file_export_lib->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
|
||||
file_export_lib->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
|
||||
file_export_lib->clear_filters();
|
||||
file_export_lib->add_filter("*.glb");
|
||||
file_export_lib->add_filter("*.gltf");
|
||||
file_export_lib->set_title(TTR("Export Mesh GLTF2"));
|
||||
String gltf_scene_name = TTR("Export GLTF...");
|
||||
add_tool_menu_item(gltf_scene_name, this, "convert_scene_to_gltf2", DEFVAL(Variant()));
|
||||
file_export_lib->set_title(TTR("Export Scene to glTF 2.0 File"));
|
||||
|
||||
PopupMenu *menu = get_export_as_menu();
|
||||
int idx = menu->get_item_count();
|
||||
menu->add_item(TTR("glTF 2.0 Scene..."));
|
||||
menu->set_item_metadata(idx, callable_mp(this, &SceneExporterGLTFPlugin::convert_scene_to_gltf2));
|
||||
}
|
||||
|
||||
void SceneExporterGLTFPlugin::_gltf2_dialog_action(String p_file) {
|
||||
Node *root = editor->get_tree()->get_edited_scene_root();
|
||||
Node *root = EditorNode::get_singleton()->get_tree()->get_edited_scene_root();
|
||||
if (!root) {
|
||||
editor->show_accept(TTR("This operation can't be done without a scene."), TTR("OK"));
|
||||
EditorNode::get_singleton()->show_accept(TTR("This operation can't be done without a scene."), TTR("OK"));
|
||||
return;
|
||||
}
|
||||
List<String> deps;
|
||||
convert_gltf2->save_scene(root, p_file, p_file, 0, 1000.0f, &deps);
|
||||
EditorFileSystem::get_singleton()->scan_changes();
|
||||
Ref<GLTFDocument> doc;
|
||||
doc.instantiate();
|
||||
Ref<GLTFState> state;
|
||||
state.instantiate();
|
||||
int32_t flags = 0;
|
||||
flags |= EditorSceneFormatImporter::IMPORT_USE_NAMED_SKIN_BINDS;
|
||||
Error err = doc->append_from_scene(root, state, flags, 30.0f);
|
||||
if (err != OK) {
|
||||
ERR_PRINT(vformat("glTF2 save scene error %s.", itos(err)));
|
||||
}
|
||||
err = doc->write_to_filesystem(state, p_file);
|
||||
if (err != OK) {
|
||||
ERR_PRINT(vformat("glTF2 save scene error %s.", itos(err)));
|
||||
}
|
||||
}
|
||||
|
||||
void SceneExporterGLTFPlugin::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("convert_scene_to_gltf2"), &SceneExporterGLTFPlugin::convert_scene_to_gltf2);
|
||||
ClassDB::bind_method(D_METHOD("_gltf2_dialog_action", "file"), &SceneExporterGLTFPlugin::_gltf2_dialog_action);
|
||||
}
|
||||
|
||||
void SceneExporterGLTFPlugin::convert_scene_to_gltf2(Variant p_null) {
|
||||
Node *root = editor->get_tree()->get_edited_scene_root();
|
||||
void SceneExporterGLTFPlugin::convert_scene_to_gltf2() {
|
||||
Node *root = EditorNode::get_singleton()->get_tree()->get_edited_scene_root();
|
||||
if (!root) {
|
||||
editor->show_accept(TTR("This operation can't be done without a scene."), TTR("OK"));
|
||||
EditorNode::get_singleton()->show_accept(TTR("This operation can't be done without a scene."), TTR("OK"));
|
||||
return;
|
||||
}
|
||||
String filename = String(root->get_filename().get_file().get_basename());
|
||||
if (filename.empty()) {
|
||||
String filename = String(root->get_scene_file_path().get_file().get_basename());
|
||||
if (filename.is_empty()) {
|
||||
filename = root->get_name();
|
||||
}
|
||||
file_export_lib->set_current_file(filename + ".gltf");
|
||||
file_export_lib->set_current_file(filename + String(".gltf"));
|
||||
file_export_lib->popup_centered_ratio();
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
#ifndef EDITOR_SCENE_EXPORTER_GLTF_PLUGIN_H
|
||||
#define EDITOR_SCENE_EXPORTER_GLTF_PLUGIN_H
|
||||
/*************************************************************************/
|
||||
/* editor_scene_exporter_gltf_plugin.h */
|
||||
/*************************************************************************/
|
||||
@ -30,27 +28,27 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "editor/editor_file_dialog.h"
|
||||
#include "editor/editor_plugin.h"
|
||||
#ifndef EDITOR_SCENE_EXPORTER_GLTF_PLUGIN_H
|
||||
#define EDITOR_SCENE_EXPORTER_GLTF_PLUGIN_H
|
||||
|
||||
#include "packed_scene_gltf.h"
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "editor/editor_plugin.h"
|
||||
#include "editor_scene_importer_gltf.h"
|
||||
|
||||
class SceneExporterGLTFPlugin : public EditorPlugin {
|
||||
GDCLASS(SceneExporterGLTFPlugin, EditorPlugin);
|
||||
|
||||
Ref<PackedSceneGLTF> convert_gltf2;
|
||||
EditorNode *editor = nullptr;
|
||||
EditorFileDialog *file_export_lib = nullptr;
|
||||
void _gltf2_dialog_action(String p_file);
|
||||
void convert_scene_to_gltf2(Variant p_null);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
void convert_scene_to_gltf2();
|
||||
|
||||
public:
|
||||
virtual String get_name() const;
|
||||
bool has_main_screen() const;
|
||||
SceneExporterGLTFPlugin(class EditorNode *p_node);
|
||||
virtual String get_name() const override;
|
||||
bool has_main_screen() const override;
|
||||
SceneExporterGLTFPlugin();
|
||||
};
|
||||
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
#endif // EDITOR_SCENE_EXPORTER_GLTF_PLUGIN_H
|
575
modules/gltf/editor/editor_scene_importer_blend.cpp
Normal file
575
modules/gltf/editor/editor_scene_importer_blend.cpp
Normal file
@ -0,0 +1,575 @@
|
||||
/*************************************************************************/
|
||||
/* editor_scene_importer_blend.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 "editor_scene_importer_blend.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "../gltf_document.h"
|
||||
#include "../gltf_state.h"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "editor/editor_file_dialog.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_scale.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "main/main.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/resources/animation.h"
|
||||
|
||||
#ifdef WINDOWS_ENABLED
|
||||
// Code by Pedro Estebanez (https://github.com/godotengine/godot/pull/59766)
|
||||
#include <shlwapi.h>
|
||||
#endif
|
||||
|
||||
uint32_t EditorSceneFormatImporterBlend::get_import_flags() const {
|
||||
return ImportFlags::IMPORT_SCENE | ImportFlags::IMPORT_ANIMATION;
|
||||
}
|
||||
|
||||
void EditorSceneFormatImporterBlend::get_extensions(List<String> *r_extensions) const {
|
||||
r_extensions->push_back("blend");
|
||||
}
|
||||
|
||||
Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_t p_flags,
|
||||
const HashMap<StringName, Variant> &p_options, int p_bake_fps,
|
||||
List<String> *r_missing_deps, Error *r_err) {
|
||||
// Get global paths for source and sink.
|
||||
|
||||
// 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(
|
||||
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();
|
||||
|
||||
// Handle configuration options.
|
||||
|
||||
String parameters_arg;
|
||||
|
||||
if (p_options.has(SNAME("blender/nodes/custom_properties")) && p_options[SNAME("blender/nodes/custom_properties")]) {
|
||||
parameters_arg += "export_extras=True,";
|
||||
} else {
|
||||
parameters_arg += "export_extras=False,";
|
||||
}
|
||||
if (p_options.has(SNAME("blender/meshes/skins")) && p_options[SNAME("blender/meshes/skins")]) {
|
||||
int32_t skins = p_options["blender/meshes/skins"];
|
||||
if (skins == BLEND_BONE_INFLUENCES_NONE) {
|
||||
parameters_arg += "export_all_influences=False,";
|
||||
} else if (skins == BLEND_BONE_INFLUENCES_COMPATIBLE) {
|
||||
parameters_arg += "export_all_influences=False,";
|
||||
} else if (skins == BLEND_BONE_INFLUENCES_ALL) {
|
||||
parameters_arg += "export_all_influences=True,";
|
||||
}
|
||||
parameters_arg += "export_skins=True,";
|
||||
} else {
|
||||
parameters_arg += "export_skins=False,";
|
||||
}
|
||||
if (p_options.has(SNAME("blender/materials/export_materials")) && p_options[SNAME("blender/materials/export_materials")]) {
|
||||
int32_t exports = p_options["blender/materials/export_materials"];
|
||||
if (exports == BLEND_MATERIAL_EXPORT_PLACEHOLDER) {
|
||||
parameters_arg += "export_materials='PLACEHOLDER',";
|
||||
} else if (exports == BLEND_MATERIAL_EXPORT_EXPORT) {
|
||||
parameters_arg += "export_materials='EXPORT',";
|
||||
}
|
||||
} else {
|
||||
parameters_arg += "export_materials='PLACEHOLDER',";
|
||||
}
|
||||
if (p_options.has(SNAME("blender/nodes/cameras")) && p_options[SNAME("blender/nodes/cameras")]) {
|
||||
parameters_arg += "export_cameras=True,";
|
||||
} else {
|
||||
parameters_arg += "export_cameras=False,";
|
||||
}
|
||||
if (p_options.has(SNAME("blender/nodes/punctual_lights")) && p_options[SNAME("blender/nodes/punctual_lights")]) {
|
||||
parameters_arg += "export_lights=True,";
|
||||
} else {
|
||||
parameters_arg += "export_lights=False,";
|
||||
}
|
||||
if (p_options.has(SNAME("blender/meshes/colors")) && p_options[SNAME("blender/meshes/colors")]) {
|
||||
parameters_arg += "export_colors=True,";
|
||||
} else {
|
||||
parameters_arg += "export_colors=False,";
|
||||
}
|
||||
if (p_options.has(SNAME("blender/nodes/visible")) && p_options[SNAME("blender/nodes/visible")]) {
|
||||
int32_t visible = p_options["blender/nodes/visible"];
|
||||
if (visible == BLEND_VISIBLE_VISIBLE_ONLY) {
|
||||
parameters_arg += "use_visible=True,";
|
||||
} else if (visible == BLEND_VISIBLE_RENDERABLE) {
|
||||
parameters_arg += "use_renderable=True,";
|
||||
} else if (visible == BLEND_VISIBLE_ALL) {
|
||||
parameters_arg += "use_visible=False,use_renderable=False,";
|
||||
}
|
||||
} else {
|
||||
parameters_arg += "use_visible=False,use_renderable=False,";
|
||||
}
|
||||
|
||||
if (p_options.has(SNAME("blender/meshes/uvs")) && p_options[SNAME("blender/meshes/uvs")]) {
|
||||
parameters_arg += "export_texcoords=True,";
|
||||
} else {
|
||||
parameters_arg += "export_texcoords=False,";
|
||||
}
|
||||
if (p_options.has(SNAME("blender/meshes/normals")) && p_options[SNAME("blender/meshes/normals")]) {
|
||||
parameters_arg += "export_normals=True,";
|
||||
} else {
|
||||
parameters_arg += "export_normals=False,";
|
||||
}
|
||||
if (p_options.has(SNAME("blender/meshes/tangents")) && p_options[SNAME("blender/meshes/tangents")]) {
|
||||
parameters_arg += "export_tangents=True,";
|
||||
} else {
|
||||
parameters_arg += "export_tangents=False,";
|
||||
}
|
||||
if (p_options.has(SNAME("blender/animation/group_tracks")) && p_options[SNAME("blender/animation/group_tracks")]) {
|
||||
parameters_arg += "export_nla_strips=True,";
|
||||
} else {
|
||||
parameters_arg += "export_nla_strips=False,";
|
||||
}
|
||||
if (p_options.has(SNAME("blender/animation/limit_playback")) && p_options[SNAME("blender/animation/limit_playback")]) {
|
||||
parameters_arg += "export_frame_range=True,";
|
||||
} else {
|
||||
parameters_arg += "export_frame_range=False,";
|
||||
}
|
||||
if (p_options.has(SNAME("blender/animation/always_sample")) && p_options[SNAME("blender/animation/always_sample")]) {
|
||||
parameters_arg += "export_force_sampling=True,";
|
||||
} else {
|
||||
parameters_arg += "export_force_sampling=False,";
|
||||
}
|
||||
if (p_options.has(SNAME("blender/meshes/export_bones_deforming_mesh_only")) && p_options[SNAME("blender/meshes/export_bones_deforming_mesh_only")]) {
|
||||
parameters_arg += "export_def_bones=True,";
|
||||
} else {
|
||||
parameters_arg += "export_def_bones=False,";
|
||||
}
|
||||
if (p_options.has(SNAME("blender/nodes/modifiers")) && p_options[SNAME("blender/nodes/modifiers")]) {
|
||||
parameters_arg += "export_apply=True";
|
||||
} else {
|
||||
parameters_arg += "export_apply=False";
|
||||
}
|
||||
|
||||
String unpack_all;
|
||||
if (p_options.has(SNAME("blender/materials/unpack_enabled")) && p_options[SNAME("blender/materials/unpack_enabled")]) {
|
||||
unpack_all = "bpy.ops.file.unpack_all(method='USE_LOCAL');";
|
||||
}
|
||||
|
||||
// Prepare Blender export script.
|
||||
|
||||
String common_args = vformat("filepath='%s',", sink_global) +
|
||||
"export_format='GLTF_SEPARATE',"
|
||||
"export_yup=True," +
|
||||
parameters_arg;
|
||||
String script =
|
||||
String("import bpy, sys;") +
|
||||
"print('Blender 3.0 or higher is required.', file=sys.stderr) if bpy.app.version < (3, 0, 0) else None;" +
|
||||
vformat("bpy.ops.wm.open_mainfile(filepath='%s');", source_global) +
|
||||
unpack_all +
|
||||
vformat("bpy.ops.export_scene.gltf(export_keep_originals=True,%s);", common_args);
|
||||
print_verbose(script);
|
||||
|
||||
// Run script with configured Blender binary.
|
||||
|
||||
String blender_path = EDITOR_GET("filesystem/import/blender/blender3_path");
|
||||
|
||||
#ifdef WINDOWS_ENABLED
|
||||
blender_path = blender_path.plus_file("blender.exe");
|
||||
#else
|
||||
blender_path = blender_path.plus_file("blender");
|
||||
#endif
|
||||
|
||||
List<String> args;
|
||||
args.push_back("--background");
|
||||
args.push_back("--python-expr");
|
||||
args.push_back(script);
|
||||
|
||||
String standard_out;
|
||||
int ret;
|
||||
OS::get_singleton()->execute(blender_path, args, &standard_out, &ret, true);
|
||||
print_verbose(blender_path);
|
||||
print_verbose(standard_out);
|
||||
|
||||
if (ret != 0) {
|
||||
if (r_err) {
|
||||
*r_err = ERR_SCRIPT_FAILED;
|
||||
}
|
||||
ERR_PRINT(vformat("Blend export to glTF failed with error: %d.", ret));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Import the generated glTF.
|
||||
|
||||
// Use GLTFDocument instead of glTF importer to keep image references.
|
||||
Ref<GLTFDocument> gltf;
|
||||
gltf.instantiate();
|
||||
Ref<GLTFState> state;
|
||||
state.instantiate();
|
||||
String base_dir;
|
||||
if (p_options.has(SNAME("blender/materials/unpack_enabled")) && p_options[SNAME("blender/materials/unpack_enabled")]) {
|
||||
base_dir = sink.get_base_dir();
|
||||
}
|
||||
Error err = gltf->append_from_file(sink.get_basename() + ".gltf", state, p_flags, p_bake_fps, base_dir);
|
||||
if (err != OK) {
|
||||
if (r_err) {
|
||||
*r_err = FAILED;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
return gltf->generate_scene(state, p_bake_fps);
|
||||
}
|
||||
|
||||
Variant EditorSceneFormatImporterBlend::get_option_visibility(const String &p_path, bool p_for_animation, const String &p_option,
|
||||
const HashMap<StringName, Variant> &p_options) {
|
||||
if (p_path.get_extension().to_lower() != "blend") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (p_option.begins_with("animation/")) {
|
||||
if (p_option != "animation/import" && !bool(p_options["animation/import"])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditorSceneFormatImporterBlend::get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options) {
|
||||
if (p_path.get_extension().to_lower() != "blend") {
|
||||
return;
|
||||
}
|
||||
#define ADD_OPTION_BOOL(PATH, VALUE) \
|
||||
r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, SNAME(PATH)), VALUE));
|
||||
#define ADD_OPTION_ENUM(PATH, ENUM_HINT, VALUE) \
|
||||
r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, SNAME(PATH), PROPERTY_HINT_ENUM, ENUM_HINT), VALUE));
|
||||
|
||||
ADD_OPTION_ENUM("blender/nodes/visible", "Visible Only,Renderable,All", BLEND_VISIBLE_ALL);
|
||||
ADD_OPTION_BOOL("blender/nodes/punctual_lights", true);
|
||||
ADD_OPTION_BOOL("blender/nodes/cameras", true);
|
||||
ADD_OPTION_BOOL("blender/nodes/custom_properties", true);
|
||||
ADD_OPTION_ENUM("blender/nodes/modifiers", "No Modifiers,All Modifiers", BLEND_MODIFIERS_ALL);
|
||||
ADD_OPTION_BOOL("blender/meshes/colors", false);
|
||||
ADD_OPTION_BOOL("blender/meshes/uvs", true);
|
||||
ADD_OPTION_BOOL("blender/meshes/normals", true);
|
||||
ADD_OPTION_BOOL("blender/meshes/tangents", true);
|
||||
ADD_OPTION_ENUM("blender/meshes/skins", "None,4 Influences (Compatible),All Influences", BLEND_BONE_INFLUENCES_ALL);
|
||||
ADD_OPTION_BOOL("blender/meshes/export_bones_deforming_mesh_only", false);
|
||||
ADD_OPTION_BOOL("blender/materials/unpack_enabled", true);
|
||||
ADD_OPTION_ENUM("blender/materials/export_materials", "Placeholder,Export", BLEND_MATERIAL_EXPORT_EXPORT);
|
||||
ADD_OPTION_BOOL("blender/animation/limit_playback", true);
|
||||
ADD_OPTION_BOOL("blender/animation/always_sample", true);
|
||||
ADD_OPTION_BOOL("blender/animation/group_tracks", true);
|
||||
|
||||
#undef ADD_OPTION_BOOL
|
||||
#undef ADD_OPTION_ENUM
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
|
||||
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");
|
||||
#else
|
||||
path = path.plus_file("blender");
|
||||
#endif
|
||||
|
||||
#if defined(MACOS_ENABLED)
|
||||
if (!FileAccess::exists(path)) {
|
||||
path = path.plus_file("Blender");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!FileAccess::exists(path)) {
|
||||
if (r_err) {
|
||||
*r_err = TTR("Path does not contain a Blender installation.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
List<String> args;
|
||||
args.push_back("--version");
|
||||
String pipe;
|
||||
Error err = OS::get_singleton()->execute(path, args, &pipe);
|
||||
if (err != OK) {
|
||||
if (r_err) {
|
||||
*r_err = TTR("Can't execute Blender binary.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pipe.find("Blender ") != 0) {
|
||||
if (r_err) {
|
||||
*r_err = vformat(TTR("Unexpected --version output from Blender binary at: %s"), path);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
pipe = pipe.replace_first("Blender ", "");
|
||||
int pp = pipe.find(".");
|
||||
if (pp == -1) {
|
||||
if (r_err) {
|
||||
*r_err = TTR("Path supplied lacks a Blender binary.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
String v = pipe.substr(0, pp);
|
||||
int version = v.to_int();
|
||||
if (version < 3) {
|
||||
if (r_err) {
|
||||
*r_err = TTR("This Blender installation is too old for this importer (not 3.0+).");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (version > 3) {
|
||||
if (r_err) {
|
||||
*r_err = TTR("This Blender installation is too new for this importer (not 3.x).");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EditorFileSystemImportFormatSupportQueryBlend::is_active() const {
|
||||
bool blend_enabled = GLOBAL_GET("filesystem/import/blender/enabled");
|
||||
|
||||
String blender_path = EDITOR_GET("filesystem/import/blender/blender3_path");
|
||||
|
||||
if (blend_enabled && !_test_blender_path(blender_path)) {
|
||||
// Intending to import Blender, but blend not configured.
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
Vector<String> EditorFileSystemImportFormatSupportQueryBlend::get_file_extensions() const {
|
||||
Vector<String> ret;
|
||||
ret.push_back("blend");
|
||||
return ret;
|
||||
}
|
||||
|
||||
void EditorFileSystemImportFormatSupportQueryBlend::_validate_path(String p_path) {
|
||||
String error;
|
||||
bool success = false;
|
||||
if (p_path == "") {
|
||||
error = TTR("Path is empty.");
|
||||
} else {
|
||||
if (_test_blender_path(p_path, &error)) {
|
||||
success = true;
|
||||
if (auto_detected_path == p_path) {
|
||||
error = TTR("Path to Blender installation is valid (Autodetected).");
|
||||
} else {
|
||||
error = TTR("Path to Blender installation is valid.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
path_status->set_text(error);
|
||||
|
||||
if (success) {
|
||||
path_status->add_theme_color_override("font_color", path_status->get_theme_color(SNAME("success_color"), SNAME("Editor")));
|
||||
configure_blender_dialog->get_ok_button()->set_disabled(false);
|
||||
} else {
|
||||
path_status->add_theme_color_override("font_color", path_status->get_theme_color(SNAME("error_color"), SNAME("Editor")));
|
||||
configure_blender_dialog->get_ok_button()->set_disabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorFileSystemImportFormatSupportQueryBlend::_autodetect_path(String p_path) {
|
||||
if (_test_blender_path(p_path)) {
|
||||
auto_detected_path = p_path;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void EditorFileSystemImportFormatSupportQueryBlend::_path_confirmed() {
|
||||
confirmed = true;
|
||||
}
|
||||
|
||||
void EditorFileSystemImportFormatSupportQueryBlend::_select_install(String p_path) {
|
||||
blender_path->set_text(p_path);
|
||||
_validate_path(p_path);
|
||||
}
|
||||
void EditorFileSystemImportFormatSupportQueryBlend::_browse_install() {
|
||||
if (blender_path->get_text() != String()) {
|
||||
browse_dialog->set_current_dir(blender_path->get_text());
|
||||
}
|
||||
|
||||
browse_dialog->popup_centered_ratio();
|
||||
}
|
||||
|
||||
bool EditorFileSystemImportFormatSupportQueryBlend::query() {
|
||||
if (!configure_blender_dialog) {
|
||||
configure_blender_dialog = memnew(ConfirmationDialog);
|
||||
configure_blender_dialog->set_title(TTR("Configure Blender Importer"));
|
||||
configure_blender_dialog->set_flag(Window::FLAG_BORDERLESS, true); // Avoid closing accidentally .
|
||||
configure_blender_dialog->set_close_on_escape(false);
|
||||
|
||||
VBoxContainer *vb = memnew(VBoxContainer);
|
||||
vb->add_child(memnew(Label(TTR("Blender 3.0+ is required to import '.blend' files.\nPlease provide a valid path to a Blender installation:"))));
|
||||
|
||||
HBoxContainer *hb = memnew(HBoxContainer);
|
||||
|
||||
blender_path = memnew(LineEdit);
|
||||
blender_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
hb->add_child(blender_path);
|
||||
blender_path_browse = memnew(Button);
|
||||
hb->add_child(blender_path_browse);
|
||||
blender_path_browse->set_text(TTR("Browse"));
|
||||
blender_path_browse->connect("pressed", callable_mp(this, &EditorFileSystemImportFormatSupportQueryBlend::_browse_install));
|
||||
hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
hb->set_custom_minimum_size(Size2(400 * EDSCALE, 0));
|
||||
|
||||
vb->add_child(hb);
|
||||
|
||||
path_status = memnew(Label);
|
||||
vb->add_child(path_status);
|
||||
|
||||
configure_blender_dialog->add_child(vb);
|
||||
|
||||
blender_path->connect("text_changed", callable_mp(this, &EditorFileSystemImportFormatSupportQueryBlend::_validate_path));
|
||||
|
||||
EditorNode::get_singleton()->get_gui_base()->add_child(configure_blender_dialog);
|
||||
|
||||
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(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);
|
||||
browse_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
|
||||
browse_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
|
||||
browse_dialog->connect("dir_selected", callable_mp(this, &EditorFileSystemImportFormatSupportQueryBlend::_select_install));
|
||||
|
||||
EditorNode::get_singleton()->get_gui_base()->add_child(browse_dialog);
|
||||
}
|
||||
|
||||
String path = EDITOR_GET("filesystem/import/blender/blender3_path");
|
||||
|
||||
if (path == "") {
|
||||
// Autodetect
|
||||
auto_detected_path = "";
|
||||
|
||||
#if defined(MACOS_ENABLED)
|
||||
|
||||
{
|
||||
Vector<String> mdfind_paths;
|
||||
{
|
||||
List<String> mdfind_args;
|
||||
mdfind_args.push_back("kMDItemCFBundleIdentifier=org.blenderfoundation.blender");
|
||||
|
||||
String output;
|
||||
Error err = OS::get_singleton()->execute("mdfind", mdfind_args, &output);
|
||||
if (err == OK) {
|
||||
mdfind_paths = output.split("\n");
|
||||
}
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
for (const String &path : mdfind_paths) {
|
||||
found = _autodetect_path(path.plus_file("Contents/MacOS"));
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
found = _autodetect_path("/opt/homebrew/bin");
|
||||
}
|
||||
if (!found) {
|
||||
found = _autodetect_path("/opt/local/bin");
|
||||
}
|
||||
if (!found) {
|
||||
found = _autodetect_path("/usr/local/bin");
|
||||
}
|
||||
if (!found) {
|
||||
found = _autodetect_path("/usr/local/opt");
|
||||
}
|
||||
if (!found) {
|
||||
found = _autodetect_path("/Applications/Blender.app/Contents/MacOS");
|
||||
}
|
||||
}
|
||||
#elif defined(WINDOWS_ENABLED)
|
||||
{
|
||||
char blender_opener_path[MAX_PATH];
|
||||
DWORD path_len = MAX_PATH;
|
||||
HRESULT res = AssocQueryString(0, ASSOCSTR_EXECUTABLE, ".blend", "open", blender_opener_path, &path_len);
|
||||
if (res == S_OK && _autodetect_path(String(blender_opener_path).get_base_dir())) {
|
||||
// Good.
|
||||
} else if (_autodetect_path("C:\\Program Files\\Blender Foundation")) {
|
||||
// Good.
|
||||
} else {
|
||||
_autodetect_path("C:\\Program Files (x86)\\Blender Foundation");
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(UNIX_ENABLED)
|
||||
if (_autodetect_path("/usr/bin")) {
|
||||
// Good.
|
||||
} else if (_autodetect_path("/usr/local/bin")) {
|
||||
// Good
|
||||
} else {
|
||||
_autodetect_path("/opt/blender/bin");
|
||||
}
|
||||
#endif
|
||||
if (auto_detected_path != "") {
|
||||
path = auto_detected_path;
|
||||
}
|
||||
}
|
||||
|
||||
blender_path->set_text(path);
|
||||
|
||||
_validate_path(path);
|
||||
|
||||
configure_blender_dialog->popup_centered();
|
||||
confirmed = false;
|
||||
|
||||
while (true) {
|
||||
OS::get_singleton()->delay_usec(1);
|
||||
DisplayServer::get_singleton()->process_events();
|
||||
Main::iteration();
|
||||
if (!configure_blender_dialog->is_visible() || confirmed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (confirmed) {
|
||||
// Can only confirm a valid path.
|
||||
EditorSettings::get_singleton()->set("filesystem/import/blender/blender3_path", blender_path->get_text());
|
||||
EditorSettings::get_singleton()->save();
|
||||
} else {
|
||||
// Disable Blender import
|
||||
ProjectSettings::get_singleton()->set("filesystem/import/blender/enabled", false);
|
||||
ProjectSettings::get_singleton()->save();
|
||||
|
||||
if (EditorNode::immediate_confirmation_dialog(TTR("Disabling '.blend' file import requires restarting the editor."), TTR("Save & Restart"), TTR("Restart"))) {
|
||||
EditorNode::get_singleton()->save_all_scenes();
|
||||
}
|
||||
EditorNode::get_singleton()->restart_editor();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
EditorFileSystemImportFormatSupportQueryBlend::EditorFileSystemImportFormatSupportQueryBlend() {
|
||||
}
|
||||
|
||||
#endif // TOOLS_ENABLED
|
112
modules/gltf/editor/editor_scene_importer_blend.h
Normal file
112
modules/gltf/editor/editor_scene_importer_blend.h
Normal file
@ -0,0 +1,112 @@
|
||||
/*************************************************************************/
|
||||
/* editor_scene_importer_blend.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 EDITOR_SCENE_IMPORTER_BLEND_H
|
||||
#define EDITOR_SCENE_IMPORTER_BLEND_H
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "editor/editor_file_system.h"
|
||||
#include "editor/import/resource_importer_scene.h"
|
||||
|
||||
class Animation;
|
||||
class Node;
|
||||
class ConfirmationDialog;
|
||||
|
||||
class EditorSceneFormatImporterBlend : public EditorSceneFormatImporter {
|
||||
GDCLASS(EditorSceneFormatImporterBlend, EditorSceneFormatImporter);
|
||||
|
||||
public:
|
||||
enum {
|
||||
BLEND_VISIBLE_VISIBLE_ONLY,
|
||||
BLEND_VISIBLE_RENDERABLE,
|
||||
BLEND_VISIBLE_ALL
|
||||
};
|
||||
enum {
|
||||
BLEND_BONE_INFLUENCES_NONE,
|
||||
BLEND_BONE_INFLUENCES_COMPATIBLE,
|
||||
BLEND_BONE_INFLUENCES_ALL
|
||||
};
|
||||
enum {
|
||||
BLEND_MATERIAL_EXPORT_PLACEHOLDER,
|
||||
BLEND_MATERIAL_EXPORT_EXPORT
|
||||
};
|
||||
enum {
|
||||
BLEND_MODIFIERS_NONE,
|
||||
BLEND_MODIFIERS_ALL
|
||||
};
|
||||
|
||||
virtual uint32_t get_import_flags() const override;
|
||||
virtual void get_extensions(List<String> *r_extensions) const override;
|
||||
virtual Node *import_scene(const String &p_path, uint32_t p_flags,
|
||||
const HashMap<StringName, Variant> &p_options, int p_bake_fps,
|
||||
List<String> *r_missing_deps, Error *r_err = nullptr) override;
|
||||
virtual void get_import_options(const String &p_path,
|
||||
List<ResourceImporter::ImportOption> *r_options) override;
|
||||
virtual Variant get_option_visibility(const String &p_path, bool p_for_animation, const String &p_option,
|
||||
const HashMap<StringName, Variant> &p_options) override;
|
||||
};
|
||||
|
||||
class LineEdit;
|
||||
class Button;
|
||||
class EditorFileDialog;
|
||||
class Label;
|
||||
|
||||
class EditorFileSystemImportFormatSupportQueryBlend : public EditorFileSystemImportFormatSupportQuery {
|
||||
GDCLASS(EditorFileSystemImportFormatSupportQueryBlend, EditorFileSystemImportFormatSupportQuery);
|
||||
|
||||
ConfirmationDialog *configure_blender_dialog = nullptr;
|
||||
LineEdit *blender_path = nullptr;
|
||||
Button *blender_path_browse = nullptr;
|
||||
EditorFileDialog *browse_dialog = nullptr;
|
||||
Label *path_status = nullptr;
|
||||
bool confirmed = false;
|
||||
|
||||
String auto_detected_path;
|
||||
void _validate_path(String p_path);
|
||||
|
||||
bool _autodetect_path(String p_path);
|
||||
|
||||
void _path_confirmed();
|
||||
|
||||
void _select_install(String p_path);
|
||||
void _browse_install();
|
||||
|
||||
public:
|
||||
virtual bool is_active() const override;
|
||||
virtual Vector<String> get_file_extensions() const override;
|
||||
virtual bool query() override;
|
||||
|
||||
EditorFileSystemImportFormatSupportQueryBlend();
|
||||
};
|
||||
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
#endif // EDITOR_SCENE_IMPORTER_BLEND_H
|
117
modules/gltf/editor/editor_scene_importer_fbx.cpp
Normal file
117
modules/gltf/editor/editor_scene_importer_fbx.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
/*************************************************************************/
|
||||
/* editor_scene_importer_fbx.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 "editor_scene_importer_fbx.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "../gltf_document.h"
|
||||
#include "../gltf_state.h"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/resources/animation.h"
|
||||
|
||||
uint32_t EditorSceneFormatImporterFBX::get_import_flags() const {
|
||||
return ImportFlags::IMPORT_SCENE | ImportFlags::IMPORT_ANIMATION;
|
||||
}
|
||||
|
||||
void EditorSceneFormatImporterFBX::get_extensions(List<String> *r_extensions) const {
|
||||
r_extensions->push_back("fbx");
|
||||
}
|
||||
|
||||
Node *EditorSceneFormatImporterFBX::import_scene(const String &p_path, uint32_t p_flags,
|
||||
const HashMap<StringName, Variant> &p_options, int p_bake_fps,
|
||||
List<String> *r_missing_deps, Error *r_err) {
|
||||
// Get global paths for source and sink.
|
||||
|
||||
// Don't use `c_escape()` as it can generate broken paths. These paths will be
|
||||
// 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(
|
||||
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();
|
||||
|
||||
// Run fbx2gltf.
|
||||
|
||||
String fbx2gltf_path = EDITOR_GET("filesystem/import/fbx/fbx2gltf_path");
|
||||
|
||||
List<String> args;
|
||||
args.push_back("--pbr-metallic-roughness");
|
||||
args.push_back("--input");
|
||||
args.push_back(source_global);
|
||||
args.push_back("--output");
|
||||
args.push_back(sink_global);
|
||||
args.push_back("--binary");
|
||||
|
||||
String standard_out;
|
||||
int ret;
|
||||
OS::get_singleton()->execute(fbx2gltf_path, args, &standard_out, &ret, true);
|
||||
print_verbose(fbx2gltf_path);
|
||||
print_verbose(standard_out);
|
||||
|
||||
if (ret != 0) {
|
||||
if (r_err) {
|
||||
*r_err = ERR_SCRIPT_FAILED;
|
||||
}
|
||||
ERR_PRINT(vformat("FBX conversion to glTF failed with error: %d.", ret));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Import the generated glTF.
|
||||
|
||||
// Use GLTFDocument instead of glTF importer to keep image references.
|
||||
Ref<GLTFDocument> gltf;
|
||||
gltf.instantiate();
|
||||
Ref<GLTFState> state;
|
||||
state.instantiate();
|
||||
print_verbose(vformat("glTF path: %s", sink));
|
||||
Error err = gltf->append_from_file(sink, state, p_flags, p_bake_fps);
|
||||
if (err != OK) {
|
||||
if (r_err) {
|
||||
*r_err = FAILED;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
return gltf->generate_scene(state, p_bake_fps);
|
||||
}
|
||||
|
||||
Variant EditorSceneFormatImporterFBX::get_option_visibility(const String &p_path, bool p_for_animation,
|
||||
const String &p_option, const HashMap<StringName, Variant> &p_options) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditorSceneFormatImporterFBX::get_import_options(const String &p_path,
|
||||
List<ResourceImporter::ImportOption> *r_options) {
|
||||
}
|
||||
|
||||
#endif // TOOLS_ENABLED
|
@ -1,7 +1,5 @@
|
||||
#ifndef PACKED_SCENE_GLTF_H
|
||||
#define PACKED_SCENE_GLTF_H
|
||||
/*************************************************************************/
|
||||
/* packed_scene_gltf.h */
|
||||
/* editor_scene_importer_fbx.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
@ -30,36 +28,31 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef EDITOR_SCENE_IMPORTER_FBX_H
|
||||
#define EDITOR_SCENE_IMPORTER_FBX_H
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/resources/packed_scene.h"
|
||||
#include "editor/import/resource_importer_scene.h"
|
||||
|
||||
#include "gltf_state.h"
|
||||
class Animation;
|
||||
class Node;
|
||||
|
||||
class PackedSceneGLTF : public PackedScene {
|
||||
GDCLASS(PackedSceneGLTF, PackedScene);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
class EditorSceneFormatImporterFBX : public EditorSceneFormatImporter {
|
||||
GDCLASS(EditorSceneFormatImporterFBX, EditorSceneFormatImporter);
|
||||
|
||||
public:
|
||||
virtual void save_scene(Node *p_node, const String &p_path, const String &p_src_path,
|
||||
uint32_t p_flags, int p_bake_fps,
|
||||
List<String> *r_missing_deps, Error *r_err = nullptr);
|
||||
virtual void _build_parent_hierachy(Ref<GLTFState> state);
|
||||
virtual Error export_gltf(Node *p_root, String p_path, int32_t p_flags = 0,
|
||||
real_t p_bake_fps = 1000.0f);
|
||||
virtual uint32_t get_import_flags() const override;
|
||||
virtual void get_extensions(List<String> *r_extensions) const override;
|
||||
virtual Node *import_scene(const String &p_path, uint32_t p_flags,
|
||||
int p_bake_fps, uint32_t p_compress_flags,
|
||||
List<String> *r_missing_deps,
|
||||
Error *r_err,
|
||||
Ref<GLTFState> r_state);
|
||||
virtual Node *import_gltf_scene(const String &p_path, uint32_t p_flags, float p_bake_fps, uint32_t p_compress_flags, Ref<GLTFState> r_state = Ref<GLTFState>());
|
||||
virtual void pack_gltf(String p_path, int32_t p_flags = 0,
|
||||
real_t p_bake_fps = 1000.0f, uint32_t p_compress_flags = Mesh::ARRAY_COMPRESS_DEFAULT, Ref<GLTFState> r_state = Ref<GLTFState>());
|
||||
const HashMap<StringName, Variant> &p_options, int p_bake_fps,
|
||||
List<String> *r_missing_deps, Error *r_err = nullptr) override;
|
||||
virtual void get_import_options(const String &p_path,
|
||||
List<ResourceImporter::ImportOption> *r_options) override;
|
||||
virtual Variant get_option_visibility(const String &p_path, bool p_for_animation, const String &p_option,
|
||||
const HashMap<StringName, Variant> &p_options) override;
|
||||
};
|
||||
|
||||
#endif // PACKED_SCENE_GLTF_H
|
||||
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
#endif // EDITOR_SCENE_IMPORTER_FBX_H
|
@ -31,34 +31,36 @@
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "editor_scene_importer_gltf.h"
|
||||
|
||||
#include "../gltf_document.h"
|
||||
#include "../gltf_state.h"
|
||||
|
||||
#include "scene/resources/animation.h"
|
||||
#include "scene/resources/skin.h"
|
||||
|
||||
#include "gltf_state.h"
|
||||
#include "packed_scene_gltf.h"
|
||||
|
||||
uint32_t EditorSceneImporterGLTF::get_import_flags() const {
|
||||
uint32_t EditorSceneFormatImporterGLTF::get_import_flags() const {
|
||||
return ImportFlags::IMPORT_SCENE | ImportFlags::IMPORT_ANIMATION;
|
||||
}
|
||||
|
||||
void EditorSceneImporterGLTF::get_extensions(List<String> *r_extensions) const {
|
||||
void EditorSceneFormatImporterGLTF::get_extensions(List<String> *r_extensions) const {
|
||||
r_extensions->push_back("gltf");
|
||||
r_extensions->push_back("glb");
|
||||
}
|
||||
|
||||
Node *EditorSceneImporterGLTF::import_scene(const String &p_path,
|
||||
uint32_t p_flags, int p_bake_fps, uint32_t p_compress_flags,
|
||||
List<String> *r_missing_deps,
|
||||
Error *r_err) {
|
||||
Ref<PackedSceneGLTF> importer;
|
||||
importer.instance();
|
||||
return importer->import_scene(p_path, p_flags, p_bake_fps, p_compress_flags, r_missing_deps, r_err, Ref<GLTFState>());
|
||||
}
|
||||
|
||||
Ref<Animation> EditorSceneImporterGLTF::import_animation(const String &p_path,
|
||||
uint32_t p_flags,
|
||||
int p_bake_fps) {
|
||||
return Ref<Animation>();
|
||||
Node *EditorSceneFormatImporterGLTF::import_scene(const String &p_path, uint32_t p_flags,
|
||||
const HashMap<StringName, Variant> &p_options, int p_bake_fps,
|
||||
List<String> *r_missing_deps, Error *r_err) {
|
||||
Ref<GLTFDocument> doc;
|
||||
doc.instantiate();
|
||||
Ref<GLTFState> state;
|
||||
state.instantiate();
|
||||
Error err = doc->append_from_file(p_path, state, p_flags, p_bake_fps);
|
||||
if (err != OK) {
|
||||
if (r_err) {
|
||||
*r_err = err;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
return doc->generate_scene(state, p_bake_fps);
|
||||
}
|
||||
|
||||
#endif // TOOLS_ENABLED
|
@ -1,5 +1,3 @@
|
||||
#ifndef EDITOR_SCENE_IMPORTER_GLTF_H
|
||||
#define EDITOR_SCENE_IMPORTER_GLTF_H
|
||||
/*************************************************************************/
|
||||
/* editor_scene_importer_gltf.h */
|
||||
/*************************************************************************/
|
||||
@ -30,27 +28,30 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef EDITOR_SCENE_IMPORTER_GLTF_H
|
||||
#define EDITOR_SCENE_IMPORTER_GLTF_H
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "../gltf_document_extension.h"
|
||||
#include "../gltf_state.h"
|
||||
|
||||
#include "editor/import/resource_importer_scene.h"
|
||||
|
||||
#include "gltf_document.h"
|
||||
#include "gltf_state.h"
|
||||
class Animation;
|
||||
class Node;
|
||||
|
||||
class EditorSceneImporterGLTF : public EditorSceneImporter {
|
||||
GDCLASS(EditorSceneImporterGLTF, EditorSceneImporter);
|
||||
class EditorSceneFormatImporterGLTF : public EditorSceneFormatImporter {
|
||||
GDCLASS(EditorSceneFormatImporterGLTF, EditorSceneFormatImporter);
|
||||
|
||||
public:
|
||||
virtual uint32_t get_import_flags() const;
|
||||
virtual void get_extensions(List<String> *r_extensions) const;
|
||||
virtual uint32_t get_import_flags() const override;
|
||||
virtual void get_extensions(List<String> *r_extensions) const override;
|
||||
virtual Node *import_scene(const String &p_path, uint32_t p_flags,
|
||||
int p_bake_fps, uint32_t p_compress_flags,
|
||||
List<String> *r_missing_deps = nullptr,
|
||||
Error *r_err = nullptr);
|
||||
virtual Ref<Animation> import_animation(const String &p_path,
|
||||
uint32_t p_flags, int p_bake_fps);
|
||||
const HashMap<StringName, Variant> &p_options, int p_bake_fps,
|
||||
List<String> *r_missing_deps, Error *r_err = nullptr) override;
|
||||
};
|
||||
|
||||
#endif // EDITOR_SCENE_IMPORTER_GLTF_H
|
||||
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
#endif // EDITOR_SCENE_IMPORTER_GLTF_H
|
@ -35,8 +35,8 @@ void GLTFLight::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_color", "color"), &GLTFLight::set_color);
|
||||
ClassDB::bind_method(D_METHOD("get_intensity"), &GLTFLight::get_intensity);
|
||||
ClassDB::bind_method(D_METHOD("set_intensity", "intensity"), &GLTFLight::set_intensity);
|
||||
ClassDB::bind_method(D_METHOD("get_type"), &GLTFLight::get_type);
|
||||
ClassDB::bind_method(D_METHOD("set_type", "type"), &GLTFLight::set_type);
|
||||
ClassDB::bind_method(D_METHOD("get_light_type"), &GLTFLight::get_light_type);
|
||||
ClassDB::bind_method(D_METHOD("set_light_type", "light_type"), &GLTFLight::set_light_type);
|
||||
ClassDB::bind_method(D_METHOD("get_range"), &GLTFLight::get_range);
|
||||
ClassDB::bind_method(D_METHOD("set_range", "range"), &GLTFLight::set_range);
|
||||
ClassDB::bind_method(D_METHOD("get_inner_cone_angle"), &GLTFLight::get_inner_cone_angle);
|
||||
@ -45,11 +45,11 @@ void GLTFLight::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_outer_cone_angle", "outer_cone_angle"), &GLTFLight::set_outer_cone_angle);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color"); // Color
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "intensity"), "set_intensity", "get_intensity"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "type"), "set_type", "get_type"); // String
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "range"), "set_range", "get_range"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "inner_cone_angle"), "set_inner_cone_angle", "get_inner_cone_angle"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "outer_cone_angle"), "set_outer_cone_angle", "get_outer_cone_angle"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "intensity"), "set_intensity", "get_intensity"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "light_type"), "set_light_type", "get_light_type"); // String
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "range"), "set_range", "get_range"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inner_cone_angle"), "set_inner_cone_angle", "get_inner_cone_angle"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "outer_cone_angle"), "set_outer_cone_angle", "get_outer_cone_angle"); // float
|
||||
}
|
||||
|
||||
Color GLTFLight::get_color() {
|
||||
@ -68,12 +68,12 @@ void GLTFLight::set_intensity(float p_intensity) {
|
||||
intensity = p_intensity;
|
||||
}
|
||||
|
||||
String GLTFLight::get_type() {
|
||||
return type;
|
||||
String GLTFLight::get_light_type() {
|
||||
return light_type;
|
||||
}
|
||||
|
||||
void GLTFLight::set_type(String p_type) {
|
||||
type = p_type;
|
||||
void GLTFLight::set_light_type(String p_light_type) {
|
||||
light_type = p_light_type;
|
||||
}
|
||||
|
||||
float GLTFLight::get_range() {
|
@ -1,5 +1,3 @@
|
||||
#ifndef GLTF_LIGHT_H
|
||||
#define GLTF_LIGHT_H
|
||||
/*************************************************************************/
|
||||
/* gltf_light.h */
|
||||
/*************************************************************************/
|
||||
@ -30,7 +28,12 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/resource.h"
|
||||
#ifndef GLTF_LIGHT_H
|
||||
#define GLTF_LIGHT_H
|
||||
|
||||
#include "core/config/engine.h"
|
||||
#include "core/io/resource.h"
|
||||
#include "scene/3d/light_3d.h"
|
||||
|
||||
class GLTFLight : public Resource {
|
||||
GDCLASS(GLTFLight, Resource)
|
||||
@ -42,7 +45,7 @@ protected:
|
||||
private:
|
||||
Color color = Color(1.0f, 1.0f, 1.0f);
|
||||
float intensity = 1.0f;
|
||||
String type;
|
||||
String light_type;
|
||||
float range = INFINITY;
|
||||
float inner_cone_angle = 0.0f;
|
||||
float outer_cone_angle = Math_TAU / 8.0f;
|
||||
@ -54,8 +57,8 @@ public:
|
||||
float get_intensity();
|
||||
void set_intensity(float p_intensity);
|
||||
|
||||
String get_type();
|
||||
void set_type(String p_type);
|
||||
String get_light_type();
|
||||
void set_light_type(String p_light_type);
|
||||
|
||||
float get_range();
|
||||
void set_range(float p_range);
|
@ -44,7 +44,7 @@ void GLTFSpecGloss::_bind_methods() {
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "diffuse_img"), "set_diffuse_img", "get_diffuse_img"); // Ref<Image>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "diffuse_factor"), "set_diffuse_factor", "get_diffuse_factor"); // Color
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "gloss_factor"), "set_gloss_factor", "get_gloss_factor"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gloss_factor"), "set_gloss_factor", "get_gloss_factor"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "specular_factor"), "set_specular_factor", "get_specular_factor"); // Color
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "spec_gloss_img"), "set_spec_gloss_img", "get_spec_gloss_img"); // Ref<Image>
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
#ifndef GLTF_SPEC_GLOSS_H
|
||||
#define GLTF_SPEC_GLOSS_H
|
||||
/*************************************************************************/
|
||||
/* gltf_spec_gloss.h */
|
||||
/*************************************************************************/
|
||||
@ -30,8 +28,11 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/image.h"
|
||||
#include "core/resource.h"
|
||||
#ifndef GLTF_SPEC_GLOSS_H
|
||||
#define GLTF_SPEC_GLOSS_H
|
||||
|
||||
#include "core/io/image.h"
|
||||
#include "core/io/resource.h"
|
||||
|
||||
class GLTFSpecGloss : public Resource {
|
||||
GDCLASS(GLTFSpecGloss, Resource);
|
87
modules/gltf/gltf_defines.h
Normal file
87
modules/gltf/gltf_defines.h
Normal file
@ -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
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,3 @@
|
||||
#ifndef GLTF_DOCUMENT_H
|
||||
#define GLTF_DOCUMENT_H
|
||||
/*************************************************************************/
|
||||
/* gltf_document.h */
|
||||
/*************************************************************************/
|
||||
@ -30,61 +28,30 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "scene/3d/bone_attachment.h"
|
||||
#include "scene/3d/camera.h"
|
||||
#include "scene/3d/light.h"
|
||||
#include "scene/3d/mesh_instance.h"
|
||||
#include "scene/3d/skeleton.h"
|
||||
#include "scene/3d/spatial.h"
|
||||
#ifndef GLTF_DOCUMENT_H
|
||||
#define GLTF_DOCUMENT_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/mesh_instance_3d.h"
|
||||
#include "scene/animation/animation_player.h"
|
||||
#include "scene/resources/material.h"
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
#include "gltf_animation.h"
|
||||
|
||||
#include "modules/modules_enabled.gen.h" // For csg, gridmap.
|
||||
|
||||
class GLTFState;
|
||||
class GLTFSkin;
|
||||
class GLTFNode;
|
||||
class GLTFSpecGloss;
|
||||
class GLTFSkeleton;
|
||||
class MultiMeshInstance;
|
||||
|
||||
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:
|
||||
const float BAKE_FPS = 30.0f;
|
||||
|
||||
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,
|
||||
@ -105,78 +72,34 @@ public:
|
||||
COMPONENT_TYPE_FLOAT = 5126,
|
||||
};
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_extensions(TypedArray<GLTFDocumentExtension> p_extensions);
|
||||
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 Set<T> &p_inp) {
|
||||
Array ret;
|
||||
typename Set<T>::Element *elem = p_inp.front();
|
||||
while (elem) {
|
||||
ret.push_back(elem->get());
|
||||
elem = elem->next();
|
||||
}
|
||||
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(Set<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 Map<K, V> &p_inp) {
|
||||
Dictionary ret;
|
||||
for (typename Map<K, V>::Element *E = p_inp.front(); E; E = E->next()) {
|
||||
ret[E->key()] = E->value();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <class K, class V>
|
||||
static void set_from_dict(Map<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);
|
||||
int _get_component_type_size(const int component_type);
|
||||
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);
|
||||
String _sanitize_bone_name(Ref<GLTFState> state, const String &name);
|
||||
String _sanitize_bone_name(const String &name);
|
||||
String _gen_unique_bone_name(Ref<GLTFState> state,
|
||||
const GLTFSkeletonIndex skel_i,
|
||||
const String &p_name);
|
||||
GLTFTextureIndex _set_texture(Ref<GLTFState> state, Ref<Texture> p_texture);
|
||||
Ref<Texture> _get_texture(Ref<GLTFState> state,
|
||||
GLTFTextureIndex _set_texture(Ref<GLTFState> state, Ref<Texture2D> p_texture);
|
||||
Ref<Texture2D> _get_texture(Ref<GLTFState> state,
|
||||
const GLTFTextureIndex p_texture);
|
||||
Error _parse_json(const String &p_path, Ref<GLTFState> state);
|
||||
Error _parse_glb(const String &p_path, Ref<GLTFState> state);
|
||||
Error _parse_glb(Ref<FileAccess> f, Ref<GLTFState> state);
|
||||
void _compute_node_heights(Ref<GLTFState> state);
|
||||
Error _parse_buffers(Ref<GLTFState> state, const String &p_base_path);
|
||||
Error _parse_buffer_views(Ref<GLTFState> state);
|
||||
@ -208,7 +131,7 @@ private:
|
||||
Vector<Color> _decode_accessor_as_color(Ref<GLTFState> state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<Quat> _decode_accessor_as_quat(Ref<GLTFState> state,
|
||||
Vector<Quaternion> _decode_accessor_as_quaternion(Ref<GLTFState> state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<Transform2D> _decode_accessor_as_xform2d(Ref<GLTFState> state,
|
||||
@ -217,7 +140,7 @@ private:
|
||||
Vector<Basis> _decode_accessor_as_basis(Ref<GLTFState> state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<Transform> _decode_accessor_as_xform(Ref<GLTFState> state,
|
||||
Vector<Transform3D> _decode_accessor_as_xform(Ref<GLTFState> state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Error _parse_meshes(Ref<GLTFState> state);
|
||||
@ -227,9 +150,9 @@ private:
|
||||
Error _parse_images(Ref<GLTFState> state, const String &p_base_path);
|
||||
Error _parse_textures(Ref<GLTFState> state);
|
||||
Error _parse_materials(Ref<GLTFState> state);
|
||||
void _set_texture_transform_uv1(const Dictionary &d, Ref<SpatialMaterial> material);
|
||||
void _set_texture_transform_uv1(const Dictionary &d, Ref<BaseMaterial3D> material);
|
||||
void spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss,
|
||||
Ref<SpatialMaterial> p_material);
|
||||
Ref<BaseMaterial3D> p_material);
|
||||
static void spec_gloss_to_metal_base_color(const Color &p_specular_factor,
|
||||
const Color &p_diffuse,
|
||||
Color &r_base_color,
|
||||
@ -259,23 +182,21 @@ private:
|
||||
Error _parse_lights(Ref<GLTFState> state);
|
||||
Error _parse_animations(Ref<GLTFState> state);
|
||||
Error _serialize_animations(Ref<GLTFState> state);
|
||||
BoneAttachment *_generate_bone_attachment(Ref<GLTFState> state,
|
||||
Skeleton *skeleton,
|
||||
BoneAttachment3D *_generate_bone_attachment(Ref<GLTFState> state,
|
||||
Skeleton3D *skeleton,
|
||||
const GLTFNodeIndex node_index,
|
||||
const GLTFNodeIndex bone_index);
|
||||
Spatial *_generate_mesh_instance(Ref<GLTFState> state, Node *scene_parent, const GLTFNodeIndex node_index);
|
||||
Camera *_generate_camera(Ref<GLTFState> state, Node *scene_parent,
|
||||
const GLTFNodeIndex node_index);
|
||||
Spatial *_generate_light(Ref<GLTFState> state, Node *scene_parent, const GLTFNodeIndex node_index);
|
||||
Spatial *_generate_spatial(Ref<GLTFState> state, Node *scene_parent,
|
||||
const GLTFNodeIndex node_index);
|
||||
ImporterMeshInstance3D *_generate_mesh_instance(Ref<GLTFState> state, const GLTFNodeIndex node_index);
|
||||
Camera3D *_generate_camera(Ref<GLTFState> state, const GLTFNodeIndex node_index);
|
||||
Node3D *_generate_light(Ref<GLTFState> state, const GLTFNodeIndex node_index);
|
||||
Node3D *_generate_spatial(Ref<GLTFState> state, const GLTFNodeIndex node_index);
|
||||
void _assign_scene_names(Ref<GLTFState> state);
|
||||
template <class T>
|
||||
T _interpolate_track(const Vector<float> &p_times, const Vector<T> &p_values,
|
||||
T _interpolate_track(const Vector<real_t> &p_times, const Vector<T> &p_values,
|
||||
const float p_time,
|
||||
const GLTFAnimation::Interpolation p_interp);
|
||||
GLTFAccessorIndex _encode_accessor_as_quats(Ref<GLTFState> state,
|
||||
const Vector<Quat> p_attribs,
|
||||
GLTFAccessorIndex _encode_accessor_as_quaternions(Ref<GLTFState> state,
|
||||
const Vector<Quaternion> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
GLTFAccessorIndex _encode_accessor_as_weights(Ref<GLTFState> state,
|
||||
const Vector<Color> p_attribs,
|
||||
@ -318,7 +239,7 @@ private:
|
||||
const Vector<int32_t> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
GLTFAccessorIndex _encode_accessor_as_xform(Ref<GLTFState> state,
|
||||
const Vector<Transform> p_attribs,
|
||||
const Vector<Transform3D> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
Error _encode_buffer_view(Ref<GLTFState> state, const double *src,
|
||||
const int count, const GLTFType type,
|
||||
@ -334,20 +255,21 @@ private:
|
||||
String interpolation_to_string(const GLTFAnimation::Interpolation p_interp);
|
||||
GLTFAnimation::Track _convert_animation_track(Ref<GLTFState> state,
|
||||
GLTFAnimation::Track p_track,
|
||||
Ref<Animation> p_animation, Transform p_bone_rest,
|
||||
Ref<Animation> p_animation,
|
||||
int32_t p_track_i,
|
||||
GLTFNodeIndex p_node_i);
|
||||
Error _encode_buffer_bins(Ref<GLTFState> state, const String &p_path);
|
||||
Error _encode_buffer_glb(Ref<GLTFState> state, const String &p_path);
|
||||
Dictionary _serialize_texture_transform_uv1(Ref<SpatialMaterial> p_material);
|
||||
Dictionary _serialize_texture_transform_uv2(Ref<SpatialMaterial> p_material);
|
||||
PackedByteArray _serialize_glb_buffer(Ref<GLTFState> state, Error *r_err);
|
||||
Dictionary _serialize_texture_transform_uv1(Ref<BaseMaterial3D> p_material);
|
||||
Dictionary _serialize_texture_transform_uv2(Ref<BaseMaterial3D> p_material);
|
||||
Error _serialize_version(Ref<GLTFState> state);
|
||||
Error _serialize_file(Ref<GLTFState> state, const String p_path);
|
||||
Error _serialize_extensions(Ref<GLTFState> state) const;
|
||||
|
||||
public:
|
||||
// http://www.itu.int/rec/R-REC-BT.601
|
||||
// http://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.601-7-201103-I!!PDF-E.pdf
|
||||
// https://www.itu.int/rec/R-REC-BT.601
|
||||
// https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.601-7-201103-I!!PDF-E.pdf
|
||||
static constexpr float R_BRIGHTNESS_COEFF = 0.299f;
|
||||
static constexpr float G_BRIGHTNESS_COEFF = 0.587f;
|
||||
static constexpr float B_BRIGHTNESS_COEFF = 0.114f;
|
||||
@ -362,27 +284,38 @@ private:
|
||||
static float get_max_component(const Color &p_color);
|
||||
|
||||
public:
|
||||
String _sanitize_scene_name(Ref<GLTFState> state, const String &p_name);
|
||||
String _legacy_validate_node_name(const String &p_name);
|
||||
Error append_from_file(String p_path, Ref<GLTFState> r_state, uint32_t p_flags = 0, int32_t p_bake_fps = 30, String p_base_path = String());
|
||||
Error append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref<GLTFState> r_state, uint32_t p_flags = 0, int32_t p_bake_fps = 30);
|
||||
Error append_from_scene(Node *p_node, Ref<GLTFState> r_state, uint32_t p_flags = 0, int32_t p_bake_fps = 30);
|
||||
|
||||
public:
|
||||
Node *generate_scene(Ref<GLTFState> state, int32_t p_bake_fps = 30.0f);
|
||||
PackedByteArray generate_buffer(Ref<GLTFState> state);
|
||||
Error write_to_filesystem(Ref<GLTFState> state, const String &p_path);
|
||||
|
||||
public:
|
||||
Error _parse_gltf_state(Ref<GLTFState> state, const String &p_search_path, float p_bake_fps);
|
||||
Error _parse_gltf_extensions(Ref<GLTFState> state);
|
||||
|
||||
void _process_mesh_instances(Ref<GLTFState> state, Node *scene_root);
|
||||
void _generate_scene_node(Ref<GLTFState> state, Node *scene_parent,
|
||||
Spatial *scene_root,
|
||||
Node3D *scene_root,
|
||||
const GLTFNodeIndex node_index);
|
||||
void _generate_skeleton_bone_node(Ref<GLTFState> state, Node *scene_parent, Spatial *scene_root, const GLTFNodeIndex node_index);
|
||||
void _generate_skeleton_bone_node(Ref<GLTFState> state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index);
|
||||
void _import_animation(Ref<GLTFState> state, AnimationPlayer *ap,
|
||||
const GLTFAnimationIndex index, const int bake_fps);
|
||||
void _convert_mesh_instances(Ref<GLTFState> state);
|
||||
GLTFCameraIndex _convert_camera(Ref<GLTFState> state, Camera *p_camera);
|
||||
void _convert_light_to_gltf(Light *light, Ref<GLTFState> state, Ref<GLTFNode> gltf_node);
|
||||
GLTFLightIndex _convert_light(Ref<GLTFState> state, Light *p_light);
|
||||
void _convert_spatial(Ref<GLTFState> state, Spatial *p_spatial, Ref<GLTFNode> p_node);
|
||||
GLTFCameraIndex _convert_camera(Ref<GLTFState> state, Camera3D *p_camera);
|
||||
void _convert_light_to_gltf(Light3D *light, Ref<GLTFState> state, Ref<GLTFNode> gltf_node);
|
||||
GLTFLightIndex _convert_light(Ref<GLTFState> state, Light3D *p_light);
|
||||
void _convert_spatial(Ref<GLTFState> state, Node3D *p_spatial, Ref<GLTFNode> p_node);
|
||||
void _convert_scene_node(Ref<GLTFState> state, Node *p_current,
|
||||
const GLTFNodeIndex p_gltf_current,
|
||||
const GLTFNodeIndex p_gltf_root);
|
||||
|
||||
#ifdef MODULE_CSG_ENABLED
|
||||
void _convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeIndex p_gltf_parent, Ref<GLTFNode> gltf_node, Ref<GLTFState> state);
|
||||
#endif // MODULE_CSG_ENABLED
|
||||
|
||||
void _create_gltf_node(Ref<GLTFState> state,
|
||||
Node *p_scene_parent,
|
||||
GLTFNodeIndex current_node_i,
|
||||
@ -395,32 +328,39 @@ public:
|
||||
GLTFNodeIndex p_gltf_root_index,
|
||||
Ref<GLTFNode> p_gltf_node, Node *p_scene_parent);
|
||||
void _check_visibility(Node *p_node, bool &retflag);
|
||||
void _convert_camera_to_gltf(Camera *camera, Ref<GLTFState> state,
|
||||
void _convert_camera_to_gltf(Camera3D *camera, Ref<GLTFState> state,
|
||||
Ref<GLTFNode> gltf_node);
|
||||
void _convert_mult_mesh_instance_to_gltf(
|
||||
MultiMeshInstance *p_scene_parent,
|
||||
#ifdef MODULE_GRIDMAP_ENABLED
|
||||
void _convert_grid_map_to_gltf(
|
||||
GridMap *p_grid_map,
|
||||
GLTFNodeIndex p_parent_node_index,
|
||||
GLTFNodeIndex p_root_node_index,
|
||||
Ref<GLTFNode> gltf_node, Ref<GLTFState> state);
|
||||
#endif // MODULE_GRIDMAP_ENABLED
|
||||
void _convert_multi_mesh_instance_to_gltf(
|
||||
MultiMeshInstance3D *p_multi_mesh_instance,
|
||||
GLTFNodeIndex p_parent_node_index,
|
||||
GLTFNodeIndex p_root_node_index,
|
||||
Ref<GLTFNode> gltf_node, Ref<GLTFState> state);
|
||||
void _convert_skeleton_to_gltf(
|
||||
Skeleton *p_scene_parent, Ref<GLTFState> state,
|
||||
Skeleton3D *p_scene_parent, Ref<GLTFState> state,
|
||||
GLTFNodeIndex p_parent_node_index,
|
||||
GLTFNodeIndex p_root_node_index,
|
||||
Ref<GLTFNode> gltf_node);
|
||||
void _convert_bone_attachment_to_gltf(BoneAttachment *p_bone_attachment,
|
||||
void _convert_bone_attachment_to_gltf(BoneAttachment3D *p_bone_attachment,
|
||||
Ref<GLTFState> state,
|
||||
GLTFNodeIndex p_parent_node_index,
|
||||
GLTFNodeIndex p_root_node_index,
|
||||
Ref<GLTFNode> gltf_node);
|
||||
void _convert_mesh_instance_to_gltf(MeshInstance *p_mesh_instance,
|
||||
void _convert_mesh_instance_to_gltf(MeshInstance3D *p_mesh_instance,
|
||||
Ref<GLTFState> state,
|
||||
Ref<GLTFNode> gltf_node);
|
||||
GLTFMeshIndex _convert_mesh_to_gltf(Ref<GLTFState> state,
|
||||
MeshInstance *p_mesh_instance);
|
||||
MeshInstance3D *p_mesh_instance);
|
||||
void _convert_animation(Ref<GLTFState> state, AnimationPlayer *ap,
|
||||
String p_animation_track_name);
|
||||
Error serialize(Ref<GLTFState> state, Node *p_root, const String &p_path);
|
||||
Error parse(Ref<GLTFState> state, String p_paths, bool p_read_binary = false);
|
||||
Error _serialize(Ref<GLTFState> state, const String &p_path);
|
||||
Error _parse(Ref<GLTFState> state, String p_path, Ref<FileAccess> f, int p_bake_fps);
|
||||
};
|
||||
|
||||
#endif // GLTF_DOCUMENT_H
|
||||
|
108
modules/gltf/gltf_document_extension.cpp
Normal file
108
modules/gltf/gltf_document_extension.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_document_extension.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_document_extension.h"
|
||||
|
||||
void GLTFDocumentExtension::_bind_methods() {
|
||||
GDVIRTUAL_BIND(_import_preflight, "state");
|
||||
GDVIRTUAL_BIND(_import_post_parse, "state");
|
||||
GDVIRTUAL_BIND(_import_node, "state", "gltf_node", "json", "node");
|
||||
GDVIRTUAL_BIND(_import_post, "state", "root");
|
||||
GDVIRTUAL_BIND(_export_preflight, "root");
|
||||
GDVIRTUAL_BIND(_export_node, "state", "gltf_node", "json", "node");
|
||||
GDVIRTUAL_BIND(_export_post, "state");
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::import_post(Ref<GLTFState> p_state, Node *p_root) {
|
||||
ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
|
||||
int err = OK;
|
||||
if (GDVIRTUAL_CALL(_import_post, p_state, p_root, err)) {
|
||||
return Error(err);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::import_preflight(Ref<GLTFState> p_state) {
|
||||
ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
|
||||
int err = OK;
|
||||
if (GDVIRTUAL_CALL(_import_preflight, p_state, err)) {
|
||||
return Error(err);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::import_post_parse(Ref<GLTFState> p_state) {
|
||||
ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
|
||||
int err = OK;
|
||||
if (GDVIRTUAL_CALL(_import_post_parse, p_state, err)) {
|
||||
return Error(err);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::export_post(Ref<GLTFState> p_state) {
|
||||
ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
|
||||
int err = OK;
|
||||
if (GDVIRTUAL_CALL(_export_post, p_state, err)) {
|
||||
return Error(err);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
Error GLTFDocumentExtension::export_preflight(Node *p_root) {
|
||||
ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER);
|
||||
int err = OK;
|
||||
if (GDVIRTUAL_CALL(_export_preflight, p_root, err)) {
|
||||
return Error(err);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::import_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_dict, Node *p_node) {
|
||||
ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_NULL_V(p_gltf_node, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER);
|
||||
int err = OK;
|
||||
if (GDVIRTUAL_CALL(_import_node, p_state, p_gltf_node, r_dict, p_node, err)) {
|
||||
return Error(err);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_dict, Node *p_node) {
|
||||
ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_NULL_V(p_gltf_node, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER);
|
||||
int err = OK;
|
||||
if (GDVIRTUAL_CALL(_export_node, p_state, p_gltf_node, r_dict, p_node, err)) {
|
||||
return Error(err);
|
||||
}
|
||||
return OK;
|
||||
}
|
60
modules/gltf/gltf_document_extension.h
Normal file
60
modules/gltf/gltf_document_extension.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_document_extension.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_DOCUMENT_EXTENSION_H
|
||||
#define GLTF_DOCUMENT_EXTENSION_H
|
||||
|
||||
#include "gltf_state.h"
|
||||
#include "structures/gltf_node.h"
|
||||
|
||||
class GLTFDocumentExtension : public Resource {
|
||||
GDCLASS(GLTFDocumentExtension, Resource);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
virtual Error import_preflight(Ref<GLTFState> p_state);
|
||||
virtual Error import_post_parse(Ref<GLTFState> p_state);
|
||||
virtual Error export_post(Ref<GLTFState> p_state);
|
||||
virtual Error import_post(Ref<GLTFState> p_state, Node *p_node);
|
||||
virtual Error export_preflight(Node *p_state);
|
||||
virtual Error import_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_json, Node *p_node);
|
||||
virtual Error export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_json, Node *p_node);
|
||||
GDVIRTUAL1R(int, _import_preflight, Ref<GLTFState>);
|
||||
GDVIRTUAL1R(int, _import_post_parse, Ref<GLTFState>);
|
||||
GDVIRTUAL4R(int, _import_node, Ref<GLTFState>, Ref<GLTFNode>, Dictionary, Node *);
|
||||
GDVIRTUAL2R(int, _import_post, Ref<GLTFState>, Node *);
|
||||
GDVIRTUAL1R(int, _export_preflight, Node *);
|
||||
GDVIRTUAL4R(int, _export_node, Ref<GLTFState>, Ref<GLTFNode>, Dictionary, Node *);
|
||||
GDVIRTUAL1R(int, _export_post, Ref<GLTFState>);
|
||||
};
|
||||
|
||||
#endif // GLTF_DOCUMENT_EXTENSION_H
|
@ -0,0 +1,81 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_document_extension_convert_importer_mesh.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_document_extension_convert_importer_mesh.h"
|
||||
|
||||
#include "gltf_state.h"
|
||||
|
||||
#include "core/error/error_macros.h"
|
||||
#include "scene/3d/mesh_instance_3d.h"
|
||||
#include "scene/resources/importer_mesh.h"
|
||||
|
||||
void GLTFDocumentExtensionConvertImporterMesh::_bind_methods() {
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtensionConvertImporterMesh::import_post(Ref<GLTFState> p_state, Node *p_root) {
|
||||
ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
|
||||
List<Node *> queue;
|
||||
queue.push_back(p_root);
|
||||
List<Node *> delete_queue;
|
||||
while (!queue.is_empty()) {
|
||||
List<Node *>::Element *E = queue.front();
|
||||
Node *node = E->get();
|
||||
ImporterMeshInstance3D *mesh_3d = cast_to<ImporterMeshInstance3D>(node);
|
||||
if (mesh_3d) {
|
||||
MeshInstance3D *mesh_instance_node_3d = memnew(MeshInstance3D);
|
||||
Ref<ImporterMesh> mesh = mesh_3d->get_mesh();
|
||||
if (mesh.is_valid()) {
|
||||
Ref<ArrayMesh> array_mesh = mesh->get_mesh();
|
||||
mesh_instance_node_3d->set_name(node->get_name());
|
||||
mesh_instance_node_3d->set_transform(mesh_3d->get_transform());
|
||||
mesh_instance_node_3d->set_mesh(array_mesh);
|
||||
mesh_instance_node_3d->set_skin(mesh_3d->get_skin());
|
||||
mesh_instance_node_3d->set_skeleton_path(mesh_3d->get_skeleton_path());
|
||||
node->replace_by(mesh_instance_node_3d);
|
||||
delete_queue.push_back(node);
|
||||
} else {
|
||||
memdelete(mesh_instance_node_3d);
|
||||
}
|
||||
}
|
||||
int child_count = node->get_child_count();
|
||||
for (int i = 0; i < child_count; i++) {
|
||||
queue.push_back(node->get_child(i));
|
||||
}
|
||||
queue.pop_front();
|
||||
}
|
||||
while (!queue.is_empty()) {
|
||||
List<Node *>::Element *E = delete_queue.front();
|
||||
Node *node = E->get();
|
||||
memdelete(node);
|
||||
delete_queue.pop_front();
|
||||
}
|
||||
return OK;
|
||||
}
|
50
modules/gltf/gltf_document_extension_convert_importer_mesh.h
Normal file
50
modules/gltf/gltf_document_extension_convert_importer_mesh.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_document_extension_convert_importer_mesh.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_DOCUMENT_EXTENSION_CONVERT_IMPORTER_MESH_H
|
||||
#define GLTF_DOCUMENT_EXTENSION_CONVERT_IMPORTER_MESH_H
|
||||
|
||||
#include "gltf_document_extension.h"
|
||||
|
||||
#include "scene/3d/importer_mesh_instance_3d.h"
|
||||
#include "scene/3d/mesh_instance_3d.h"
|
||||
#include "scene/resources/importer_mesh.h"
|
||||
|
||||
class GLTFDocumentExtensionConvertImporterMesh : public GLTFDocumentExtension {
|
||||
GDCLASS(GLTFDocumentExtensionConvertImporterMesh, GLTFDocumentExtension);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
Error import_post(Ref<GLTFState> p_state, Node *p_root) override;
|
||||
};
|
||||
|
||||
#endif // GLTF_DOCUMENT_EXTENSION_CONVERT_IMPORTER_MESH_H
|
@ -30,8 +30,6 @@
|
||||
|
||||
#include "gltf_state.h"
|
||||
|
||||
#include "scene/resources/skin.h"
|
||||
|
||||
void GLTFState::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_json"), &GLTFState::get_json);
|
||||
ClassDB::bind_method(D_METHOD("set_json", "json"), &GLTFState::set_json);
|
||||
@ -59,6 +57,8 @@ void GLTFState::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_materials", "materials"), &GLTFState::set_materials);
|
||||
ClassDB::bind_method(D_METHOD("get_scene_name"), &GLTFState::get_scene_name);
|
||||
ClassDB::bind_method(D_METHOD("set_scene_name", "scene_name"), &GLTFState::set_scene_name);
|
||||
ClassDB::bind_method(D_METHOD("get_base_path"), &GLTFState::get_base_path);
|
||||
ClassDB::bind_method(D_METHOD("set_base_path", "base_path"), &GLTFState::set_base_path);
|
||||
ClassDB::bind_method(D_METHOD("get_root_nodes"), &GLTFState::get_root_nodes);
|
||||
ClassDB::bind_method(D_METHOD("set_root_nodes", "root_nodes"), &GLTFState::set_root_nodes);
|
||||
ClassDB::bind_method(D_METHOD("get_textures"), &GLTFState::get_textures);
|
||||
@ -86,7 +86,7 @@ void GLTFState::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "json"), "set_json", "get_json"); // Dictionary
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "major_version"), "set_major_version", "get_major_version"); // int
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "minor_version"), "set_minor_version", "get_minor_version"); // int
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY, "glb_data"), "set_glb_data", "get_glb_data"); // Vector<uint8_t>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "glb_data"), "set_glb_data", "get_glb_data"); // Vector<uint8_t>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_named_skin_binds"), "set_use_named_skin_binds", "get_use_named_skin_binds"); // bool
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "nodes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_nodes", "get_nodes"); // Vector<Ref<GLTFNode>>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "buffers"), "set_buffers", "get_buffers"); // Vector<Vector<uint8_t>
|
||||
@ -95,7 +95,8 @@ void GLTFState::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "meshes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_meshes", "get_meshes"); // Vector<Ref<GLTFMesh>>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "materials", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_materials", "get_materials"); // Vector<Ref<Material>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "scene_name"), "set_scene_name", "get_scene_name"); // String
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "root_nodes"), "set_root_nodes", "get_root_nodes"); // Vector<int>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_path"), "set_base_path", "get_base_path"); // String
|
||||
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "root_nodes"), "set_root_nodes", "get_root_nodes"); // Vector<int>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "textures", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_textures", "get_textures"); // Vector<Ref<GLTFTexture>>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "images", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_images", "get_images"); // Vector<Ref<Texture>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "skins", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skins", "get_skins"); // Vector<Ref<GLTFSkin>>
|
||||
@ -104,7 +105,7 @@ void GLTFState::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "unique_names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_unique_names", "get_unique_names"); // Set<String>
|
||||
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"); // Map<GLTFSkeletonIndex,
|
||||
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::ARRAY, "animations", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_animations", "get_animations"); // Vector<Ref<GLTFAnimation>>
|
||||
}
|
||||
|
||||
@ -149,51 +150,51 @@ void GLTFState::set_use_named_skin_binds(bool p_use_named_skin_binds) {
|
||||
}
|
||||
|
||||
Array GLTFState::get_nodes() {
|
||||
return GLTFDocument::to_array(nodes);
|
||||
return GLTFTemplateConvert::to_array(nodes);
|
||||
}
|
||||
|
||||
void GLTFState::set_nodes(Array p_nodes) {
|
||||
GLTFDocument::set_from_array(nodes, p_nodes);
|
||||
GLTFTemplateConvert::set_from_array(nodes, p_nodes);
|
||||
}
|
||||
|
||||
Array GLTFState::get_buffers() {
|
||||
return GLTFDocument::to_array(buffers);
|
||||
return GLTFTemplateConvert::to_array(buffers);
|
||||
}
|
||||
|
||||
void GLTFState::set_buffers(Array p_buffers) {
|
||||
GLTFDocument::set_from_array(buffers, p_buffers);
|
||||
GLTFTemplateConvert::set_from_array(buffers, p_buffers);
|
||||
}
|
||||
|
||||
Array GLTFState::get_buffer_views() {
|
||||
return GLTFDocument::to_array(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);
|
||||
GLTFTemplateConvert::set_from_array(buffer_views, p_buffer_views);
|
||||
}
|
||||
|
||||
Array GLTFState::get_accessors() {
|
||||
return GLTFDocument::to_array(accessors);
|
||||
return GLTFTemplateConvert::to_array(accessors);
|
||||
}
|
||||
|
||||
void GLTFState::set_accessors(Array p_accessors) {
|
||||
GLTFDocument::set_from_array(accessors, p_accessors);
|
||||
GLTFTemplateConvert::set_from_array(accessors, p_accessors);
|
||||
}
|
||||
|
||||
Array GLTFState::get_meshes() {
|
||||
return GLTFDocument::to_array(meshes);
|
||||
return GLTFTemplateConvert::to_array(meshes);
|
||||
}
|
||||
|
||||
void GLTFState::set_meshes(Array p_meshes) {
|
||||
GLTFDocument::set_from_array(meshes, p_meshes);
|
||||
GLTFTemplateConvert::set_from_array(meshes, p_meshes);
|
||||
}
|
||||
|
||||
Array GLTFState::get_materials() {
|
||||
return GLTFDocument::to_array(materials);
|
||||
return GLTFTemplateConvert::to_array(materials);
|
||||
}
|
||||
|
||||
void GLTFState::set_materials(Array p_materials) {
|
||||
GLTFDocument::set_from_array(materials, p_materials);
|
||||
GLTFTemplateConvert::set_from_array(materials, p_materials);
|
||||
}
|
||||
|
||||
String GLTFState::get_scene_name() {
|
||||
@ -205,91 +206,91 @@ void GLTFState::set_scene_name(String p_scene_name) {
|
||||
}
|
||||
|
||||
Array GLTFState::get_root_nodes() {
|
||||
return GLTFDocument::to_array(root_nodes);
|
||||
return GLTFTemplateConvert::to_array(root_nodes);
|
||||
}
|
||||
|
||||
void GLTFState::set_root_nodes(Array p_root_nodes) {
|
||||
GLTFDocument::set_from_array(root_nodes, p_root_nodes);
|
||||
GLTFTemplateConvert::set_from_array(root_nodes, p_root_nodes);
|
||||
}
|
||||
|
||||
Array GLTFState::get_textures() {
|
||||
return GLTFDocument::to_array(textures);
|
||||
return GLTFTemplateConvert::to_array(textures);
|
||||
}
|
||||
|
||||
void GLTFState::set_textures(Array p_textures) {
|
||||
GLTFDocument::set_from_array(textures, p_textures);
|
||||
GLTFTemplateConvert::set_from_array(textures, p_textures);
|
||||
}
|
||||
|
||||
Array GLTFState::get_images() {
|
||||
return GLTFDocument::to_array(images);
|
||||
return GLTFTemplateConvert::to_array(images);
|
||||
}
|
||||
|
||||
void GLTFState::set_images(Array p_images) {
|
||||
GLTFDocument::set_from_array(images, p_images);
|
||||
GLTFTemplateConvert::set_from_array(images, p_images);
|
||||
}
|
||||
|
||||
Array GLTFState::get_skins() {
|
||||
return GLTFDocument::to_array(skins);
|
||||
return GLTFTemplateConvert::to_array(skins);
|
||||
}
|
||||
|
||||
void GLTFState::set_skins(Array p_skins) {
|
||||
GLTFDocument::set_from_array(skins, p_skins);
|
||||
GLTFTemplateConvert::set_from_array(skins, p_skins);
|
||||
}
|
||||
|
||||
Array GLTFState::get_cameras() {
|
||||
return GLTFDocument::to_array(cameras);
|
||||
return GLTFTemplateConvert::to_array(cameras);
|
||||
}
|
||||
|
||||
void GLTFState::set_cameras(Array p_cameras) {
|
||||
GLTFDocument::set_from_array(cameras, p_cameras);
|
||||
GLTFTemplateConvert::set_from_array(cameras, p_cameras);
|
||||
}
|
||||
|
||||
Array GLTFState::get_lights() {
|
||||
return GLTFDocument::to_array(lights);
|
||||
return GLTFTemplateConvert::to_array(lights);
|
||||
}
|
||||
|
||||
void GLTFState::set_lights(Array p_lights) {
|
||||
GLTFDocument::set_from_array(lights, p_lights);
|
||||
GLTFTemplateConvert::set_from_array(lights, p_lights);
|
||||
}
|
||||
|
||||
Array GLTFState::get_unique_names() {
|
||||
return GLTFDocument::to_array(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);
|
||||
GLTFTemplateConvert::set_from_array(unique_names, p_unique_names);
|
||||
}
|
||||
|
||||
Array GLTFState::get_unique_animation_names() {
|
||||
return GLTFDocument::to_array(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);
|
||||
GLTFTemplateConvert::set_from_array(unique_animation_names, p_unique_animation_names);
|
||||
}
|
||||
|
||||
Array GLTFState::get_skeletons() {
|
||||
return GLTFDocument::to_array(skeletons);
|
||||
return GLTFTemplateConvert::to_array(skeletons);
|
||||
}
|
||||
|
||||
void GLTFState::set_skeletons(Array p_skeletons) {
|
||||
GLTFDocument::set_from_array(skeletons, 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);
|
||||
return GLTFTemplateConvert::to_array(animations);
|
||||
}
|
||||
|
||||
void GLTFState::set_animations(Array p_animations) {
|
||||
GLTFDocument::set_from_array(animations, p_animations);
|
||||
GLTFTemplateConvert::set_from_array(animations, p_animations);
|
||||
}
|
||||
|
||||
Node *GLTFState::get_scene_node(GLTFNodeIndex idx) {
|
||||
@ -307,3 +308,19 @@ AnimationPlayer *GLTFState::get_animation_player(int idx) {
|
||||
ERR_FAIL_INDEX_V(idx, animation_players.size(), nullptr);
|
||||
return animation_players[idx];
|
||||
}
|
||||
|
||||
void GLTFState::set_discard_meshes_and_materials(bool p_discard_meshes_and_materials) {
|
||||
discard_meshes_and_materials = p_discard_meshes_and_materials;
|
||||
}
|
||||
|
||||
bool GLTFState::get_discard_meshes_and_materials() {
|
||||
return discard_meshes_and_materials;
|
||||
}
|
||||
|
||||
String GLTFState::get_base_path() {
|
||||
return base_path;
|
||||
}
|
||||
|
||||
void GLTFState::set_base_path(String p_base_path) {
|
||||
base_path = p_base_path;
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
#ifndef GLTF_STATE_H
|
||||
#define GLTF_STATE_H
|
||||
/*************************************************************************/
|
||||
/* gltf_state.h */
|
||||
/*************************************************************************/
|
||||
@ -30,38 +28,39 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/map.h"
|
||||
#include "core/resource.h"
|
||||
#include "core/vector.h"
|
||||
#ifndef GLTF_STATE_H
|
||||
#define GLTF_STATE_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"
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
#include "gltf_accessor.h"
|
||||
#include "gltf_animation.h"
|
||||
#include "gltf_buffer_view.h"
|
||||
#include "gltf_camera.h"
|
||||
#include "gltf_document.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"
|
||||
|
||||
class GLTFState : public Resource {
|
||||
GDCLASS(GLTFState, Resource);
|
||||
friend class GLTFDocument;
|
||||
friend class PackedSceneGLTF;
|
||||
|
||||
String filename;
|
||||
String base_path;
|
||||
Dictionary json;
|
||||
int major_version = 0;
|
||||
int minor_version = 0;
|
||||
Vector<uint8_t> glb_data;
|
||||
|
||||
bool use_named_skin_binds = false;
|
||||
bool use_legacy_names = false;
|
||||
uint32_t compress_flags = 0;
|
||||
bool use_khr_texture_transform = false;
|
||||
bool discard_meshes_and_materials = false;
|
||||
|
||||
Vector<Ref<GLTFNode>> nodes;
|
||||
Vector<Vector<uint8_t>> buffers;
|
||||
@ -71,27 +70,27 @@ class GLTFState : public Resource {
|
||||
Vector<Ref<GLTFMesh>> meshes; // meshes are loaded directly, no reason not to.
|
||||
|
||||
Vector<AnimationPlayer *> animation_players;
|
||||
Map<Ref<Material>, GLTFMaterialIndex> material_cache;
|
||||
Vector<Ref<Material>> materials;
|
||||
HashMap<Ref<BaseMaterial3D>, GLTFMaterialIndex> material_cache;
|
||||
Vector<Ref<BaseMaterial3D>> materials;
|
||||
|
||||
String scene_name;
|
||||
Vector<int> root_nodes;
|
||||
Vector<Ref<GLTFTexture>> textures;
|
||||
Vector<Ref<Texture>> images;
|
||||
Vector<Ref<Texture2D>> images;
|
||||
|
||||
Vector<Ref<GLTFSkin>> skins;
|
||||
Vector<Ref<GLTFCamera>> cameras;
|
||||
Vector<Ref<GLTFLight>> lights;
|
||||
Set<String> unique_names;
|
||||
Set<String> unique_animation_names;
|
||||
HashSet<String> unique_names;
|
||||
HashSet<String> unique_animation_names;
|
||||
|
||||
Vector<Ref<GLTFSkeleton>> skeletons;
|
||||
Map<GLTFSkeletonIndex, GLTFNodeIndex> skeleton_to_node;
|
||||
HashMap<GLTFSkeletonIndex, GLTFNodeIndex> skeleton_to_node;
|
||||
Vector<Ref<GLTFAnimation>> animations;
|
||||
Map<GLTFNodeIndex, Node *> scene_nodes;
|
||||
HashMap<GLTFNodeIndex, Node *> scene_nodes;
|
||||
|
||||
Map<ObjectID, GLTFSkeletonIndex> skeleton3d_to_gltf_skeleton;
|
||||
Map<ObjectID, Map<ObjectID, GLTFSkinIndex>> skin_and_skeleton3d_to_gltf_skin;
|
||||
HashMap<ObjectID, GLTFSkeletonIndex> skeleton3d_to_gltf_skeleton;
|
||||
HashMap<ObjectID, HashMap<ObjectID, GLTFSkinIndex>> skin_and_skeleton3d_to_gltf_skin;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
@ -112,6 +111,9 @@ public:
|
||||
bool get_use_named_skin_binds();
|
||||
void set_use_named_skin_binds(bool p_use_named_skin_binds);
|
||||
|
||||
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);
|
||||
|
||||
@ -133,6 +135,9 @@ public:
|
||||
String get_scene_name();
|
||||
void set_scene_name(String p_scene_name);
|
||||
|
||||
String get_base_path();
|
||||
void set_base_path(String p_base_path);
|
||||
|
||||
Array get_root_nodes();
|
||||
void set_root_nodes(Array p_root_nodes);
|
||||
|
||||
@ -171,6 +176,21 @@ public:
|
||||
int get_animation_players_count(int idx);
|
||||
|
||||
AnimationPlayer *get_animation_player(int idx);
|
||||
|
||||
//void set_scene_nodes(RBMap<GLTFNodeIndex, Node *> p_scene_nodes) {
|
||||
// this->scene_nodes = p_scene_nodes;
|
||||
//}
|
||||
|
||||
//void set_animation_players(Vector<AnimationPlayer *> p_animation_players) {
|
||||
// this->animation_players = p_animation_players;
|
||||
//}
|
||||
|
||||
//RBMap<Ref<Material>, GLTFMaterialIndex> get_material_cache() {
|
||||
// return this->material_cache;
|
||||
//}
|
||||
//void set_material_cache(RBMap<Ref<Material>, GLTFMaterialIndex> p_material_cache) {
|
||||
// this->material_cache = p_material_cache;
|
||||
//}
|
||||
};
|
||||
|
||||
#endif // GLTF_STATE_H
|
||||
|
94
modules/gltf/gltf_template_convert.h
Normal file
94
modules/gltf/gltf_template_convert.h
Normal file
@ -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 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]];
|
||||
}
|
||||
}
|
||||
} //namespace GLTFTemplateConvert
|
||||
|
||||
#endif // GLTF_TEMPLATE_CONVERT_H
|
@ -1,160 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* packed_scene_gltf.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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "packed_scene_gltf.h"
|
||||
|
||||
#include "editor/import/resource_importer_scene.h"
|
||||
#include "scene/3d/spatial.h"
|
||||
#include "scene/animation/animation_player.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
#include "scene/resources/skin.h"
|
||||
|
||||
#include "gltf_document.h"
|
||||
|
||||
void PackedSceneGLTF::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("export_gltf", "node", "path", "flags", "bake_fps"),
|
||||
&PackedSceneGLTF::export_gltf, DEFVAL(0), DEFVAL(1000.0f));
|
||||
ClassDB::bind_method(D_METHOD("pack_gltf", "path", "flags", "bake_fps", "compress_flags", "state"),
|
||||
&PackedSceneGLTF::pack_gltf, DEFVAL(0), DEFVAL(1000.0f), DEFVAL(Mesh::ARRAY_COMPRESS_DEFAULT), DEFVAL(Ref<GLTFState>()));
|
||||
ClassDB::bind_method(D_METHOD("import_gltf_scene", "path", "flags", "bake_fps", "compress_flags", "state"),
|
||||
&PackedSceneGLTF::import_gltf_scene, DEFVAL(0), DEFVAL(1000.0f), DEFVAL(Mesh::ARRAY_COMPRESS_DEFAULT), DEFVAL(Ref<GLTFState>()));
|
||||
}
|
||||
|
||||
Node *PackedSceneGLTF::import_gltf_scene(const String &p_path, uint32_t p_flags, float p_bake_fps, uint32_t p_compress_flags, Ref<GLTFState> r_state) {
|
||||
Error err = FAILED;
|
||||
List<String> deps;
|
||||
return import_scene(p_path, p_flags, p_bake_fps, p_compress_flags, &deps, &err, r_state);
|
||||
}
|
||||
|
||||
Node *PackedSceneGLTF::import_scene(const String &p_path, uint32_t p_flags,
|
||||
int p_bake_fps, uint32_t p_compress_flags,
|
||||
List<String> *r_missing_deps,
|
||||
Error *r_err,
|
||||
Ref<GLTFState> r_state) {
|
||||
if (r_state == Ref<GLTFState>()) {
|
||||
r_state.instance();
|
||||
}
|
||||
r_state->use_named_skin_binds =
|
||||
p_flags & EditorSceneImporter::IMPORT_USE_NAMED_SKIN_BINDS;
|
||||
r_state->use_legacy_names =
|
||||
p_flags & EditorSceneImporter::IMPORT_USE_LEGACY_NAMES;
|
||||
r_state->compress_flags = p_compress_flags;
|
||||
|
||||
Ref<GLTFDocument> gltf_document;
|
||||
gltf_document.instance();
|
||||
Error err = gltf_document->parse(r_state, p_path);
|
||||
*r_err = err;
|
||||
ERR_FAIL_COND_V(err != Error::OK, nullptr);
|
||||
|
||||
Spatial *root = memnew(Spatial);
|
||||
if (r_state->use_legacy_names) {
|
||||
root->set_name(gltf_document->_legacy_validate_node_name(r_state->scene_name));
|
||||
} else {
|
||||
root->set_name(r_state->scene_name);
|
||||
}
|
||||
for (int32_t root_i = 0; root_i < r_state->root_nodes.size(); root_i++) {
|
||||
gltf_document->_generate_scene_node(r_state, root, root, r_state->root_nodes[root_i]);
|
||||
}
|
||||
gltf_document->_process_mesh_instances(r_state, root);
|
||||
if (r_state->animations.size()) {
|
||||
AnimationPlayer *ap = memnew(AnimationPlayer);
|
||||
root->add_child(ap);
|
||||
ap->set_owner(root);
|
||||
for (int i = 0; i < r_state->animations.size(); i++) {
|
||||
gltf_document->_import_animation(r_state, ap, i, p_bake_fps);
|
||||
}
|
||||
}
|
||||
|
||||
return cast_to<Spatial>(root);
|
||||
}
|
||||
|
||||
void PackedSceneGLTF::pack_gltf(String p_path, int32_t p_flags,
|
||||
real_t p_bake_fps, uint32_t p_compress_flags, Ref<GLTFState> r_state) {
|
||||
Error err = FAILED;
|
||||
List<String> deps;
|
||||
Node *root = import_scene(p_path, p_flags, p_bake_fps, p_compress_flags, &deps, &err, r_state);
|
||||
ERR_FAIL_COND(err != OK);
|
||||
pack(root);
|
||||
}
|
||||
|
||||
void PackedSceneGLTF::save_scene(Node *p_node, const String &p_path,
|
||||
const String &p_src_path, uint32_t p_flags,
|
||||
int p_bake_fps, List<String> *r_missing_deps,
|
||||
Error *r_err) {
|
||||
Error err = FAILED;
|
||||
if (r_err) {
|
||||
*r_err = err;
|
||||
}
|
||||
Ref<GLTFDocument> gltf_document;
|
||||
gltf_document.instance();
|
||||
Ref<GLTFState> state;
|
||||
state.instance();
|
||||
err = gltf_document->serialize(state, p_node, p_path);
|
||||
if (r_err) {
|
||||
*r_err = err;
|
||||
}
|
||||
}
|
||||
|
||||
void PackedSceneGLTF::_build_parent_hierachy(Ref<GLTFState> state) {
|
||||
// build the hierarchy
|
||||
for (GLTFNodeIndex node_i = 0; node_i < state->nodes.size(); node_i++) {
|
||||
for (int j = 0; j < state->nodes[node_i]->children.size(); j++) {
|
||||
GLTFNodeIndex child_i = state->nodes[node_i]->children[j];
|
||||
ERR_FAIL_INDEX(child_i, state->nodes.size());
|
||||
if (state->nodes.write[child_i]->parent != -1) {
|
||||
continue;
|
||||
}
|
||||
state->nodes.write[child_i]->parent = node_i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Error PackedSceneGLTF::export_gltf(Node *p_root, String p_path,
|
||||
int32_t p_flags,
|
||||
real_t p_bake_fps) {
|
||||
ERR_FAIL_COND_V(!p_root, FAILED);
|
||||
List<String> deps;
|
||||
Error err;
|
||||
String path = p_path;
|
||||
int32_t flags = p_flags;
|
||||
real_t baked_fps = p_bake_fps;
|
||||
Ref<PackedSceneGLTF> exporter;
|
||||
exporter.instance();
|
||||
exporter->save_scene(p_root, path, "", flags, baked_fps, &deps, &err);
|
||||
int32_t error_code = err;
|
||||
if (error_code != 0) {
|
||||
return Error(error_code);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif // TOOLS_ENABLED
|
@ -28,66 +28,131 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef _3D_DISABLED
|
||||
|
||||
#include "register_types.h"
|
||||
|
||||
#include "gltf_accessor.h"
|
||||
#include "gltf_animation.h"
|
||||
#include "gltf_buffer_view.h"
|
||||
#include "gltf_camera.h"
|
||||
#include "gltf_document.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 "packed_scene_gltf.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor_scene_exporter_gltf_plugin.h"
|
||||
#include "editor_scene_importer_gltf.h"
|
||||
#endif
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
static void _editor_init() {
|
||||
Ref<EditorSceneImporterGLTF> import_gltf;
|
||||
import_gltf.instance();
|
||||
ResourceImporterScene::get_singleton()->add_importer(import_gltf);
|
||||
}
|
||||
#endif
|
||||
#ifndef _3D_DISABLED
|
||||
|
||||
void register_gltf_types() {
|
||||
#ifdef TOOLS_ENABLED
|
||||
ClassDB::APIType prev_api = ClassDB::get_current_api();
|
||||
ClassDB::set_current_api(ClassDB::API_EDITOR);
|
||||
ClassDB::register_class<EditorSceneImporterGLTF>();
|
||||
ClassDB::register_class<GLTFMesh>();
|
||||
EditorPlugins::add_by_type<SceneExporterGLTFPlugin>();
|
||||
ClassDB::set_current_api(prev_api);
|
||||
EditorNode::add_init_callback(_editor_init);
|
||||
#endif
|
||||
|
||||
ClassDB::register_class<GLTFSpecGloss>();
|
||||
ClassDB::register_class<GLTFNode>();
|
||||
ClassDB::register_class<GLTFAnimation>();
|
||||
ClassDB::register_class<GLTFBufferView>();
|
||||
ClassDB::register_class<GLTFAccessor>();
|
||||
ClassDB::register_class<GLTFTexture>();
|
||||
ClassDB::register_class<GLTFSkeleton>();
|
||||
ClassDB::register_class<GLTFSkin>();
|
||||
ClassDB::register_class<GLTFCamera>();
|
||||
ClassDB::register_class<GLTFLight>();
|
||||
ClassDB::register_class<GLTFState>();
|
||||
ClassDB::register_class<GLTFDocument>();
|
||||
ClassDB::register_class<PackedSceneGLTF>();
|
||||
}
|
||||
|
||||
void unregister_gltf_types() {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
#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_state.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"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_scene_exporter_gltf_plugin.h"
|
||||
#include "editor/editor_scene_importer_blend.h"
|
||||
#include "editor/editor_scene_importer_fbx.h"
|
||||
#include "editor/editor_scene_importer_gltf.h"
|
||||
#include "editor/editor_settings.h"
|
||||
|
||||
static void _editor_init() {
|
||||
Ref<EditorSceneFormatImporterGLTF> import_gltf;
|
||||
import_gltf.instantiate();
|
||||
ResourceImporterScene::add_importer(import_gltf);
|
||||
|
||||
// Blend to glTF importer.
|
||||
|
||||
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", "");
|
||||
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<EditorFileSystemImportFormatSupportQueryBlend> blend_import_query;
|
||||
blend_import_query.instantiate();
|
||||
EditorFileSystem::get_singleton()->add_import_format_support_query(blend_import_query);
|
||||
}
|
||||
|
||||
// FBX to glTF importer.
|
||||
|
||||
bool fbx_enabled = GLOBAL_GET("filesystem/import/fbx/enabled");
|
||||
// Defined here because EditorSettings doesn't exist in `register_gltf_types` yet.
|
||||
String fbx2gltf_path = EDITOR_DEF_RST("filesystem/import/fbx/fbx2gltf_path", "");
|
||||
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,
|
||||
"filesystem/import/fbx/fbx2gltf_path", PROPERTY_HINT_GLOBAL_FILE));
|
||||
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.");
|
||||
} 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.");
|
||||
} else {
|
||||
Ref<EditorSceneFormatImporterFBX> importer;
|
||||
importer.instantiate();
|
||||
ResourceImporterScene::add_importer(importer);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
void initialize_gltf_module() {
|
||||
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
// glTF API available at runtime.
|
||||
GDREGISTER_CLASS(GLTFAccessor);
|
||||
GDREGISTER_CLASS(GLTFAnimation);
|
||||
GDREGISTER_CLASS(GLTFBufferView);
|
||||
GDREGISTER_CLASS(GLTFCamera);
|
||||
GDREGISTER_CLASS(GLTFDocument);
|
||||
GDREGISTER_CLASS(GLTFDocumentExtension);
|
||||
GDREGISTER_CLASS(GLTFDocumentExtensionConvertImporterMesh);
|
||||
GDREGISTER_CLASS(GLTFLight);
|
||||
GDREGISTER_CLASS(GLTFMesh);
|
||||
GDREGISTER_CLASS(GLTFNode);
|
||||
GDREGISTER_CLASS(GLTFSkeleton);
|
||||
GDREGISTER_CLASS(GLTFSkin);
|
||||
GDREGISTER_CLASS(GLTFSpecGloss);
|
||||
GDREGISTER_CLASS(GLTFState);
|
||||
GDREGISTER_CLASS(GLTFTexture);
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
|
||||
// Editor-specific API.
|
||||
ClassDB::APIType prev_api = ClassDB::get_current_api();
|
||||
ClassDB::set_current_api(ClassDB::API_EDITOR);
|
||||
|
||||
GDREGISTER_CLASS(EditorSceneFormatImporterGLTF);
|
||||
EditorPlugins::add_by_type<SceneExporterGLTFPlugin>();
|
||||
|
||||
// Project settings defined here so doctool finds them.
|
||||
GLOBAL_DEF_RST("filesystem/import/blender/enabled", true);
|
||||
GLOBAL_DEF_RST("filesystem/import/fbx/enabled", true);
|
||||
GDREGISTER_CLASS(EditorSceneFormatImporterBlend);
|
||||
GDREGISTER_CLASS(EditorSceneFormatImporterFBX);
|
||||
|
||||
ClassDB::set_current_api(prev_api);
|
||||
EditorNode::add_init_callback(_editor_init);
|
||||
}
|
||||
|
||||
#endif // TOOLS_ENABLED
|
||||
}
|
||||
|
||||
void uninitialize_gltf_module() {
|
||||
}
|
||||
*/
|
||||
|
||||
#endif // _3D_DISABLED
|
||||
|
@ -1,5 +1,3 @@
|
||||
#ifndef GLTF_REGISTER_TYPES_H
|
||||
#define GLTF_REGISTER_TYPES_H
|
||||
/*************************************************************************/
|
||||
/* register_types.h */
|
||||
/*************************************************************************/
|
||||
@ -30,11 +28,5 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef _3D_DISABLED
|
||||
|
||||
void register_gltf_types();
|
||||
void unregister_gltf_types();
|
||||
|
||||
#endif // _3D_DISABLED
|
||||
|
||||
#endif // GLTF_REGISTER_TYPES_H
|
||||
|
@ -65,9 +65,9 @@ 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::POOL_REAL_ARRAY, "min"), "set_min", "get_min"); // Vector<real_t>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_REAL_ARRAY, "max"), "set_max", "get_max"); // Vector<real_t>
|
||||
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
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_indices_buffer_view"), "set_sparse_indices_buffer_view", "get_sparse_indices_buffer_view"); // int
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_indices_byte_offset"), "set_sparse_indices_byte_offset", "get_sparse_indices_byte_offset"); // int
|
||||
@ -121,22 +121,22 @@ 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
|
||||
}
|
||||
|
||||
PoolVector<float> GLTFAccessor::get_min() {
|
||||
Vector<double> GLTFAccessor::get_min() {
|
||||
return min;
|
||||
}
|
||||
|
||||
void GLTFAccessor::set_min(PoolVector<float> p_min) {
|
||||
void GLTFAccessor::set_min(Vector<double> p_min) {
|
||||
min = p_min;
|
||||
}
|
||||
|
||||
PoolVector<float> GLTFAccessor::get_max() {
|
||||
Vector<double> GLTFAccessor::get_max() {
|
||||
return max;
|
||||
}
|
||||
|
||||
void GLTFAccessor::set_max(PoolVector<float> p_max) {
|
||||
void GLTFAccessor::set_max(Vector<double> p_max) {
|
||||
max = p_max;
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
#ifndef GLTF_ACCESSOR_H
|
||||
#define GLTF_ACCESSOR_H
|
||||
/*************************************************************************/
|
||||
/* gltf_accessor.h */
|
||||
/*************************************************************************/
|
||||
@ -30,9 +28,12 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/resource.h"
|
||||
#ifndef GLTF_ACCESSOR_H
|
||||
#define GLTF_ACCESSOR_H
|
||||
|
||||
#include "gltf_document.h"
|
||||
#include "core/io/resource.h"
|
||||
|
||||
#include "../gltf_defines.h"
|
||||
|
||||
struct GLTFAccessor : public Resource {
|
||||
GDCLASS(GLTFAccessor, Resource);
|
||||
@ -44,9 +45,9 @@ private:
|
||||
int component_type = 0;
|
||||
bool normalized = false;
|
||||
int count = 0;
|
||||
GLTFDocument::GLTFType type = GLTFDocument::TYPE_SCALAR;
|
||||
PoolVector<float> min;
|
||||
PoolVector<float> max;
|
||||
GLTFType type = GLTFType::TYPE_SCALAR;
|
||||
Vector<double> min;
|
||||
Vector<double> max;
|
||||
int sparse_count = 0;
|
||||
int sparse_indices_buffer_view = 0;
|
||||
int sparse_indices_byte_offset = 0;
|
||||
@ -76,11 +77,11 @@ public:
|
||||
int get_type();
|
||||
void set_type(int p_type);
|
||||
|
||||
PoolVector<float> get_min();
|
||||
void set_min(PoolVector<float> p_min);
|
||||
Vector<double> get_min();
|
||||
void set_min(Vector<double> p_min);
|
||||
|
||||
PoolVector<float> get_max();
|
||||
void set_max(PoolVector<float> p_max);
|
||||
Vector<double> get_max();
|
||||
void set_max(Vector<double> p_max);
|
||||
|
||||
int get_sparse_count();
|
||||
void set_sparse_count(int p_sparse_count);
|
@ -45,7 +45,7 @@ void GLTFAnimation::set_loop(bool p_val) {
|
||||
loop = p_val;
|
||||
}
|
||||
|
||||
Map<int, GLTFAnimation::Track> &GLTFAnimation::get_tracks() {
|
||||
HashMap<int, GLTFAnimation::Track> &GLTFAnimation::get_tracks() {
|
||||
return tracks;
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
#ifndef GLTF_ANIMATION_H
|
||||
#define GLTF_ANIMATION_H
|
||||
/*************************************************************************/
|
||||
/* gltf_animation.h */
|
||||
/*************************************************************************/
|
||||
@ -30,7 +28,10 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/resource.h"
|
||||
#ifndef GLTF_ANIMATION_H
|
||||
#define GLTF_ANIMATION_H
|
||||
|
||||
#include "core/io/resource.h"
|
||||
|
||||
class GLTFAnimation : public Resource {
|
||||
GDCLASS(GLTFAnimation, Resource);
|
||||
@ -49,26 +50,26 @@ public:
|
||||
template <class T>
|
||||
struct Channel {
|
||||
Interpolation interpolation;
|
||||
Vector<float> times;
|
||||
Vector<real_t> times;
|
||||
Vector<T> values;
|
||||
};
|
||||
|
||||
struct Track {
|
||||
Channel<Vector3> translation_track;
|
||||
Channel<Quat> rotation_track;
|
||||
Channel<Vector3> position_track;
|
||||
Channel<Quaternion> rotation_track;
|
||||
Channel<Vector3> scale_track;
|
||||
Vector<Channel<float>> weight_tracks;
|
||||
Vector<Channel<real_t>> weight_tracks;
|
||||
};
|
||||
|
||||
public:
|
||||
bool get_loop() const;
|
||||
void set_loop(bool p_val);
|
||||
Map<int, GLTFAnimation::Track> &get_tracks();
|
||||
HashMap<int, GLTFAnimation::Track> &get_tracks();
|
||||
GLTFAnimation();
|
||||
|
||||
private:
|
||||
bool loop = false;
|
||||
Map<int, Track> tracks;
|
||||
HashMap<int, Track> tracks;
|
||||
};
|
||||
|
||||
#endif // GLTF_ANIMATION_H
|
@ -30,6 +30,8 @@
|
||||
|
||||
#include "gltf_buffer_view.h"
|
||||
|
||||
#include "../gltf_document_extension.h"
|
||||
|
||||
void GLTFBufferView::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_buffer"), &GLTFBufferView::get_buffer);
|
||||
ClassDB::bind_method(D_METHOD("set_buffer", "buffer"), &GLTFBufferView::set_buffer);
|
@ -1,5 +1,3 @@
|
||||
#ifndef GLTF_BUFFER_VIEW_H
|
||||
#define GLTF_BUFFER_VIEW_H
|
||||
/*************************************************************************/
|
||||
/* gltf_buffer_view.h */
|
||||
/*************************************************************************/
|
||||
@ -30,9 +28,11 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/resource.h"
|
||||
#ifndef GLTF_BUFFER_VIEW_H
|
||||
#define GLTF_BUFFER_VIEW_H
|
||||
|
||||
#include "gltf_document.h"
|
||||
#include "../gltf_defines.h"
|
||||
#include "core/io/resource.h"
|
||||
|
||||
class GLTFBufferView : public Resource {
|
||||
GDCLASS(GLTFBufferView, Resource);
|
@ -35,13 +35,13 @@ void GLTFCamera::_bind_methods() {
|
||||
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_zfar"), &GLTFCamera::get_zfar);
|
||||
ClassDB::bind_method(D_METHOD("set_zfar", "zfar"), &GLTFCamera::set_zfar);
|
||||
ClassDB::bind_method(D_METHOD("get_znear"), &GLTFCamera::get_znear);
|
||||
ClassDB::bind_method(D_METHOD("set_znear", "znear"), &GLTFCamera::set_znear);
|
||||
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::REAL, "fov_size"), "set_fov_size", "get_fov_size"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "zfar"), "set_zfar", "get_zfar"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "znear"), "set_znear", "get_znear"); // float
|
||||
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
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
#ifndef GLTF_CAMERA_H
|
||||
#define GLTF_CAMERA_H
|
||||
/*************************************************************************/
|
||||
/* gltf_camera.h */
|
||||
/*************************************************************************/
|
||||
@ -30,7 +28,10 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/resource.h"
|
||||
#ifndef GLTF_CAMERA_H
|
||||
#define GLTF_CAMERA_H
|
||||
|
||||
#include "core/io/resource.h"
|
||||
|
||||
class GLTFCamera : public Resource {
|
||||
GDCLASS(GLTFCamera, Resource);
|
||||
@ -38,8 +39,8 @@ class GLTFCamera : public Resource {
|
||||
private:
|
||||
bool perspective = true;
|
||||
float fov_size = 75.0;
|
||||
float zfar = 4000.0;
|
||||
float znear = 0.05;
|
||||
float depth_far = 4000.0;
|
||||
float depth_near = 0.05;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
@ -49,10 +50,10 @@ public:
|
||||
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_zfar() const { return zfar; }
|
||||
void set_zfar(float p_val) { zfar = p_val; }
|
||||
float get_znear() const { return znear; }
|
||||
void set_znear(float p_val) { znear = 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; }
|
||||
};
|
||||
|
||||
#endif // GLTF_CAMERA_H
|
@ -30,6 +30,8 @@
|
||||
|
||||
#include "gltf_mesh.h"
|
||||
|
||||
#include "scene/resources/importer_mesh.h"
|
||||
|
||||
void GLTFMesh::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_mesh"), &GLTFMesh::get_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &GLTFMesh::set_mesh);
|
||||
@ -39,15 +41,15 @@ void GLTFMesh::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_instance_materials", "instance_materials"), &GLTFMesh::set_instance_materials);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh"), "set_mesh", "get_mesh");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_REAL_ARRAY, "blend_weights"), "set_blend_weights", "get_blend_weights"); // Vector<float>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT32_ARRAY, "blend_weights"), "set_blend_weights", "get_blend_weights"); // Vector<float>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "instance_materials"), "set_instance_materials", "get_instance_materials");
|
||||
}
|
||||
|
||||
Ref<ArrayMesh> GLTFMesh::get_mesh() {
|
||||
Ref<ImporterMesh> GLTFMesh::get_mesh() {
|
||||
return mesh;
|
||||
}
|
||||
|
||||
void GLTFMesh::set_mesh(Ref<ArrayMesh> p_mesh) {
|
||||
void GLTFMesh::set_mesh(Ref<ImporterMesh> p_mesh) {
|
||||
mesh = p_mesh;
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
#ifndef GLTF_MESH_H
|
||||
#define GLTF_MESH_H
|
||||
/*************************************************************************/
|
||||
/* gltf_mesh.h */
|
||||
/*************************************************************************/
|
||||
@ -30,14 +28,19 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/resource.h"
|
||||
#ifndef GLTF_MESH_H
|
||||
#define GLTF_MESH_H
|
||||
|
||||
#include "core/io/resource.h"
|
||||
#include "scene/3d/importer_mesh_instance_3d.h"
|
||||
#include "scene/resources/importer_mesh.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
|
||||
class GLTFMesh : public Resource {
|
||||
GDCLASS(GLTFMesh, Resource);
|
||||
|
||||
private:
|
||||
Ref<ArrayMesh> mesh;
|
||||
Ref<ImporterMesh> mesh;
|
||||
Vector<float> blend_weights;
|
||||
Array instance_materials;
|
||||
|
||||
@ -45,8 +48,8 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
Ref<ArrayMesh> get_mesh();
|
||||
void set_mesh(Ref<ArrayMesh> p_mesh);
|
||||
Ref<ImporterMesh> get_mesh();
|
||||
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();
|
@ -47,8 +47,8 @@ void GLTFNode::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_skeleton", "skeleton"), &GLTFNode::set_skeleton);
|
||||
ClassDB::bind_method(D_METHOD("get_joint"), &GLTFNode::get_joint);
|
||||
ClassDB::bind_method(D_METHOD("set_joint", "joint"), &GLTFNode::set_joint);
|
||||
ClassDB::bind_method(D_METHOD("get_translation"), &GLTFNode::get_translation);
|
||||
ClassDB::bind_method(D_METHOD("set_translation", "translation"), &GLTFNode::set_translation);
|
||||
ClassDB::bind_method(D_METHOD("get_position"), &GLTFNode::get_position);
|
||||
ClassDB::bind_method(D_METHOD("set_position", "position"), &GLTFNode::set_position);
|
||||
ClassDB::bind_method(D_METHOD("get_rotation"), &GLTFNode::get_rotation);
|
||||
ClassDB::bind_method(D_METHOD("set_rotation", "rotation"), &GLTFNode::set_rotation);
|
||||
ClassDB::bind_method(D_METHOD("get_scale"), &GLTFNode::get_scale);
|
||||
@ -60,16 +60,16 @@ void GLTFNode::_bind_methods() {
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "parent"), "set_parent", "get_parent"); // GLTFNodeIndex
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "height"), "set_height", "get_height"); // int
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "xform"), "set_xform", "get_xform"); // Transform
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "xform"), "set_xform", "get_xform"); // Transform3D
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "mesh"), "set_mesh", "get_mesh"); // GLTFMeshIndex
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "camera"), "set_camera", "get_camera"); // GLTFCameraIndex
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "skin"), "set_skin", "get_skin"); // GLTFSkinIndex
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "skeleton"), "set_skeleton", "get_skeleton"); // GLTFSkeletonIndex
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "joint"), "set_joint", "get_joint"); // bool
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "translation"), "set_translation", "get_translation"); // Vector3
|
||||
ADD_PROPERTY(PropertyInfo(Variant::QUAT, "rotation"), "set_rotation", "get_rotation"); // Quat
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position"), "set_position", "get_position"); // Vector3
|
||||
ADD_PROPERTY(PropertyInfo(Variant::QUATERNION, "rotation"), "set_rotation", "get_rotation"); // Quaternion
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale"), "set_scale", "get_scale"); // Vector3
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "children"), "set_children", "get_children"); // Vector<int>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "children"), "set_children", "get_children"); // Vector<int>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "light"), "set_light", "get_light"); // GLTFLightIndex
|
||||
}
|
||||
|
||||
@ -89,11 +89,11 @@ void GLTFNode::set_height(int p_height) {
|
||||
height = p_height;
|
||||
}
|
||||
|
||||
Transform GLTFNode::get_xform() {
|
||||
Transform3D GLTFNode::get_xform() {
|
||||
return xform;
|
||||
}
|
||||
|
||||
void GLTFNode::set_xform(Transform p_xform) {
|
||||
void GLTFNode::set_xform(Transform3D p_xform) {
|
||||
xform = p_xform;
|
||||
}
|
||||
|
||||
@ -137,19 +137,19 @@ void GLTFNode::set_joint(bool p_joint) {
|
||||
joint = p_joint;
|
||||
}
|
||||
|
||||
Vector3 GLTFNode::get_translation() {
|
||||
return translation;
|
||||
Vector3 GLTFNode::get_position() {
|
||||
return position;
|
||||
}
|
||||
|
||||
void GLTFNode::set_translation(Vector3 p_translation) {
|
||||
translation = p_translation;
|
||||
void GLTFNode::set_position(Vector3 p_position) {
|
||||
position = p_position;
|
||||
}
|
||||
|
||||
Quat GLTFNode::get_rotation() {
|
||||
Quaternion GLTFNode::get_rotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
void GLTFNode::set_rotation(Quat p_rotation) {
|
||||
void GLTFNode::set_rotation(Quaternion p_rotation) {
|
||||
rotation = p_rotation;
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
#ifndef GLTF_NODE_H
|
||||
#define GLTF_NODE_H
|
||||
/*************************************************************************/
|
||||
/* gltf_node.h */
|
||||
/*************************************************************************/
|
||||
@ -30,27 +28,28 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/resource.h"
|
||||
#ifndef GLTF_NODE_H
|
||||
#define GLTF_NODE_H
|
||||
|
||||
#include "gltf_document.h"
|
||||
#include "../gltf_defines.h"
|
||||
#include "core/io/resource.h"
|
||||
|
||||
class GLTFNode : public Resource {
|
||||
GDCLASS(GLTFNode, Resource);
|
||||
friend class GLTFDocument;
|
||||
friend class PackedSceneGLTF;
|
||||
|
||||
private:
|
||||
// matrices need to be transformed to this
|
||||
GLTFNodeIndex parent = -1;
|
||||
int height = -1;
|
||||
Transform xform;
|
||||
Transform3D xform;
|
||||
GLTFMeshIndex mesh = -1;
|
||||
GLTFCameraIndex camera = -1;
|
||||
GLTFSkinIndex skin = -1;
|
||||
GLTFSkeletonIndex skeleton = -1;
|
||||
bool joint = false;
|
||||
Vector3 translation;
|
||||
Quat rotation;
|
||||
Vector3 position;
|
||||
Quaternion rotation;
|
||||
Vector3 scale = Vector3(1, 1, 1);
|
||||
Vector<int> children;
|
||||
GLTFLightIndex light = -1;
|
||||
@ -65,8 +64,8 @@ public:
|
||||
int get_height();
|
||||
void set_height(int p_height);
|
||||
|
||||
Transform get_xform();
|
||||
void set_xform(Transform p_xform);
|
||||
Transform3D get_xform();
|
||||
void set_xform(Transform3D p_xform);
|
||||
|
||||
GLTFMeshIndex get_mesh();
|
||||
void set_mesh(GLTFMeshIndex p_mesh);
|
||||
@ -83,11 +82,11 @@ public:
|
||||
bool get_joint();
|
||||
void set_joint(bool p_joint);
|
||||
|
||||
Vector3 get_translation();
|
||||
void set_translation(Vector3 p_translation);
|
||||
Vector3 get_position();
|
||||
void set_position(Vector3 p_position);
|
||||
|
||||
Quat get_rotation();
|
||||
void set_rotation(Quat p_rotation);
|
||||
Quaternion get_rotation();
|
||||
void set_rotation(Quaternion p_rotation);
|
||||
|
||||
Vector3 get_scale();
|
||||
void set_scale(Vector3 p_scale);
|
@ -30,62 +30,65 @@
|
||||
|
||||
#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);
|
||||
ClassDB::bind_method(D_METHOD("get_roots"), &GLTFSkeleton::get_roots);
|
||||
ClassDB::bind_method(D_METHOD("set_roots", "roots"), &GLTFSkeleton::set_roots);
|
||||
ClassDB::bind_method(D_METHOD("get_pandemonium_skeleton"), &GLTFSkeleton::get_pandemonium_skeleton);
|
||||
ClassDB::bind_method(D_METHOD("get_godot_skeleton"), &GLTFSkeleton::get_godot_skeleton);
|
||||
ClassDB::bind_method(D_METHOD("get_unique_names"), &GLTFSkeleton::get_unique_names);
|
||||
ClassDB::bind_method(D_METHOD("set_unique_names", "unique_names"), &GLTFSkeleton::set_unique_names);
|
||||
ClassDB::bind_method(D_METHOD("get_pandemonium_bone_node"), &GLTFSkeleton::get_pandemonium_bone_node);
|
||||
ClassDB::bind_method(D_METHOD("set_pandemonium_bone_node", "pandemonium_bone_node"), &GLTFSkeleton::set_pandemonium_bone_node);
|
||||
ClassDB::bind_method(D_METHOD("get_godot_bone_node"), &GLTFSkeleton::get_godot_bone_node);
|
||||
ClassDB::bind_method(D_METHOD("set_godot_bone_node", "godot_bone_node"), &GLTFSkeleton::set_godot_bone_node);
|
||||
ClassDB::bind_method(D_METHOD("get_bone_attachment_count"), &GLTFSkeleton::get_bone_attachment_count);
|
||||
ClassDB::bind_method(D_METHOD("get_bone_attachment", "idx"), &GLTFSkeleton::get_bone_attachment);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "joints"), "set_joints", "get_joints"); // PoolVector<GLTFNodeIndex>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "roots"), "set_roots", "get_roots"); // PoolVector<GLTFNodeIndex>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "joints"), "set_joints", "get_joints"); // Vector<GLTFNodeIndex>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "roots"), "set_roots", "get_roots"); // Vector<GLTFNodeIndex>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "unique_names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_unique_names", "get_unique_names"); // Set<String>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "pandemonium_bone_node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_pandemonium_bone_node", "get_pandemonium_bone_node"); // Map<int32_t,
|
||||
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "godot_bone_node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_godot_bone_node", "get_godot_bone_node"); // RBMap<int32_t,
|
||||
}
|
||||
|
||||
PoolVector<GLTFNodeIndex> GLTFSkeleton::get_joints() {
|
||||
Vector<GLTFNodeIndex> GLTFSkeleton::get_joints() {
|
||||
return joints;
|
||||
}
|
||||
|
||||
void GLTFSkeleton::set_joints(PoolVector<GLTFNodeIndex> p_joints) {
|
||||
void GLTFSkeleton::set_joints(Vector<GLTFNodeIndex> p_joints) {
|
||||
joints = p_joints;
|
||||
}
|
||||
|
||||
PoolVector<GLTFNodeIndex> GLTFSkeleton::get_roots() {
|
||||
Vector<GLTFNodeIndex> GLTFSkeleton::get_roots() {
|
||||
return roots;
|
||||
}
|
||||
|
||||
void GLTFSkeleton::set_roots(PoolVector<GLTFNodeIndex> p_roots) {
|
||||
void GLTFSkeleton::set_roots(Vector<GLTFNodeIndex> p_roots) {
|
||||
roots = p_roots;
|
||||
}
|
||||
|
||||
Skeleton *GLTFSkeleton::get_pandemonium_skeleton() {
|
||||
return pandemonium_skeleton;
|
||||
Skeleton3D *GLTFSkeleton::get_godot_skeleton() {
|
||||
return godot_skeleton;
|
||||
}
|
||||
|
||||
Array GLTFSkeleton::get_unique_names() {
|
||||
return GLTFDocument::to_array(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);
|
||||
GLTFTemplateConvert::set_from_array(unique_names, p_unique_names);
|
||||
}
|
||||
|
||||
Dictionary GLTFSkeleton::get_pandemonium_bone_node() {
|
||||
return GLTFDocument::to_dict(pandemonium_bone_node);
|
||||
Dictionary GLTFSkeleton::get_godot_bone_node() {
|
||||
return GLTFTemplateConvert::to_dict(godot_bone_node);
|
||||
}
|
||||
|
||||
void GLTFSkeleton::set_pandemonium_bone_node(Dictionary p_indict) {
|
||||
GLTFDocument::set_from_dict(pandemonium_bone_node, p_indict);
|
||||
void GLTFSkeleton::set_godot_bone_node(Dictionary p_indict) {
|
||||
GLTFTemplateConvert::set_from_dict(godot_bone_node, p_indict);
|
||||
}
|
||||
|
||||
BoneAttachment *GLTFSkeleton::get_bone_attachment(int idx) {
|
||||
BoneAttachment3D *GLTFSkeleton::get_bone_attachment(int idx) {
|
||||
ERR_FAIL_INDEX_V(idx, bone_attachments.size(), nullptr);
|
||||
return bone_attachments[idx];
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
#ifndef GLTF_SKELETON_H
|
||||
#define GLTF_SKELETON_H
|
||||
/*************************************************************************/
|
||||
/* gltf_skeleton.h */
|
||||
/*************************************************************************/
|
||||
@ -30,9 +28,11 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/resource.h"
|
||||
#ifndef GLTF_SKELETON_H
|
||||
#define GLTF_SKELETON_H
|
||||
|
||||
#include "gltf_document.h"
|
||||
#include "../gltf_defines.h"
|
||||
#include "core/io/resource.h"
|
||||
|
||||
class GLTFSkeleton : public Resource {
|
||||
GDCLASS(GLTFSkeleton, Resource);
|
||||
@ -40,41 +40,61 @@ class GLTFSkeleton : public Resource {
|
||||
|
||||
private:
|
||||
// The *synthesized* skeletons joints
|
||||
PoolVector<GLTFNodeIndex> joints;
|
||||
Vector<GLTFNodeIndex> joints;
|
||||
|
||||
// The roots of the skeleton. If there are multiple, each root must have the
|
||||
// same parent (ie roots are siblings)
|
||||
PoolVector<GLTFNodeIndex> roots;
|
||||
Vector<GLTFNodeIndex> roots;
|
||||
|
||||
// The created Skeleton for the scene
|
||||
Skeleton *pandemonium_skeleton = nullptr;
|
||||
// The created Skeleton3D for the scene
|
||||
Skeleton3D *godot_skeleton = nullptr;
|
||||
|
||||
// Set of unique bone names for the skeleton
|
||||
Set<String> unique_names;
|
||||
HashSet<String> unique_names;
|
||||
|
||||
Map<int32_t, GLTFNodeIndex> pandemonium_bone_node;
|
||||
HashMap<int32_t, GLTFNodeIndex> godot_bone_node;
|
||||
|
||||
PoolVector<BoneAttachment *> bone_attachments;
|
||||
Vector<BoneAttachment3D *> bone_attachments;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
PoolVector<GLTFNodeIndex> get_joints();
|
||||
void set_joints(PoolVector<GLTFNodeIndex> p_joints);
|
||||
Vector<GLTFNodeIndex> get_joints();
|
||||
void set_joints(Vector<GLTFNodeIndex> p_joints);
|
||||
|
||||
PoolVector<GLTFNodeIndex> get_roots();
|
||||
void set_roots(PoolVector<GLTFNodeIndex> p_roots);
|
||||
Vector<GLTFNodeIndex> get_roots();
|
||||
void set_roots(Vector<GLTFNodeIndex> p_roots);
|
||||
|
||||
Skeleton *get_pandemonium_skeleton();
|
||||
Skeleton3D *get_godot_skeleton();
|
||||
|
||||
// Skeleton *get_godot_skeleton() {
|
||||
// return this->godot_skeleton;
|
||||
// }
|
||||
// void set_godot_skeleton(Skeleton p_*godot_skeleton) {
|
||||
// this->godot_skeleton = p_godot_skeleton;
|
||||
// }
|
||||
|
||||
Array get_unique_names();
|
||||
void set_unique_names(Array p_unique_names);
|
||||
|
||||
Dictionary get_pandemonium_bone_node();
|
||||
void set_pandemonium_bone_node(Dictionary p_indict);
|
||||
//RBMap<int32_t, GLTFNodeIndex> get_godot_bone_node() {
|
||||
// return this->godot_bone_node;
|
||||
//}
|
||||
//void set_godot_bone_node(RBMap<int32_t, GLTFNodeIndex> p_godot_bone_node) {
|
||||
// this->godot_bone_node = p_godot_bone_node;
|
||||
//}
|
||||
Dictionary get_godot_bone_node();
|
||||
void set_godot_bone_node(Dictionary p_indict);
|
||||
|
||||
BoneAttachment *get_bone_attachment(int idx);
|
||||
//Dictionary get_godot_bone_node() {
|
||||
// return VariantConversion::to_dict(this->godot_bone_node);
|
||||
//}
|
||||
//void set_godot_bone_node(Dictionary p_indict) {
|
||||
// VariantConversion::set_from_dict(this->godot_bone_node, p_indict);
|
||||
//}
|
||||
|
||||
BoneAttachment3D *get_bone_attachment(int idx);
|
||||
|
||||
int32_t get_bone_attachment_count();
|
||||
};
|
@ -30,6 +30,7 @@
|
||||
|
||||
#include "gltf_skin.h"
|
||||
|
||||
#include "../gltf_template_convert.h"
|
||||
#include "scene/resources/skin.h"
|
||||
|
||||
void GLTFSkin::_bind_methods() {
|
||||
@ -51,19 +52,19 @@ void GLTFSkin::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_joint_i_to_bone_i", "joint_i_to_bone_i"), &GLTFSkin::set_joint_i_to_bone_i);
|
||||
ClassDB::bind_method(D_METHOD("get_joint_i_to_name"), &GLTFSkin::get_joint_i_to_name);
|
||||
ClassDB::bind_method(D_METHOD("set_joint_i_to_name", "joint_i_to_name"), &GLTFSkin::set_joint_i_to_name);
|
||||
ClassDB::bind_method(D_METHOD("get_pandemonium_skin"), &GLTFSkin::get_pandemonium_skin);
|
||||
ClassDB::bind_method(D_METHOD("set_pandemonium_skin", "pandemonium_skin"), &GLTFSkin::set_pandemonium_skin);
|
||||
ClassDB::bind_method(D_METHOD("get_godot_skin"), &GLTFSkin::get_godot_skin);
|
||||
ClassDB::bind_method(D_METHOD("set_godot_skin", "godot_skin"), &GLTFSkin::set_godot_skin);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "skin_root"), "set_skin_root", "get_skin_root"); // GLTFNodeIndex
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "joints_original"), "set_joints_original", "get_joints_original"); // Vector<GLTFNodeIndex>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "inverse_binds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_inverse_binds", "get_inverse_binds"); // Vector<Transform>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "joints"), "set_joints", "get_joints"); // Vector<GLTFNodeIndex>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "non_joints"), "set_non_joints", "get_non_joints"); // Vector<GLTFNodeIndex>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "roots"), "set_roots", "get_roots"); // Vector<GLTFNodeIndex>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "joints_original"), "set_joints_original", "get_joints_original"); // Vector<GLTFNodeIndex>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "inverse_binds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_inverse_binds", "get_inverse_binds"); // Vector<Transform3D>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "joints"), "set_joints", "get_joints"); // Vector<GLTFNodeIndex>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "non_joints"), "set_non_joints", "get_non_joints"); // Vector<GLTFNodeIndex>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "roots"), "set_roots", "get_roots"); // Vector<GLTFNodeIndex>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "skeleton"), "set_skeleton", "get_skeleton"); // int
|
||||
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "joint_i_to_bone_i", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_joint_i_to_bone_i", "get_joint_i_to_bone_i"); // Map<int,
|
||||
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "joint_i_to_name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_joint_i_to_name", "get_joint_i_to_name"); // Map<int,
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "pandemonium_skin"), "set_pandemonium_skin", "get_pandemonium_skin"); // Ref<Skin>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "joint_i_to_bone_i", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_joint_i_to_bone_i", "get_joint_i_to_bone_i"); // RBMap<int,
|
||||
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "joint_i_to_name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_joint_i_to_name", "get_joint_i_to_name"); // RBMap<int,
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "godot_skin"), "set_godot_skin", "get_godot_skin"); // Ref<Skin>
|
||||
}
|
||||
|
||||
GLTFNodeIndex GLTFSkin::get_skin_root() {
|
||||
@ -83,11 +84,11 @@ void GLTFSkin::set_joints_original(Vector<GLTFNodeIndex> p_joints_original) {
|
||||
}
|
||||
|
||||
Array GLTFSkin::get_inverse_binds() {
|
||||
return GLTFDocument::to_array(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);
|
||||
GLTFTemplateConvert::set_from_array(inverse_binds, p_inverse_binds);
|
||||
}
|
||||
|
||||
Vector<GLTFNodeIndex> GLTFSkin::get_joints() {
|
||||
@ -123,41 +124,35 @@ 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() {
|
||||
Dictionary ret;
|
||||
Map<int, StringName>::Element *elem = joint_i_to_name.front();
|
||||
HashMap<int, StringName>::Iterator elem = joint_i_to_name.begin();
|
||||
while (elem) {
|
||||
ret[elem->key()] = String(elem->value());
|
||||
elem = elem->next();
|
||||
ret[elem->key] = String(elem->value);
|
||||
++elem;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void GLTFSkin::set_joint_i_to_name(Dictionary p_joint_i_to_name) {
|
||||
joint_i_to_name = Map<int, StringName>();
|
||||
joint_i_to_name = HashMap<int, StringName>();
|
||||
Array keys = p_joint_i_to_name.keys();
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
joint_i_to_name[keys[i]] = p_joint_i_to_name[keys[i]];
|
||||
}
|
||||
}
|
||||
|
||||
Ref<Skin> GLTFSkin::get_pandemonium_skin() {
|
||||
return pandemonium_skin;
|
||||
Ref<Skin> GLTFSkin::get_godot_skin() {
|
||||
return godot_skin;
|
||||
}
|
||||
|
||||
void GLTFSkin::set_pandemonium_skin(Ref<Skin> p_pandemonium_skin) {
|
||||
pandemonium_skin = p_pandemonium_skin;
|
||||
}
|
||||
|
||||
GLTFSkin::GLTFSkin() {
|
||||
}
|
||||
|
||||
GLTFSkin::~GLTFSkin() {
|
||||
void GLTFSkin::set_godot_skin(Ref<Skin> p_godot_skin) {
|
||||
godot_skin = p_godot_skin;
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
#ifndef GLTF_SKIN_H
|
||||
#define GLTF_SKIN_H
|
||||
/*************************************************************************/
|
||||
/* gltf_skin.h */
|
||||
/*************************************************************************/
|
||||
@ -30,11 +28,11 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/resource.h"
|
||||
#ifndef GLTF_SKIN_H
|
||||
#define GLTF_SKIN_H
|
||||
|
||||
#include "gltf_document.h"
|
||||
|
||||
class Skin;
|
||||
#include "../gltf_defines.h"
|
||||
#include "core/io/resource.h"
|
||||
|
||||
class GLTFSkin : public Resource {
|
||||
GDCLASS(GLTFSkin, Resource);
|
||||
@ -45,7 +43,7 @@ private:
|
||||
GLTFNodeIndex skin_root = -1;
|
||||
|
||||
Vector<GLTFNodeIndex> joints_original;
|
||||
Vector<Transform> inverse_binds;
|
||||
Vector<Transform3D> inverse_binds;
|
||||
|
||||
// Note: joints + non_joints should form a complete subtree, or subtrees
|
||||
// with a common parent
|
||||
@ -66,13 +64,13 @@ private:
|
||||
GLTFSkeletonIndex skeleton = -1;
|
||||
|
||||
// A mapping from the joint indices (in the order of joints_original) to the
|
||||
// Pandemonium Skeleton's bone_indices
|
||||
Map<int, int> joint_i_to_bone_i;
|
||||
Map<int, StringName> joint_i_to_name;
|
||||
// Godot Skeleton's bone_indices
|
||||
HashMap<int, int> joint_i_to_bone_i;
|
||||
HashMap<int, StringName> joint_i_to_name;
|
||||
|
||||
// The Actual Skin that will be created as a mapping between the IBM's of
|
||||
// this skin to the generated skeleton for the mesh instances.
|
||||
Ref<Skin> pandemonium_skin;
|
||||
Ref<Skin> godot_skin;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
@ -105,11 +103,8 @@ public:
|
||||
Dictionary get_joint_i_to_name();
|
||||
void set_joint_i_to_name(Dictionary p_joint_i_to_name);
|
||||
|
||||
Ref<Skin> get_pandemonium_skin();
|
||||
void set_pandemonium_skin(Ref<Skin> p_pandemonium_skin);
|
||||
|
||||
GLTFSkin();
|
||||
~GLTFSkin();
|
||||
Ref<Skin> get_godot_skin();
|
||||
void set_godot_skin(Ref<Skin> p_godot_skin);
|
||||
};
|
||||
|
||||
#endif // GLTF_SKIN_H
|
@ -1,5 +1,3 @@
|
||||
#ifndef GLTF_TEXTURE_H
|
||||
#define GLTF_TEXTURE_H
|
||||
/*************************************************************************/
|
||||
/* gltf_texture.h */
|
||||
/*************************************************************************/
|
||||
@ -30,9 +28,11 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/resource.h"
|
||||
#ifndef GLTF_TEXTURE_H
|
||||
#define GLTF_TEXTURE_H
|
||||
|
||||
#include "gltf_document.h"
|
||||
#include "../gltf_defines.h"
|
||||
#include "core/io/resource.h"
|
||||
|
||||
class GLTFTexture : public Resource {
|
||||
GDCLASS(GLTFTexture, Resource);
|
Loading…
Reference in New Issue
Block a user