mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-03-25 21:52:13 +01:00
Switched back to the old gltf module. Apparently this one can export aswell.
This commit is contained in:
parent
9ae0437034
commit
d89dc61436
@ -1,11 +0,0 @@
|
||||
# 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,20 +5,5 @@ Import("env_modules")
|
||||
|
||||
env_gltf = env_modules.Clone()
|
||||
|
||||
# Godot source files
|
||||
env_gltf.add_source_files(env.modules_sources, "register_types.cpp")
|
||||
|
||||
env_gltf.add_source_files(env.modules_sources, "gltf_state.cpp")
|
||||
env_gltf.add_source_files(env.modules_sources, "gltf_document_extension.cpp")
|
||||
env_gltf.add_source_files(env.modules_sources, "gltf_document_extension_convert_importer_mesh.cpp")
|
||||
env_gltf.add_source_files(env.modules_sources, "gltf_document.cpp")
|
||||
|
||||
#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/editor_scene_importer_gltf.cpp")
|
||||
env_gltf.add_source_files(env.modules_sources, "editor/editor_scene_importer_fbx.cpp")
|
||||
#env_gltf.add_source_files(env.modules_sources, "editor/*.cpp")
|
||||
# Pandemonium's own source files
|
||||
env_gltf.add_source_files(env.modules_sources, "*.cpp")
|
||||
|
@ -1,8 +1,5 @@
|
||||
|
||||
|
||||
def can_build(env, platform):
|
||||
#return not env["disable_3d"]
|
||||
return False
|
||||
return env["tools"] and not env["disable_3d"]
|
||||
|
||||
|
||||
def configure(env):
|
||||
@ -11,16 +8,12 @@ def configure(env):
|
||||
|
||||
def get_doc_classes():
|
||||
return [
|
||||
"EditorSceneFormatImporterBlend",
|
||||
"EditorSceneFormatImporterFBX",
|
||||
"EditorSceneFormatImporterGLTF",
|
||||
"EditorSceneImporterGLTF",
|
||||
"GLTFAccessor",
|
||||
"GLTFAnimation",
|
||||
"GLTFBufferView",
|
||||
"GLTFCamera",
|
||||
"GLTFDocument",
|
||||
"GLTFDocumentExtension",
|
||||
"GLTFDocumentExtensionConvertImporterMesh",
|
||||
"GLTFLight",
|
||||
"GLTFMesh",
|
||||
"GLTFNode",
|
||||
@ -29,6 +22,7 @@ def get_doc_classes():
|
||||
"GLTFSpecGloss",
|
||||
"GLTFState",
|
||||
"GLTFTexture",
|
||||
"PackedSceneGLTF",
|
||||
]
|
||||
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
<?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>
|
@ -1,13 +0,0 @@
|
||||
<?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>
|
@ -1,9 +0,0 @@
|
||||
<?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>
|
14
modules/gltf/doc_classes/EditorSceneImporterGLTF.xml
Normal file
14
modules/gltf/doc_classes/EditorSceneImporterGLTF.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?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,11 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFAccessor" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<class name="GLTFAccessor" inherits="Resource" 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 [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>
|
||||
@ -15,9 +18,9 @@
|
||||
</member>
|
||||
<member name="count" type="int" setter="set_count" getter="get_count" default="0">
|
||||
</member>
|
||||
<member name="max" type="PackedFloat64Array" setter="set_max" getter="get_max" default="PackedFloat64Array()">
|
||||
<member name="max" type="PoolRealArray" setter="set_max" getter="get_max" default="PoolRealArray( )">
|
||||
</member>
|
||||
<member name="min" type="PackedFloat64Array" setter="set_min" getter="get_min" default="PackedFloat64Array()">
|
||||
<member name="min" type="PoolRealArray" setter="set_min" getter="get_min" default="PoolRealArray( )">
|
||||
</member>
|
||||
<member name="normalized" type="bool" setter="set_normalized" getter="get_normalized" default="false">
|
||||
</member>
|
||||
@ -36,4 +39,6 @@
|
||||
<member name="type" type="int" setter="set_type" getter="get_type" default="0">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,13 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFAnimation" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<class name="GLTFAnimation" inherits="Resource" 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 [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,11 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFBufferView" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<class name="GLTFBufferView" inherits="Resource" 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 [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>
|
||||
@ -18,4 +21,6 @@
|
||||
<member name="indices" type="bool" setter="set_indices" getter="get_indices" default="false">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,19 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFCamera" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<class name="GLTFCamera" inherits="Resource" 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 [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,65 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFDocument" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<class name="GLTFDocument" inherits="Resource" version="3.5">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
Append a glTF2 3d format from a file, buffer or scene and then write to the filesystem, buffer or scene.
|
||||
[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.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="append_from_buffer">
|
||||
<return type="int" enum="Error" />
|
||||
<argument index="0" name="bytes" type="PoolByteArray" />
|
||||
<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="PoolByteArray" />
|
||||
<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>
|
||||
<members>
|
||||
<member name="extensions" type="GLTFDocumentExtension[]" setter="set_extensions" getter="get_extensions" default="[]">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,60 +0,0 @@
|
||||
<?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>
|
@ -1,9 +0,0 @@
|
||||
<?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,31 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFLight" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<class name="GLTFLight" inherits="Resource" 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 [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 Godot [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 Pandemonium [SpotLight], 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 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 [OmniLight], [SpotLight], and [DirectionalLight] respectively.
|
||||
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.
|
||||
</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 Godot [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 Pandemonium [SpotLight], 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 Godot light, the range is clamped to 4096.
|
||||
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.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,17 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFMesh" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<class name="GLTFMesh" inherits="Resource" 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 [GLTFMesh] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="blend_weights" type="PackedFloat32Array" setter="set_blend_weights" getter="get_blend_weights" default="PackedFloat32Array()">
|
||||
<member name="blend_weights" type="PoolRealArray" setter="set_blend_weights" getter="get_blend_weights" default="PoolRealArray( )">
|
||||
</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="ImporterMesh" setter="set_mesh" getter="get_mesh">
|
||||
<member name="mesh" type="ArrayMesh" setter="set_mesh" getter="get_mesh">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,15 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFNode" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<class name="GLTFNode" inherits="Resource" 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 [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="PackedInt32Array" setter="set_children" getter="get_children" default="PackedInt32Array()">
|
||||
<member name="children" type="PoolIntArray" setter="set_children" getter="get_children" default="PoolIntArray( )">
|
||||
</member>
|
||||
<member name="height" type="int" setter="set_height" getter="get_height" default="-1">
|
||||
</member>
|
||||
@ -21,17 +24,19 @@
|
||||
</member>
|
||||
<member name="parent" type="int" setter="set_parent" getter="get_parent" default="-1">
|
||||
</member>
|
||||
<member name="position" type="Vector3" setter="set_position" getter="get_position" default="Vector3(0, 0, 0)">
|
||||
<member name="rotation" type="Quat" setter="set_rotation" getter="get_rotation" default="Quat( 0, 0, 0, 1 )">
|
||||
</member>
|
||||
<member name="rotation" type="Quat" setter="set_rotation" getter="get_rotation" default="Quat(0, 0, 0, 1)">
|
||||
</member>
|
||||
<member name="scale" type="Vector3" setter="set_scale" getter="get_scale" default="Vector3(1, 1, 1)">
|
||||
<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="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="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>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFSkeleton" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<class name="GLTFSkeleton" inherits="Resource" 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 [GLTFSkeleton] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
@ -18,12 +19,12 @@
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_godot_bone_node">
|
||||
<method name="get_pandemonium_bone_node">
|
||||
<return type="Dictionary" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_godot_skeleton">
|
||||
<method name="get_pandemonium_skeleton">
|
||||
<return type="Skeleton" />
|
||||
<description>
|
||||
</description>
|
||||
@ -33,9 +34,9 @@
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_godot_bone_node">
|
||||
<method name="set_pandemonium_bone_node">
|
||||
<return type="void" />
|
||||
<argument index="0" name="godot_bone_node" type="Dictionary" />
|
||||
<argument index="0" name="pandemonium_bone_node" type="Dictionary" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
@ -47,9 +48,11 @@
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="joints" type="PackedInt32Array" setter="set_joints" getter="get_joints" default="PackedInt32Array()">
|
||||
<member name="joints" type="PoolIntArray" setter="set_joints" getter="get_joints" default="PoolIntArray( )">
|
||||
</member>
|
||||
<member name="roots" type="PackedInt32Array" setter="set_roots" getter="get_roots" default="PackedInt32Array()">
|
||||
<member name="roots" type="PoolIntArray" setter="set_roots" getter="get_roots" default="PoolIntArray( )">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFSkin" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<class name="GLTFSkin" inherits="Resource" version="3.5">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
@ -42,19 +42,21 @@
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="godot_skin" type="Skin" setter="set_godot_skin" getter="get_godot_skin">
|
||||
<member name="joints" type="PoolIntArray" setter="set_joints" getter="get_joints" default="PoolIntArray( )">
|
||||
</member>
|
||||
<member name="joints" type="PackedInt32Array" setter="set_joints" getter="get_joints" default="PackedInt32Array()">
|
||||
<member name="joints_original" type="PoolIntArray" setter="set_joints_original" getter="get_joints_original" default="PoolIntArray( )">
|
||||
</member>
|
||||
<member name="joints_original" type="PackedInt32Array" setter="set_joints_original" getter="get_joints_original" default="PackedInt32Array()">
|
||||
<member name="non_joints" type="PoolIntArray" setter="set_non_joints" getter="get_non_joints" default="PoolIntArray( )">
|
||||
</member>
|
||||
<member name="non_joints" type="PackedInt32Array" setter="set_non_joints" getter="get_non_joints" default="PackedInt32Array()">
|
||||
<member name="pandemonium_skin" type="Skin" setter="set_pandemonium_skin" getter="get_pandemonium_skin">
|
||||
</member>
|
||||
<member name="roots" type="PackedInt32Array" setter="set_roots" getter="get_roots" default="PackedInt32Array()">
|
||||
<member name="roots" type="PoolIntArray" setter="set_roots" getter="get_roots" default="PoolIntArray( )">
|
||||
</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,13 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFSpecGloss" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<class name="GLTFSpecGloss" inherits="Resource" 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 [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>
|
||||
@ -15,7 +18,9 @@
|
||||
</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,8 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFState" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<class name="GLTFState" inherits="Resource" 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 [GLTFState] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
@ -192,11 +193,9 @@
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="base_path" type="String" setter="set_base_path" getter="get_base_path" default="""">
|
||||
<member name="buffers" type="Array" setter="set_buffers" getter="get_buffers" default="[ ]">
|
||||
</member>
|
||||
<member name="buffers" type="Array" setter="set_buffers" getter="get_buffers" default="[]">
|
||||
</member>
|
||||
<member name="glb_data" type="PoolByteArray" setter="set_glb_data" getter="get_glb_data" default="PoolByteArray()">
|
||||
<member name="glb_data" type="PoolByteArray" setter="set_glb_data" getter="get_glb_data" default="PoolByteArray( )">
|
||||
</member>
|
||||
<member name="json" type="Dictionary" setter="set_json" getter="get_json" default="{}">
|
||||
</member>
|
||||
@ -204,11 +203,13 @@
|
||||
</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,13 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFTexture" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
||||
<class name="GLTFTexture" inherits="Resource" 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 [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>
|
||||
|
46
modules/gltf/doc_classes/PackedSceneGLTF.xml
Normal file
46
modules/gltf/doc_classes/PackedSceneGLTF.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<?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>
|
@ -1,575 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* 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
|
@ -1,112 +0,0 @@
|
||||
#ifndef EDITOR_SCENE_IMPORTER_BLEND_H
|
||||
#define EDITOR_SCENE_IMPORTER_BLEND_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#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
|
@ -1,123 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* 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/os/os.h"
|
||||
#include "core/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, int p_bake_fps, uint32_t p_compress_flags, 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_project_data_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, true, nullptr, &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.instance();
|
||||
Ref<GLTFState> state;
|
||||
state.instance();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
bool EditorSceneFormatImporterFBX::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditorSceneFormatImporterFBX::get_import_options(List<ResourceImporterScene::ImportOption> *r_options, int p_preset) const {
|
||||
}
|
||||
|
||||
EditorSceneFormatImporterFBX::EditorSceneFormatImporterFBX() {
|
||||
}
|
||||
EditorSceneFormatImporterFBX::~EditorSceneFormatImporterFBX() {
|
||||
}
|
||||
|
||||
#endif // TOOLS_ENABLED
|
@ -32,18 +32,9 @@
|
||||
|
||||
#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 {
|
||||
@ -54,58 +45,50 @@ bool SceneExporterGLTFPlugin::has_main_screen() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
SceneExporterGLTFPlugin::SceneExporterGLTFPlugin() {
|
||||
SceneExporterGLTFPlugin::SceneExporterGLTFPlugin(EditorNode *p_node) {
|
||||
editor = p_node;
|
||||
convert_gltf2.instance();
|
||||
file_export_lib = memnew(EditorFileDialog);
|
||||
EditorNode::get_singleton()->get_gui_base()->add_child(file_export_lib);
|
||||
file_export_lib->connect("file_selected", callable_mp(this, &SceneExporterGLTFPlugin::_gltf2_dialog_action));
|
||||
editor->get_gui_base()->add_child(file_export_lib);
|
||||
file_export_lib->connect("file_selected", this, "_gltf2_dialog_action");
|
||||
file_export_lib->set_title(TTR("Export Library"));
|
||||
file_export_lib->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
|
||||
file_export_lib->set_mode(EditorFileDialog::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 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));
|
||||
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()));
|
||||
}
|
||||
|
||||
void SceneExporterGLTFPlugin::_gltf2_dialog_action(String p_file) {
|
||||
Node *root = EditorNode::get_singleton()->get_tree()->get_edited_scene_root();
|
||||
Node *root = editor->get_tree()->get_edited_scene_root();
|
||||
if (!root) {
|
||||
EditorNode::get_singleton()->show_accept(TTR("This operation can't be done without a scene."), TTR("OK"));
|
||||
editor->show_accept(TTR("This operation can't be done without a scene."), TTR("OK"));
|
||||
return;
|
||||
}
|
||||
List<String> deps;
|
||||
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)));
|
||||
}
|
||||
convert_gltf2->save_scene(root, p_file, p_file, 0, 1000.0f, &deps);
|
||||
EditorFileSystem::get_singleton()->scan_changes();
|
||||
}
|
||||
|
||||
void SceneExporterGLTFPlugin::convert_scene_to_gltf2() {
|
||||
Node *root = EditorNode::get_singleton()->get_tree()->get_edited_scene_root();
|
||||
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();
|
||||
if (!root) {
|
||||
EditorNode::get_singleton()->show_accept(TTR("This operation can't be done without a scene."), TTR("OK"));
|
||||
editor->show_accept(TTR("This operation can't be done without a scene."), TTR("OK"));
|
||||
return;
|
||||
}
|
||||
String filename = String(root->get_scene_file_path().get_file().get_basename());
|
||||
if (filename.is_empty()) {
|
||||
String filename = String(root->get_filename().get_file().get_basename());
|
||||
if (filename.empty()) {
|
||||
filename = root->get_name();
|
||||
}
|
||||
file_export_lib->set_current_file(filename + String(".gltf"));
|
||||
file_export_lib->set_current_file(filename + ".gltf");
|
||||
file_export_lib->popup_centered_ratio();
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#ifndef EDITOR_SCENE_EXPORTER_GLTF_PLUGIN_H
|
||||
#define EDITOR_SCENE_EXPORTER_GLTF_PLUGIN_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* editor_scene_exporter_gltf_plugin.h */
|
||||
/*************************************************************************/
|
||||
@ -31,24 +30,27 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "editor/editor_file_dialog.h"
|
||||
#include "editor/editor_plugin.h"
|
||||
#include "editor_scene_importer_gltf.h"
|
||||
|
||||
#include "packed_scene_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();
|
||||
void convert_scene_to_gltf2(Variant p_null);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
virtual String get_name() const override;
|
||||
bool has_main_screen() const override;
|
||||
SceneExporterGLTFPlugin();
|
||||
virtual String get_name() const;
|
||||
bool has_main_screen() const;
|
||||
SceneExporterGLTFPlugin(class EditorNode *p_node);
|
||||
};
|
||||
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
#endif // EDITOR_SCENE_EXPORTER_GLTF_PLUGIN_H
|
@ -31,42 +31,33 @@
|
||||
#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"
|
||||
|
||||
uint32_t EditorSceneFormatImporterGLTF::get_import_flags() const {
|
||||
#include "gltf_state.h"
|
||||
#include "packed_scene_gltf.h"
|
||||
|
||||
uint32_t EditorSceneImporterGLTF::get_import_flags() const {
|
||||
return ImportFlags::IMPORT_SCENE | ImportFlags::IMPORT_ANIMATION;
|
||||
}
|
||||
|
||||
void EditorSceneFormatImporterGLTF::get_extensions(List<String> *r_extensions) const {
|
||||
void EditorSceneImporterGLTF::get_extensions(List<String> *r_extensions) const {
|
||||
r_extensions->push_back("gltf");
|
||||
r_extensions->push_back("glb");
|
||||
}
|
||||
|
||||
Node *EditorSceneFormatImporterGLTF::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<GLTFDocument> doc;
|
||||
doc.instance();
|
||||
Ref<GLTFState> state;
|
||||
state.instance();
|
||||
|
||||
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);
|
||||
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> EditorSceneFormatImporterGLTF::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) {
|
||||
Ref<Animation> EditorSceneImporterGLTF::import_animation(const String &p_path,
|
||||
uint32_t p_flags,
|
||||
int p_bake_fps) {
|
||||
return Ref<Animation>();
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#ifndef EDITOR_SCENE_IMPORTER_GLTF_H
|
||||
#define EDITOR_SCENE_IMPORTER_GLTF_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* editor_scene_importer_gltf.h */
|
||||
/*************************************************************************/
|
||||
@ -33,25 +32,25 @@
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "../gltf_document_extension.h"
|
||||
#include "../gltf_state.h"
|
||||
|
||||
#include "editor/import/resource_importer_scene.h"
|
||||
|
||||
class Animation;
|
||||
class Node;
|
||||
#include "gltf_document.h"
|
||||
#include "gltf_state.h"
|
||||
|
||||
class EditorSceneFormatImporterGLTF : public EditorSceneImporter {
|
||||
GDCLASS(EditorSceneFormatImporterGLTF, EditorSceneImporter);
|
||||
class EditorSceneImporterGLTF : public EditorSceneImporter {
|
||||
GDCLASS(EditorSceneImporterGLTF, EditorSceneImporter);
|
||||
|
||||
public:
|
||||
virtual uint32_t get_import_flags() const;
|
||||
virtual void get_extensions(List<String> *r_extensions) const;
|
||||
|
||||
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);
|
||||
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);
|
||||
};
|
||||
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
#endif // EDITOR_SCENE_IMPORTER_GLTF_H
|
||||
|
||||
#endif // TOOLS_ENABLED
|
@ -65,7 +65,7 @@ void GLTFAccessor::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "component_type"), "set_component_type", "get_component_type"); // int
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "normalized"), "set_normalized", "get_normalized"); // bool
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "count"), "set_count", "get_count"); // int
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "type"), "set_type", "get_type"); // GLTFType
|
||||
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, "sparse_count"), "set_sparse_count", "get_sparse_count"); // int
|
||||
@ -121,22 +121,22 @@ int GLTFAccessor::get_type() {
|
||||
}
|
||||
|
||||
void GLTFAccessor::set_type(int p_type) {
|
||||
type = (GLTFType)p_type; // TODO: Register enum
|
||||
type = (GLTFDocument::GLTFType)p_type; // TODO: Register enum
|
||||
}
|
||||
|
||||
PoolRealArray GLTFAccessor::get_min() {
|
||||
PoolVector<float> GLTFAccessor::get_min() {
|
||||
return min;
|
||||
}
|
||||
|
||||
void GLTFAccessor::set_min(const PoolRealArray &p_min) {
|
||||
void GLTFAccessor::set_min(PoolVector<float> p_min) {
|
||||
min = p_min;
|
||||
}
|
||||
|
||||
PoolRealArray GLTFAccessor::get_max() {
|
||||
PoolVector<float> GLTFAccessor::get_max() {
|
||||
return max;
|
||||
}
|
||||
|
||||
void GLTFAccessor::set_max(const PoolRealArray &p_max) {
|
||||
void GLTFAccessor::set_max(PoolVector<float> p_max) {
|
||||
max = p_max;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#ifndef GLTF_ACCESSOR_H
|
||||
#define GLTF_ACCESSOR_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* gltf_accessor.h */
|
||||
/*************************************************************************/
|
||||
@ -33,7 +32,7 @@
|
||||
|
||||
#include "core/resource.h"
|
||||
|
||||
#include "../gltf_defines.h"
|
||||
#include "gltf_document.h"
|
||||
|
||||
struct GLTFAccessor : public Resource {
|
||||
GDCLASS(GLTFAccessor, Resource);
|
||||
@ -45,9 +44,9 @@ private:
|
||||
int component_type = 0;
|
||||
bool normalized = false;
|
||||
int count = 0;
|
||||
GLTFType type = GLTFType::TYPE_SCALAR;
|
||||
PoolRealArray min;
|
||||
PoolRealArray max;
|
||||
GLTFDocument::GLTFType type = GLTFDocument::TYPE_SCALAR;
|
||||
PoolVector<float> min;
|
||||
PoolVector<float> max;
|
||||
int sparse_count = 0;
|
||||
int sparse_indices_buffer_view = 0;
|
||||
int sparse_indices_byte_offset = 0;
|
||||
@ -77,11 +76,11 @@ public:
|
||||
int get_type();
|
||||
void set_type(int p_type);
|
||||
|
||||
PoolRealArray get_min();
|
||||
void set_min(const PoolRealArray &p_min);
|
||||
PoolVector<float> get_min();
|
||||
void set_min(PoolVector<float> p_min);
|
||||
|
||||
PoolRealArray get_max();
|
||||
void set_max(const PoolRealArray &p_max);
|
||||
PoolVector<float> get_max();
|
||||
void set_max(PoolVector<float> 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;
|
||||
}
|
||||
|
||||
HashMap<int, GLTFAnimation::Track> &GLTFAnimation::get_tracks() {
|
||||
Map<int, GLTFAnimation::Track> &GLTFAnimation::get_tracks() {
|
||||
return tracks;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#ifndef GLTF_ANIMATION_H
|
||||
#define GLTF_ANIMATION_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* gltf_animation.h */
|
||||
/*************************************************************************/
|
||||
@ -50,26 +49,26 @@ public:
|
||||
template <class T>
|
||||
struct Channel {
|
||||
Interpolation interpolation;
|
||||
PoolRealArray times;
|
||||
PoolVector<T> values;
|
||||
Vector<float> times;
|
||||
Vector<T> values;
|
||||
};
|
||||
|
||||
struct Track {
|
||||
Channel<Vector3> position_track;
|
||||
Channel<Vector3> translation_track;
|
||||
Channel<Quat> rotation_track;
|
||||
Channel<Vector3> scale_track;
|
||||
Vector<Channel<real_t>> weight_tracks;
|
||||
Vector<Channel<float>> weight_tracks;
|
||||
};
|
||||
|
||||
public:
|
||||
bool get_loop() const;
|
||||
void set_loop(bool p_val);
|
||||
HashMap<int, GLTFAnimation::Track> &get_tracks();
|
||||
Map<int, GLTFAnimation::Track> &get_tracks();
|
||||
GLTFAnimation();
|
||||
|
||||
private:
|
||||
bool loop = false;
|
||||
HashMap<int, Track> tracks;
|
||||
Map<int, Track> tracks;
|
||||
};
|
||||
|
||||
#endif // GLTF_ANIMATION_H
|
@ -1,6 +1,5 @@
|
||||
#ifndef GLTF_BUFFER_VIEW_H
|
||||
#define GLTF_BUFFER_VIEW_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* gltf_buffer_view.h */
|
||||
/*************************************************************************/
|
||||
@ -31,9 +30,10 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "../gltf_defines.h"
|
||||
#include "core/resource.h"
|
||||
|
||||
#include "gltf_document.h"
|
||||
|
||||
class GLTFBufferView : public Resource {
|
||||
GDCLASS(GLTFBufferView, Resource);
|
||||
friend class GLTFDocument;
|
@ -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_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);
|
||||
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);
|
||||
|
||||
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, "depth_far"), "set_depth_far", "get_depth_far"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "depth_near"), "set_depth_near", "get_depth_near"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "zfar"), "set_zfar", "get_zfar"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "znear"), "set_znear", "get_znear"); // float
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
#ifndef GLTF_CAMERA_H
|
||||
#define GLTF_CAMERA_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* gltf_camera.h */
|
||||
/*************************************************************************/
|
||||
@ -39,8 +38,8 @@ class GLTFCamera : public Resource {
|
||||
private:
|
||||
bool perspective = true;
|
||||
float fov_size = 75.0;
|
||||
float depth_far = 4000.0;
|
||||
float depth_near = 0.05;
|
||||
float zfar = 4000.0;
|
||||
float znear = 0.05;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
@ -50,10 +49,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_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; }
|
||||
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; }
|
||||
};
|
||||
|
||||
#endif // GLTF_CAMERA_H
|
@ -1,85 +0,0 @@
|
||||
#ifndef GLTF_DEFINES_H
|
||||
#define GLTF_DEFINES_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
// This file should only be included by other headers.
|
||||
|
||||
// Godot classes used by GLTF headers.
|
||||
class BoneAttachment;
|
||||
class DirectionalLight;
|
||||
class Light;
|
||||
class MultiMeshInstance;
|
||||
class Skeleton;
|
||||
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,6 +1,5 @@
|
||||
#ifndef GLTF_DOCUMENT_H
|
||||
#define GLTF_DOCUMENT_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* gltf_document.h */
|
||||
/*************************************************************************/
|
||||
@ -31,24 +30,61 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "gltf_defines.h"
|
||||
#include "structures/gltf_animation.h"
|
||||
|
||||
#include "core/os/file_access.h"
|
||||
#include "scene/3d/bone_attachment.h"
|
||||
#include "scene/3d/importer_mesh_instance_3d.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"
|
||||
#include "scene/animation/animation_player.h"
|
||||
#include "scene/resources/material.h"
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
class Camera;
|
||||
class GLTFDocumentExtension;
|
||||
#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;
|
||||
|
||||
private:
|
||||
const float BAKE_FPS = 30.0f;
|
||||
|
||||
public:
|
||||
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,
|
||||
@ -69,26 +105,70 @@ public:
|
||||
COMPONENT_TYPE_FLOAT = 5126,
|
||||
};
|
||||
|
||||
public:
|
||||
void set_extensionsv(const Vector<Ref<GLTFDocumentExtension>> &p_extensions);
|
||||
Vector<Ref<GLTFDocumentExtension>> get_extensionsv() const;
|
||||
|
||||
void set_extensions(const Vector<Variant> &p_extensions);
|
||||
Vector<Variant> get_extensions() const;
|
||||
|
||||
private:
|
||||
void _build_parent_hierachy(Ref<GLTFState> state);
|
||||
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]];
|
||||
}
|
||||
}
|
||||
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 GLTFType p_type);
|
||||
String _get_accessor_type_name(const GLTFDocument::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(const String &name);
|
||||
String _sanitize_bone_name(Ref<GLTFState> state, const String &name);
|
||||
String _gen_unique_bone_name(Ref<GLTFState> state,
|
||||
const GLTFSkeletonIndex skel_i,
|
||||
const String &p_name);
|
||||
@ -96,7 +176,7 @@ private:
|
||||
Ref<Texture> _get_texture(Ref<GLTFState> state,
|
||||
const GLTFTextureIndex p_texture);
|
||||
Error _parse_json(const String &p_path, Ref<GLTFState> state);
|
||||
Error _parse_glb(FileAccess *f, Ref<GLTFState> state);
|
||||
Error _parse_glb(const String &p_path, 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);
|
||||
@ -113,22 +193,22 @@ private:
|
||||
Vector<double> _decode_accessor(Ref<GLTFState> state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
PoolVector<float> _decode_accessor_as_floats(Ref<GLTFState> state,
|
||||
Vector<float> _decode_accessor_as_floats(Ref<GLTFState> state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
PoolIntArray _decode_accessor_as_ints(Ref<GLTFState> state,
|
||||
Vector<int> _decode_accessor_as_ints(Ref<GLTFState> state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<Vector2> _decode_accessor_as_vec2(Ref<GLTFState> state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
PoolVector3Array _decode_accessor_as_vec3(Ref<GLTFState> state,
|
||||
Vector<Vector3> _decode_accessor_as_vec3(Ref<GLTFState> state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<Color> _decode_accessor_as_color(Ref<GLTFState> state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
PoolVector<Quat> _decode_accessor_as_quaternion(Ref<GLTFState> state,
|
||||
Vector<Quat> _decode_accessor_as_quat(Ref<GLTFState> state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<Transform2D> _decode_accessor_as_xform2d(Ref<GLTFState> state,
|
||||
@ -183,17 +263,19 @@ private:
|
||||
Skeleton *skeleton,
|
||||
const GLTFNodeIndex node_index,
|
||||
const GLTFNodeIndex bone_index);
|
||||
ImporterMeshInstance3D *_generate_mesh_instance(Ref<GLTFState> state, const GLTFNodeIndex node_index);
|
||||
Camera *_generate_camera(Ref<GLTFState> state, const GLTFNodeIndex node_index);
|
||||
Spatial *_generate_light(Ref<GLTFState> state, const GLTFNodeIndex node_index);
|
||||
Spatial *_generate_spatial(Ref<GLTFState> state, const GLTFNodeIndex node_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);
|
||||
void _assign_scene_names(Ref<GLTFState> state);
|
||||
template <class T>
|
||||
T _interpolate_track(const PoolRealArray &p_times, const PoolVector<T> &p_values,
|
||||
T _interpolate_track(const Vector<float> &p_times, const Vector<T> &p_values,
|
||||
const float p_time,
|
||||
const GLTFAnimation::Interpolation p_interp);
|
||||
GLTFAccessorIndex _encode_accessor_as_quaternions(Ref<GLTFState> state,
|
||||
const PoolVector<Quat> p_attribs,
|
||||
GLTFAccessorIndex _encode_accessor_as_quats(Ref<GLTFState> state,
|
||||
const Vector<Quat> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
GLTFAccessorIndex _encode_accessor_as_weights(Ref<GLTFState> state,
|
||||
const Vector<Color> p_attribs,
|
||||
@ -202,35 +284,35 @@ private:
|
||||
const Vector<Color> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
GLTFAccessorIndex _encode_accessor_as_floats(Ref<GLTFState> state,
|
||||
const PoolRealArray p_attribs,
|
||||
const Vector<real_t> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
GLTFAccessorIndex _encode_accessor_as_vec2(Ref<GLTFState> state,
|
||||
const Vector<Vector2> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
|
||||
void _calc_accessor_vec2_min_max(int i, const int element_count, PoolRealArray &type_max, Vector2 attribs, PoolRealArray &type_min) {
|
||||
void _calc_accessor_vec2_min_max(int i, const int element_count, Vector<double> &type_max, Vector2 attribs, Vector<double> &type_min) {
|
||||
if (i == 0) {
|
||||
for (int32_t type_i = 0; type_i < element_count; type_i++) {
|
||||
type_max.set(type_i, attribs[(i * element_count) + type_i]);
|
||||
type_min.set(type_i, attribs[(i * element_count) + type_i]);
|
||||
type_max.write[type_i] = attribs[(i * element_count) + type_i];
|
||||
type_min.write[type_i] = attribs[(i * element_count) + type_i];
|
||||
}
|
||||
}
|
||||
for (int32_t type_i = 0; type_i < element_count; type_i++) {
|
||||
type_max.set(type_i, MAX(attribs[(i * element_count) + type_i], type_max[type_i]));
|
||||
type_min.set(type_i, MIN(attribs[(i * element_count) + type_i], type_min[type_i]));
|
||||
type_max.set(type_i, _filter_number(type_max[type_i]));
|
||||
type_min.set(type_i, _filter_number(type_min[type_i]));
|
||||
type_max.write[type_i] = MAX(attribs[(i * element_count) + type_i], type_max[type_i]);
|
||||
type_min.write[type_i] = MIN(attribs[(i * element_count) + type_i], type_min[type_i]);
|
||||
type_max.write[type_i] = _filter_number(type_max.write[type_i]);
|
||||
type_min.write[type_i] = _filter_number(type_min.write[type_i]);
|
||||
}
|
||||
}
|
||||
|
||||
GLTFAccessorIndex _encode_accessor_as_vec3(Ref<GLTFState> state,
|
||||
const PoolVector<Vector3> p_attribs,
|
||||
const Vector<Vector3> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
GLTFAccessorIndex _encode_accessor_as_color(Ref<GLTFState> state,
|
||||
const Vector<Color> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
|
||||
void _calc_accessor_min_max(int p_i, const int p_element_count, PoolRealArray &p_type_max, PoolRealArray p_attribs, PoolRealArray &p_type_min);
|
||||
void _calc_accessor_min_max(int p_i, const int p_element_count, Vector<double> &p_type_max, Vector<double> p_attribs, Vector<double> &p_type_min);
|
||||
|
||||
GLTFAccessorIndex _encode_accessor_as_ints(Ref<GLTFState> state,
|
||||
const Vector<int32_t> p_attribs,
|
||||
@ -238,7 +320,7 @@ private:
|
||||
GLTFAccessorIndex _encode_accessor_as_xform(Ref<GLTFState> state,
|
||||
const Vector<Transform> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
Error _encode_buffer_view(Ref<GLTFState> state, const float *src,
|
||||
Error _encode_buffer_view(Ref<GLTFState> state, const double *src,
|
||||
const int count, const GLTFType type,
|
||||
const int component_type, const bool normalized,
|
||||
const int byte_offset, const bool for_vertex,
|
||||
@ -250,22 +332,13 @@ private:
|
||||
Error _serialize_nodes(Ref<GLTFState> state);
|
||||
Error _serialize_scenes(Ref<GLTFState> state);
|
||||
String interpolation_to_string(const GLTFAnimation::Interpolation p_interp);
|
||||
|
||||
//TODO UNCOMMENT
|
||||
/*
|
||||
GLTFAnimation::Track _convert_animation_track(Ref<GLTFState> state,
|
||||
GLTFAnimation::Track p_track,
|
||||
Ref<Animation> p_animation,
|
||||
Ref<Animation> p_animation, Transform p_bone_rest,
|
||||
int32_t p_track_i,
|
||||
GLTFNodeIndex p_node_i);
|
||||
*/
|
||||
|
||||
//TODO DELETE
|
||||
GLTFAnimation::Track _convert_animation_track(Ref<GLTFState> state, GLTFAnimation::Track p_track, Ref<Animation> p_animation, Transform p_bone_rest, 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);
|
||||
PoolByteArray _serialize_glb_buffer(Ref<GLTFState> state, Error *r_err);
|
||||
Dictionary _serialize_texture_transform_uv1(Ref<SpatialMaterial> p_material);
|
||||
Dictionary _serialize_texture_transform_uv2(Ref<SpatialMaterial> p_material);
|
||||
Error _serialize_version(Ref<GLTFState> state);
|
||||
@ -273,8 +346,8 @@ private:
|
||||
Error _serialize_extensions(Ref<GLTFState> state) const;
|
||||
|
||||
public:
|
||||
// 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
|
||||
// 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
|
||||
static constexpr float R_BRIGHTNESS_COEFF = 0.299f;
|
||||
static constexpr float G_BRIGHTNESS_COEFF = 0.587f;
|
||||
static constexpr float B_BRIGHTNESS_COEFF = 0.114f;
|
||||
@ -289,18 +362,11 @@ private:
|
||||
static float get_max_component(const Color &p_color);
|
||||
|
||||
public:
|
||||
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(PoolByteArray 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);
|
||||
String _sanitize_scene_name(Ref<GLTFState> state, const String &p_name);
|
||||
String _legacy_validate_node_name(const String &p_name);
|
||||
|
||||
public:
|
||||
Node *generate_scene(Ref<GLTFState> state, int32_t p_bake_fps = 30.0f);
|
||||
PoolByteArray 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,
|
||||
@ -331,8 +397,8 @@ public:
|
||||
void _check_visibility(Node *p_node, bool &retflag);
|
||||
void _convert_camera_to_gltf(Camera *camera, Ref<GLTFState> state,
|
||||
Ref<GLTFNode> gltf_node);
|
||||
void _convert_multi_mesh_instance_to_gltf(
|
||||
MultiMeshInstance *p_multi_mesh_instance,
|
||||
void _convert_mult_mesh_instance_to_gltf(
|
||||
MultiMeshInstance *p_scene_parent,
|
||||
GLTFNodeIndex p_parent_node_index,
|
||||
GLTFNodeIndex p_root_node_index,
|
||||
Ref<GLTFNode> gltf_node, Ref<GLTFState> state);
|
||||
@ -353,19 +419,8 @@ public:
|
||||
MeshInstance *p_mesh_instance);
|
||||
void _convert_animation(Ref<GLTFState> state, AnimationPlayer *ap,
|
||||
String p_animation_track_name);
|
||||
Error _serialize(Ref<GLTFState> state, const String &p_path);
|
||||
Error _parse(Ref<GLTFState> state, String p_path, FileAccess *f, int p_bake_fps);
|
||||
|
||||
GLTFDocument();
|
||||
~GLTFDocument();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
const float BAKE_FPS = 30.0f;
|
||||
|
||||
Vector<Ref<GLTFDocumentExtension>> document_extensions;
|
||||
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);
|
||||
};
|
||||
|
||||
#endif // GLTF_DOCUMENT_H
|
||||
|
@ -1,159 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* 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"
|
||||
|
||||
#include "gltf_state.h"
|
||||
#include "structures/gltf_node.h"
|
||||
|
||||
Error GLTFDocumentExtension::import_post(Ref<GLTFState> p_state, Node *p_root) {
|
||||
ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
|
||||
|
||||
int err = call("_import_post", p_state, p_root);
|
||||
return static_cast<Error>(err);
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::import_preflight(Ref<GLTFState> p_state) {
|
||||
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
|
||||
|
||||
int err = call("_import_preflight", p_state);
|
||||
return static_cast<Error>(err);
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::import_post_parse(Ref<GLTFState> p_state) {
|
||||
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
|
||||
|
||||
int err = call("_import_post_parse", p_state);
|
||||
return static_cast<Error>(err);
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::export_post(Ref<GLTFState> p_state) {
|
||||
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
|
||||
|
||||
int err = call("_export_post", p_state);
|
||||
return static_cast<Error>(err);
|
||||
}
|
||||
Error GLTFDocumentExtension::export_preflight(Node *p_root) {
|
||||
ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER);
|
||||
|
||||
int err = call("_export_preflight", p_root);
|
||||
return static_cast<Error>(err);
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::import_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, const Dictionary &r_dict, Node *p_node) {
|
||||
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(p_gltf_node.is_null(), ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER);
|
||||
|
||||
int err = call("_import_node", p_state, p_gltf_node, r_dict, p_node);
|
||||
return static_cast<Error>(err);
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, const Dictionary &r_dict, Node *p_node) {
|
||||
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(p_gltf_node.is_null(), ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER);
|
||||
|
||||
int err = call("_export_node", p_state, p_gltf_node, r_dict, p_node);
|
||||
return static_cast<Error>(err);
|
||||
}
|
||||
|
||||
int GLTFDocumentExtension::_import_preflight(Ref<GLTFState> p_state) {
|
||||
return OK;
|
||||
}
|
||||
int GLTFDocumentExtension::_import_post_parse(Ref<GLTFState> p_state) {
|
||||
return OK;
|
||||
}
|
||||
int GLTFDocumentExtension::_export_post(Ref<GLTFState> p_state) {
|
||||
return OK;
|
||||
}
|
||||
int GLTFDocumentExtension::_import_post(Ref<GLTFState> p_state, Node *p_node) {
|
||||
return OK;
|
||||
}
|
||||
int GLTFDocumentExtension::_export_preflight(Node *p_state) {
|
||||
return OK;
|
||||
}
|
||||
int GLTFDocumentExtension::_import_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, const Dictionary &r_json, Node *p_node) {
|
||||
return OK;
|
||||
}
|
||||
int GLTFDocumentExtension::_export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, const Dictionary &r_json, Node *p_node) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
GLTFDocumentExtension::GLTFDocumentExtension() {
|
||||
}
|
||||
GLTFDocumentExtension::~GLTFDocumentExtension() {
|
||||
}
|
||||
|
||||
void GLTFDocumentExtension::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"),
|
||||
"_import_preflight",
|
||||
PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "GLTFState")));
|
||||
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"),
|
||||
"_import_post_parse",
|
||||
PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "GLTFState")));
|
||||
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"),
|
||||
"_import_node",
|
||||
PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "GLTFState"),
|
||||
PropertyInfo(Variant::OBJECT, "gltf_node", PROPERTY_HINT_RESOURCE_TYPE, "GLTFNode"),
|
||||
PropertyInfo(Variant::DICTIONARY, "json"),
|
||||
PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
|
||||
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"),
|
||||
"_import_post",
|
||||
PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "GLTFState"),
|
||||
PropertyInfo(Variant::OBJECT, "root", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
|
||||
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"),
|
||||
"_export_preflight",
|
||||
PropertyInfo(Variant::OBJECT, "root", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
|
||||
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"),
|
||||
"_export_node",
|
||||
PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "GLTFState"),
|
||||
PropertyInfo(Variant::OBJECT, "gltf_node", PROPERTY_HINT_RESOURCE_TYPE, "GLTFNode"),
|
||||
PropertyInfo(Variant::DICTIONARY, "json"),
|
||||
PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
|
||||
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"),
|
||||
"_export_post",
|
||||
PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "GLTFState")));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_import_preflight", "p_state"), &GLTFDocumentExtension::_import_preflight);
|
||||
ClassDB::bind_method(D_METHOD("_import_post_parse", "p_state"), &GLTFDocumentExtension::_import_post_parse);
|
||||
ClassDB::bind_method(D_METHOD("_export_post", "p_state"), &GLTFDocumentExtension::_export_post);
|
||||
ClassDB::bind_method(D_METHOD("_import_post", "p_state", "p_node"), &GLTFDocumentExtension::_import_post);
|
||||
ClassDB::bind_method(D_METHOD("_export_preflight", "p_state"), &GLTFDocumentExtension::_export_preflight);
|
||||
ClassDB::bind_method(D_METHOD("_import_node", "p_state", "p_gltf_node", "r_json", "p_node"), &GLTFDocumentExtension::_import_node);
|
||||
ClassDB::bind_method(D_METHOD("_export_node", "p_state", "p_gltf_node", "r_json", "p_node"), &GLTFDocumentExtension::_export_node);
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
#ifndef GLTF_DOCUMENT_EXTENSION_H
|
||||
#define GLTF_DOCUMENT_EXTENSION_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/reference.h"
|
||||
|
||||
#include "core/resource.h"
|
||||
|
||||
class GLTFNode;
|
||||
class GLTFState;
|
||||
|
||||
class GLTFDocumentExtension : public Resource {
|
||||
GDCLASS(GLTFDocumentExtension, Resource);
|
||||
|
||||
public:
|
||||
Error import_preflight(Ref<GLTFState> p_state);
|
||||
Error import_post_parse(Ref<GLTFState> p_state);
|
||||
Error export_post(Ref<GLTFState> p_state);
|
||||
Error import_post(Ref<GLTFState> p_state, Node *p_node);
|
||||
Error export_preflight(Node *p_state);
|
||||
Error import_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, const Dictionary &r_json, Node *p_node);
|
||||
Error export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, const Dictionary &r_json, Node *p_node);
|
||||
|
||||
virtual int _import_preflight(Ref<GLTFState> p_state);
|
||||
virtual int _import_post_parse(Ref<GLTFState> p_state);
|
||||
virtual int _export_post(Ref<GLTFState> p_state);
|
||||
virtual int _import_post(Ref<GLTFState> p_state, Node *p_node);
|
||||
virtual int _export_preflight(Node *p_state);
|
||||
virtual int _import_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, const Dictionary &r_json, Node *p_node);
|
||||
virtual int _export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, const Dictionary &r_json, Node *p_node);
|
||||
|
||||
GLTFDocumentExtension();
|
||||
~GLTFDocumentExtension();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
};
|
||||
|
||||
#endif // GLTF_DOCUMENT_EXTENSION_H
|
@ -1,87 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* 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_macros.h"
|
||||
#include "scene/3d/mesh_instance.h"
|
||||
#include "scene/resources/importer_mesh.h"
|
||||
#include "scene/3d/importer_mesh_instance_3d.h"
|
||||
#include "scene/3d/mesh_instance.h"
|
||||
#include "scene/main/node.h"
|
||||
|
||||
void GLTFDocumentExtensionConvertImporterMesh::_bind_methods() {
|
||||
}
|
||||
|
||||
int GLTFDocumentExtensionConvertImporterMesh::_import_post(Ref<GLTFState> p_state, Node *p_root) {
|
||||
ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
|
||||
|
||||
List<Node *> queue;
|
||||
queue.push_back(p_root);
|
||||
List<Node *> delete_queue;
|
||||
while (!queue.empty()) {
|
||||
List<Node *>::Element *E = queue.front();
|
||||
Node *node = E->get();
|
||||
ImporterMeshInstance3D *mesh_3d = cast_to<ImporterMeshInstance3D>(node);
|
||||
if (mesh_3d) {
|
||||
MeshInstance *mesh_instance_node_3d = memnew(MeshInstance);
|
||||
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.empty()) {
|
||||
List<Node *>::Element *E = delete_queue.front();
|
||||
Node *node = E->get();
|
||||
memdelete(node);
|
||||
delete_queue.pop_front();
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
#ifndef GLTF_DOCUMENT_EXTENSION_CONVERT_IMPORTER_MESH_H
|
||||
#define GLTF_DOCUMENT_EXTENSION_CONVERT_IMPORTER_MESH_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/reference.h"
|
||||
|
||||
#include "gltf_document_extension.h"
|
||||
|
||||
class GLTFState;
|
||||
class Node;
|
||||
|
||||
class GLTFDocumentExtensionConvertImporterMesh : public GLTFDocumentExtension {
|
||||
GDCLASS(GLTFDocumentExtensionConvertImporterMesh, GLTFDocumentExtension);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
int _import_post(Ref<GLTFState> p_state, Node *p_root);
|
||||
};
|
||||
|
||||
#endif // GLTF_DOCUMENT_EXTENSION_CONVERT_IMPORTER_MESH_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_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_type"), &GLTFLight::get_type);
|
||||
ClassDB::bind_method(D_METHOD("set_type", "type"), &GLTFLight::set_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);
|
||||
@ -46,7 +46,7 @@ void GLTFLight::_bind_methods() {
|
||||
|
||||
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, "light_type"), "set_light_type", "get_light_type"); // String
|
||||
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
|
||||
@ -68,12 +68,12 @@ void GLTFLight::set_intensity(float p_intensity) {
|
||||
intensity = p_intensity;
|
||||
}
|
||||
|
||||
String GLTFLight::get_light_type() {
|
||||
return light_type;
|
||||
String GLTFLight::get_type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
void GLTFLight::set_light_type(String p_light_type) {
|
||||
light_type = p_light_type;
|
||||
void GLTFLight::set_type(String p_type) {
|
||||
type = p_type;
|
||||
}
|
||||
|
||||
float GLTFLight::get_range() {
|
@ -1,6 +1,5 @@
|
||||
#ifndef GLTF_LIGHT_H
|
||||
#define GLTF_LIGHT_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* gltf_light.h */
|
||||
/*************************************************************************/
|
||||
@ -31,9 +30,7 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/engine.h"
|
||||
#include "core/resource.h"
|
||||
#include "scene/3d/light.h"
|
||||
|
||||
class GLTFLight : public Resource {
|
||||
GDCLASS(GLTFLight, Resource)
|
||||
@ -45,7 +42,7 @@ protected:
|
||||
private:
|
||||
Color color = Color(1.0f, 1.0f, 1.0f);
|
||||
float intensity = 1.0f;
|
||||
String light_type;
|
||||
String type;
|
||||
float range = INFINITY;
|
||||
float inner_cone_angle = 0.0f;
|
||||
float outer_cone_angle = Math_TAU / 8.0f;
|
||||
@ -57,8 +54,8 @@ public:
|
||||
float get_intensity();
|
||||
void set_intensity(float p_intensity);
|
||||
|
||||
String get_light_type();
|
||||
void set_light_type(String p_light_type);
|
||||
String get_type();
|
||||
void set_type(String p_type);
|
||||
|
||||
float get_range();
|
||||
void set_range(float p_range);
|
@ -30,8 +30,6 @@
|
||||
|
||||
#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);
|
||||
@ -45,11 +43,11 @@ void GLTFMesh::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "instance_materials"), "set_instance_materials", "get_instance_materials");
|
||||
}
|
||||
|
||||
Ref<ImporterMesh> GLTFMesh::get_mesh() {
|
||||
Ref<ArrayMesh> GLTFMesh::get_mesh() {
|
||||
return mesh;
|
||||
}
|
||||
|
||||
void GLTFMesh::set_mesh(Ref<ImporterMesh> p_mesh) {
|
||||
void GLTFMesh::set_mesh(Ref<ArrayMesh> p_mesh) {
|
||||
mesh = p_mesh;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#ifndef GLTF_MESH_H
|
||||
#define GLTF_MESH_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* gltf_mesh.h */
|
||||
/*************************************************************************/
|
||||
@ -32,15 +31,13 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/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<ImporterMesh> mesh;
|
||||
Ref<ArrayMesh> mesh;
|
||||
Vector<float> blend_weights;
|
||||
Array instance_materials;
|
||||
|
||||
@ -48,8 +45,8 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
Ref<ImporterMesh> get_mesh();
|
||||
void set_mesh(Ref<ImporterMesh> p_mesh);
|
||||
Ref<ArrayMesh> get_mesh();
|
||||
void set_mesh(Ref<ArrayMesh> 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_position"), &GLTFNode::get_position);
|
||||
ClassDB::bind_method(D_METHOD("set_position", "position"), &GLTFNode::set_position);
|
||||
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_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);
|
||||
@ -66,7 +66,7 @@ void GLTFNode::_bind_methods() {
|
||||
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, "position"), "set_position", "get_position"); // Vector3
|
||||
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, "scale"), "set_scale", "get_scale"); // Vector3
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "children"), "set_children", "get_children"); // Vector<int>
|
||||
@ -137,12 +137,12 @@ void GLTFNode::set_joint(bool p_joint) {
|
||||
joint = p_joint;
|
||||
}
|
||||
|
||||
Vector3 GLTFNode::get_position() {
|
||||
return position;
|
||||
Vector3 GLTFNode::get_translation() {
|
||||
return translation;
|
||||
}
|
||||
|
||||
void GLTFNode::set_position(Vector3 p_position) {
|
||||
position = p_position;
|
||||
void GLTFNode::set_translation(Vector3 p_translation) {
|
||||
translation = p_translation;
|
||||
}
|
||||
|
||||
Quat GLTFNode::get_rotation() {
|
@ -1,6 +1,5 @@
|
||||
#ifndef GLTF_NODE_H
|
||||
#define GLTF_NODE_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* gltf_node.h */
|
||||
/*************************************************************************/
|
||||
@ -31,12 +30,14 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "../gltf_defines.h"
|
||||
#include "core/resource.h"
|
||||
|
||||
#include "gltf_document.h"
|
||||
|
||||
class GLTFNode : public Resource {
|
||||
GDCLASS(GLTFNode, Resource);
|
||||
friend class GLTFDocument;
|
||||
friend class PackedSceneGLTF;
|
||||
|
||||
private:
|
||||
// matrices need to be transformed to this
|
||||
@ -48,7 +49,7 @@ private:
|
||||
GLTFSkinIndex skin = -1;
|
||||
GLTFSkeletonIndex skeleton = -1;
|
||||
bool joint = false;
|
||||
Vector3 position;
|
||||
Vector3 translation;
|
||||
Quat rotation;
|
||||
Vector3 scale = Vector3(1, 1, 1);
|
||||
Vector<int> children;
|
||||
@ -82,8 +83,8 @@ public:
|
||||
bool get_joint();
|
||||
void set_joint(bool p_joint);
|
||||
|
||||
Vector3 get_position();
|
||||
void set_position(Vector3 p_position);
|
||||
Vector3 get_translation();
|
||||
void set_translation(Vector3 p_translation);
|
||||
|
||||
Quat get_rotation();
|
||||
void set_rotation(Quat p_rotation);
|
@ -30,62 +30,59 @@
|
||||
|
||||
#include "gltf_skeleton.h"
|
||||
|
||||
#include "../gltf_template_convert.h"
|
||||
#include "scene/3d/bone_attachment.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_godot_skeleton"), &GLTFSkeleton::get_godot_skeleton);
|
||||
ClassDB::bind_method(D_METHOD("get_pandemonium_skeleton"), &GLTFSkeleton::get_pandemonium_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_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_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_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"); // Vector<GLTFNodeIndex>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "roots"), "set_roots", "get_roots"); // Vector<GLTFNodeIndex>
|
||||
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::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, "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,
|
||||
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,
|
||||
}
|
||||
|
||||
Vector<GLTFNodeIndex> GLTFSkeleton::get_joints() {
|
||||
PoolVector<GLTFNodeIndex> GLTFSkeleton::get_joints() {
|
||||
return joints;
|
||||
}
|
||||
|
||||
void GLTFSkeleton::set_joints(Vector<GLTFNodeIndex> p_joints) {
|
||||
void GLTFSkeleton::set_joints(PoolVector<GLTFNodeIndex> p_joints) {
|
||||
joints = p_joints;
|
||||
}
|
||||
|
||||
Vector<GLTFNodeIndex> GLTFSkeleton::get_roots() {
|
||||
PoolVector<GLTFNodeIndex> GLTFSkeleton::get_roots() {
|
||||
return roots;
|
||||
}
|
||||
|
||||
void GLTFSkeleton::set_roots(Vector<GLTFNodeIndex> p_roots) {
|
||||
void GLTFSkeleton::set_roots(PoolVector<GLTFNodeIndex> p_roots) {
|
||||
roots = p_roots;
|
||||
}
|
||||
|
||||
Skeleton *GLTFSkeleton::get_godot_skeleton() {
|
||||
return godot_skeleton;
|
||||
Skeleton *GLTFSkeleton::get_pandemonium_skeleton() {
|
||||
return pandemonium_skeleton;
|
||||
}
|
||||
|
||||
Array GLTFSkeleton::get_unique_names() {
|
||||
return GLTFTemplateConvert::to_array(unique_names);
|
||||
return GLTFDocument::to_array(unique_names);
|
||||
}
|
||||
|
||||
void GLTFSkeleton::set_unique_names(Array p_unique_names) {
|
||||
GLTFTemplateConvert::set_from_array(unique_names, p_unique_names);
|
||||
GLTFDocument::set_from_array(unique_names, p_unique_names);
|
||||
}
|
||||
|
||||
Dictionary GLTFSkeleton::get_godot_bone_node() {
|
||||
return GLTFTemplateConvert::to_dict(godot_bone_node);
|
||||
Dictionary GLTFSkeleton::get_pandemonium_bone_node() {
|
||||
return GLTFDocument::to_dict(pandemonium_bone_node);
|
||||
}
|
||||
|
||||
void GLTFSkeleton::set_godot_bone_node(Dictionary p_indict) {
|
||||
GLTFTemplateConvert::set_from_dict(godot_bone_node, p_indict);
|
||||
void GLTFSkeleton::set_pandemonium_bone_node(Dictionary p_indict) {
|
||||
GLTFDocument::set_from_dict(pandemonium_bone_node, p_indict);
|
||||
}
|
||||
|
||||
BoneAttachment *GLTFSkeleton::get_bone_attachment(int idx) {
|
@ -1,6 +1,5 @@
|
||||
#ifndef GLTF_SKELETON_H
|
||||
#define GLTF_SKELETON_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* gltf_skeleton.h */
|
||||
/*************************************************************************/
|
||||
@ -31,9 +30,9 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "../gltf_defines.h"
|
||||
#include "core/resource.h"
|
||||
#include "core/hash_set.h"
|
||||
|
||||
#include "gltf_document.h"
|
||||
|
||||
class GLTFSkeleton : public Resource {
|
||||
GDCLASS(GLTFSkeleton, Resource);
|
||||
@ -41,59 +40,39 @@ class GLTFSkeleton : public Resource {
|
||||
|
||||
private:
|
||||
// The *synthesized* skeletons joints
|
||||
Vector<GLTFNodeIndex> joints;
|
||||
PoolVector<GLTFNodeIndex> joints;
|
||||
|
||||
// The roots of the skeleton. If there are multiple, each root must have the
|
||||
// same parent (ie roots are siblings)
|
||||
Vector<GLTFNodeIndex> roots;
|
||||
PoolVector<GLTFNodeIndex> roots;
|
||||
|
||||
// The created Skeleton for the scene
|
||||
Skeleton *godot_skeleton = nullptr;
|
||||
Skeleton *pandemonium_skeleton = nullptr;
|
||||
|
||||
// Set of unique bone names for the skeleton
|
||||
HashSet<String> unique_names;
|
||||
Set<String> unique_names;
|
||||
|
||||
HashMap<int32_t, GLTFNodeIndex> godot_bone_node;
|
||||
Map<int32_t, GLTFNodeIndex> pandemonium_bone_node;
|
||||
|
||||
Vector<BoneAttachment *> bone_attachments;
|
||||
PoolVector<BoneAttachment *> bone_attachments;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
Vector<GLTFNodeIndex> get_joints();
|
||||
void set_joints(Vector<GLTFNodeIndex> p_joints);
|
||||
PoolVector<GLTFNodeIndex> get_joints();
|
||||
void set_joints(PoolVector<GLTFNodeIndex> p_joints);
|
||||
|
||||
Vector<GLTFNodeIndex> get_roots();
|
||||
void set_roots(Vector<GLTFNodeIndex> p_roots);
|
||||
PoolVector<GLTFNodeIndex> get_roots();
|
||||
void set_roots(PoolVector<GLTFNodeIndex> p_roots);
|
||||
|
||||
Skeleton *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;
|
||||
// }
|
||||
Skeleton *get_pandemonium_skeleton();
|
||||
|
||||
Array get_unique_names();
|
||||
void set_unique_names(Array p_unique_names);
|
||||
|
||||
//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);
|
||||
|
||||
//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);
|
||||
//}
|
||||
Dictionary get_pandemonium_bone_node();
|
||||
void set_pandemonium_bone_node(Dictionary p_indict);
|
||||
|
||||
BoneAttachment *get_bone_attachment(int idx);
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
#include "gltf_skin.h"
|
||||
|
||||
#include "../gltf_template_convert.h"
|
||||
#include "scene/resources/skin.h"
|
||||
|
||||
void GLTFSkin::_bind_methods() {
|
||||
@ -52,8 +51,8 @@ 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_godot_skin"), &GLTFSkin::get_godot_skin);
|
||||
ClassDB::bind_method(D_METHOD("set_godot_skin", "godot_skin"), &GLTFSkin::set_godot_skin);
|
||||
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);
|
||||
|
||||
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>
|
||||
@ -62,9 +61,9 @@ void GLTFSkin::_bind_methods() {
|
||||
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::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"); // 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>
|
||||
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>
|
||||
}
|
||||
|
||||
GLTFNodeIndex GLTFSkin::get_skin_root() {
|
||||
@ -84,11 +83,11 @@ void GLTFSkin::set_joints_original(Vector<GLTFNodeIndex> p_joints_original) {
|
||||
}
|
||||
|
||||
Array GLTFSkin::get_inverse_binds() {
|
||||
return GLTFTemplateConvert::to_array(inverse_binds);
|
||||
return GLTFDocument::to_array(inverse_binds);
|
||||
}
|
||||
|
||||
void GLTFSkin::set_inverse_binds(Array p_inverse_binds) {
|
||||
GLTFTemplateConvert::set_from_array(inverse_binds, p_inverse_binds);
|
||||
GLTFDocument::set_from_array(inverse_binds, p_inverse_binds);
|
||||
}
|
||||
|
||||
Vector<GLTFNodeIndex> GLTFSkin::get_joints() {
|
||||
@ -124,35 +123,41 @@ void GLTFSkin::set_skeleton(int p_skeleton) {
|
||||
}
|
||||
|
||||
Dictionary GLTFSkin::get_joint_i_to_bone_i() {
|
||||
return GLTFTemplateConvert::to_dict(joint_i_to_bone_i);
|
||||
return GLTFDocument::to_dict(joint_i_to_bone_i);
|
||||
}
|
||||
|
||||
void GLTFSkin::set_joint_i_to_bone_i(Dictionary p_joint_i_to_bone_i) {
|
||||
GLTFTemplateConvert::set_from_dict(joint_i_to_bone_i, p_joint_i_to_bone_i);
|
||||
GLTFDocument::set_from_dict(joint_i_to_bone_i, p_joint_i_to_bone_i);
|
||||
}
|
||||
|
||||
Dictionary GLTFSkin::get_joint_i_to_name() {
|
||||
Dictionary ret;
|
||||
|
||||
const int *key = NULL;
|
||||
while ((key = joint_i_to_name.next(key))) {
|
||||
ret[*key] = String(joint_i_to_name[*key]);
|
||||
Map<int, StringName>::Element *elem = joint_i_to_name.front();
|
||||
while (elem) {
|
||||
ret[elem->key()] = String(elem->value());
|
||||
elem = elem->next();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void GLTFSkin::set_joint_i_to_name(Dictionary p_joint_i_to_name) {
|
||||
joint_i_to_name = HashMap<int, StringName>();
|
||||
joint_i_to_name = Map<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_godot_skin() {
|
||||
return godot_skin;
|
||||
Ref<Skin> GLTFSkin::get_pandemonium_skin() {
|
||||
return pandemonium_skin;
|
||||
}
|
||||
|
||||
void GLTFSkin::set_godot_skin(Ref<Skin> p_godot_skin) {
|
||||
godot_skin = p_godot_skin;
|
||||
void GLTFSkin::set_pandemonium_skin(Ref<Skin> p_pandemonium_skin) {
|
||||
pandemonium_skin = p_pandemonium_skin;
|
||||
}
|
||||
|
||||
GLTFSkin::GLTFSkin() {
|
||||
}
|
||||
|
||||
GLTFSkin::~GLTFSkin() {
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
#ifndef GLTF_SKIN_H
|
||||
#define GLTF_SKIN_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* gltf_skin.h */
|
||||
/*************************************************************************/
|
||||
@ -31,9 +30,12 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "../gltf_defines.h"
|
||||
#include "core/resource.h"
|
||||
|
||||
#include "gltf_document.h"
|
||||
|
||||
class Skin;
|
||||
|
||||
class GLTFSkin : public Resource {
|
||||
GDCLASS(GLTFSkin, Resource);
|
||||
friend class GLTFDocument;
|
||||
@ -64,13 +66,13 @@ private:
|
||||
GLTFSkeletonIndex skeleton = -1;
|
||||
|
||||
// A mapping from the joint indices (in the order of joints_original) to the
|
||||
// Godot Skeleton's bone_indices
|
||||
HashMap<int, int> joint_i_to_bone_i;
|
||||
HashMap<int, StringName> joint_i_to_name;
|
||||
// Pandemonium Skeleton's bone_indices
|
||||
Map<int, int> joint_i_to_bone_i;
|
||||
Map<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> godot_skin;
|
||||
Ref<Skin> pandemonium_skin;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
@ -103,8 +105,11 @@ public:
|
||||
Dictionary get_joint_i_to_name();
|
||||
void set_joint_i_to_name(Dictionary p_joint_i_to_name);
|
||||
|
||||
Ref<Skin> get_godot_skin();
|
||||
void set_godot_skin(Ref<Skin> p_godot_skin);
|
||||
Ref<Skin> get_pandemonium_skin();
|
||||
void set_pandemonium_skin(Ref<Skin> p_pandemonium_skin);
|
||||
|
||||
GLTFSkin();
|
||||
~GLTFSkin();
|
||||
};
|
||||
|
||||
#endif // GLTF_SKIN_H
|
@ -1,6 +1,5 @@
|
||||
#ifndef GLTF_SPEC_GLOSS_H
|
||||
#define GLTF_SPEC_GLOSS_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* gltf_spec_gloss.h */
|
||||
/*************************************************************************/
|
@ -30,6 +30,8 @@
|
||||
|
||||
#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);
|
||||
@ -57,8 +59,6 @@ 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);
|
||||
@ -95,7 +95,6 @@ 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::STRING, "base_path"), "set_base_path", "get_base_path"); // String
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_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>
|
||||
@ -105,7 +104,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"); // RBMap<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"); // Map<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>>
|
||||
}
|
||||
|
||||
@ -150,51 +149,51 @@ void GLTFState::set_use_named_skin_binds(bool p_use_named_skin_binds) {
|
||||
}
|
||||
|
||||
Array GLTFState::get_nodes() {
|
||||
return GLTFTemplateConvert::to_array(nodes);
|
||||
return GLTFDocument::to_array(nodes);
|
||||
}
|
||||
|
||||
void GLTFState::set_nodes(Array p_nodes) {
|
||||
GLTFTemplateConvert::set_from_array(nodes, p_nodes);
|
||||
GLTFDocument::set_from_array(nodes, p_nodes);
|
||||
}
|
||||
|
||||
Array GLTFState::get_buffers() {
|
||||
return GLTFTemplateConvert::to_array(buffers);
|
||||
return GLTFDocument::to_array(buffers);
|
||||
}
|
||||
|
||||
void GLTFState::set_buffers(Array p_buffers) {
|
||||
GLTFTemplateConvert::set_from_array(buffers, p_buffers);
|
||||
GLTFDocument::set_from_array(buffers, p_buffers);
|
||||
}
|
||||
|
||||
Array GLTFState::get_buffer_views() {
|
||||
return GLTFTemplateConvert::to_array(buffer_views);
|
||||
return GLTFDocument::to_array(buffer_views);
|
||||
}
|
||||
|
||||
void GLTFState::set_buffer_views(Array p_buffer_views) {
|
||||
GLTFTemplateConvert::set_from_array(buffer_views, p_buffer_views);
|
||||
GLTFDocument::set_from_array(buffer_views, p_buffer_views);
|
||||
}
|
||||
|
||||
Array GLTFState::get_accessors() {
|
||||
return GLTFTemplateConvert::to_array(accessors);
|
||||
return GLTFDocument::to_array(accessors);
|
||||
}
|
||||
|
||||
void GLTFState::set_accessors(Array p_accessors) {
|
||||
GLTFTemplateConvert::set_from_array(accessors, p_accessors);
|
||||
GLTFDocument::set_from_array(accessors, p_accessors);
|
||||
}
|
||||
|
||||
Array GLTFState::get_meshes() {
|
||||
return GLTFTemplateConvert::to_array(meshes);
|
||||
return GLTFDocument::to_array(meshes);
|
||||
}
|
||||
|
||||
void GLTFState::set_meshes(Array p_meshes) {
|
||||
GLTFTemplateConvert::set_from_array(meshes, p_meshes);
|
||||
GLTFDocument::set_from_array(meshes, p_meshes);
|
||||
}
|
||||
|
||||
Array GLTFState::get_materials() {
|
||||
return GLTFTemplateConvert::to_array(materials);
|
||||
return GLTFDocument::to_array(materials);
|
||||
}
|
||||
|
||||
void GLTFState::set_materials(Array p_materials) {
|
||||
GLTFTemplateConvert::set_from_array(materials, p_materials);
|
||||
GLTFDocument::set_from_array(materials, p_materials);
|
||||
}
|
||||
|
||||
String GLTFState::get_scene_name() {
|
||||
@ -206,91 +205,91 @@ void GLTFState::set_scene_name(String p_scene_name) {
|
||||
}
|
||||
|
||||
Array GLTFState::get_root_nodes() {
|
||||
return GLTFTemplateConvert::to_array(root_nodes);
|
||||
return GLTFDocument::to_array(root_nodes);
|
||||
}
|
||||
|
||||
void GLTFState::set_root_nodes(Array p_root_nodes) {
|
||||
GLTFTemplateConvert::set_from_array(root_nodes, p_root_nodes);
|
||||
GLTFDocument::set_from_array(root_nodes, p_root_nodes);
|
||||
}
|
||||
|
||||
Array GLTFState::get_textures() {
|
||||
return GLTFTemplateConvert::to_array(textures);
|
||||
return GLTFDocument::to_array(textures);
|
||||
}
|
||||
|
||||
void GLTFState::set_textures(Array p_textures) {
|
||||
GLTFTemplateConvert::set_from_array(textures, p_textures);
|
||||
GLTFDocument::set_from_array(textures, p_textures);
|
||||
}
|
||||
|
||||
Array GLTFState::get_images() {
|
||||
return GLTFTemplateConvert::to_array(images);
|
||||
return GLTFDocument::to_array(images);
|
||||
}
|
||||
|
||||
void GLTFState::set_images(Array p_images) {
|
||||
GLTFTemplateConvert::set_from_array(images, p_images);
|
||||
GLTFDocument::set_from_array(images, p_images);
|
||||
}
|
||||
|
||||
Array GLTFState::get_skins() {
|
||||
return GLTFTemplateConvert::to_array(skins);
|
||||
return GLTFDocument::to_array(skins);
|
||||
}
|
||||
|
||||
void GLTFState::set_skins(Array p_skins) {
|
||||
GLTFTemplateConvert::set_from_array(skins, p_skins);
|
||||
GLTFDocument::set_from_array(skins, p_skins);
|
||||
}
|
||||
|
||||
Array GLTFState::get_cameras() {
|
||||
return GLTFTemplateConvert::to_array(cameras);
|
||||
return GLTFDocument::to_array(cameras);
|
||||
}
|
||||
|
||||
void GLTFState::set_cameras(Array p_cameras) {
|
||||
GLTFTemplateConvert::set_from_array(cameras, p_cameras);
|
||||
GLTFDocument::set_from_array(cameras, p_cameras);
|
||||
}
|
||||
|
||||
Array GLTFState::get_lights() {
|
||||
return GLTFTemplateConvert::to_array(lights);
|
||||
return GLTFDocument::to_array(lights);
|
||||
}
|
||||
|
||||
void GLTFState::set_lights(Array p_lights) {
|
||||
GLTFTemplateConvert::set_from_array(lights, p_lights);
|
||||
GLTFDocument::set_from_array(lights, p_lights);
|
||||
}
|
||||
|
||||
Array GLTFState::get_unique_names() {
|
||||
return GLTFTemplateConvert::to_array(unique_names);
|
||||
return GLTFDocument::to_array(unique_names);
|
||||
}
|
||||
|
||||
void GLTFState::set_unique_names(Array p_unique_names) {
|
||||
GLTFTemplateConvert::set_from_array(unique_names, p_unique_names);
|
||||
GLTFDocument::set_from_array(unique_names, p_unique_names);
|
||||
}
|
||||
|
||||
Array GLTFState::get_unique_animation_names() {
|
||||
return GLTFTemplateConvert::to_array(unique_animation_names);
|
||||
return GLTFDocument::to_array(unique_animation_names);
|
||||
}
|
||||
|
||||
void GLTFState::set_unique_animation_names(Array p_unique_animation_names) {
|
||||
GLTFTemplateConvert::set_from_array(unique_animation_names, p_unique_animation_names);
|
||||
GLTFDocument::set_from_array(unique_animation_names, p_unique_animation_names);
|
||||
}
|
||||
|
||||
Array GLTFState::get_skeletons() {
|
||||
return GLTFTemplateConvert::to_array(skeletons);
|
||||
return GLTFDocument::to_array(skeletons);
|
||||
}
|
||||
|
||||
void GLTFState::set_skeletons(Array p_skeletons) {
|
||||
GLTFTemplateConvert::set_from_array(skeletons, p_skeletons);
|
||||
GLTFDocument::set_from_array(skeletons, p_skeletons);
|
||||
}
|
||||
|
||||
Dictionary GLTFState::get_skeleton_to_node() {
|
||||
return GLTFTemplateConvert::to_dict(skeleton_to_node);
|
||||
return GLTFDocument::to_dict(skeleton_to_node);
|
||||
}
|
||||
|
||||
void GLTFState::set_skeleton_to_node(Dictionary p_skeleton_to_node) {
|
||||
GLTFTemplateConvert::set_from_dict(skeleton_to_node, p_skeleton_to_node);
|
||||
GLTFDocument::set_from_dict(skeleton_to_node, p_skeleton_to_node);
|
||||
}
|
||||
|
||||
Array GLTFState::get_animations() {
|
||||
return GLTFTemplateConvert::to_array(animations);
|
||||
return GLTFDocument::to_array(animations);
|
||||
}
|
||||
|
||||
void GLTFState::set_animations(Array p_animations) {
|
||||
GLTFTemplateConvert::set_from_array(animations, p_animations);
|
||||
GLTFDocument::set_from_array(animations, p_animations);
|
||||
}
|
||||
|
||||
Node *GLTFState::get_scene_node(GLTFNodeIndex idx) {
|
||||
@ -308,19 +307,3 @@ 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,6 +1,5 @@
|
||||
#ifndef GLTF_STATE_H
|
||||
#define GLTF_STATE_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* gltf_state.h */
|
||||
/*************************************************************************/
|
||||
@ -31,36 +30,38 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#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/rb_map.h"
|
||||
#include "core/map.h"
|
||||
#include "core/resource.h"
|
||||
#include "core/vector.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_khr_texture_transform = false;
|
||||
bool discard_meshes_and_materials = false;
|
||||
bool use_legacy_names = false;
|
||||
uint32_t compress_flags = 0;
|
||||
|
||||
Vector<Ref<GLTFNode>> nodes;
|
||||
Vector<Vector<uint8_t>> buffers;
|
||||
@ -70,8 +71,8 @@ class GLTFState : public Resource {
|
||||
Vector<Ref<GLTFMesh>> meshes; // meshes are loaded directly, no reason not to.
|
||||
|
||||
Vector<AnimationPlayer *> animation_players;
|
||||
HashMap<Ref<SpatialMaterial>, GLTFMaterialIndex> material_cache;
|
||||
Vector<Ref<SpatialMaterial>> materials;
|
||||
Map<Ref<Material>, GLTFMaterialIndex> material_cache;
|
||||
Vector<Ref<Material>> materials;
|
||||
|
||||
String scene_name;
|
||||
Vector<int> root_nodes;
|
||||
@ -81,16 +82,16 @@ class GLTFState : public Resource {
|
||||
Vector<Ref<GLTFSkin>> skins;
|
||||
Vector<Ref<GLTFCamera>> cameras;
|
||||
Vector<Ref<GLTFLight>> lights;
|
||||
HashSet<String> unique_names;
|
||||
HashSet<String> unique_animation_names;
|
||||
Set<String> unique_names;
|
||||
Set<String> unique_animation_names;
|
||||
|
||||
Vector<Ref<GLTFSkeleton>> skeletons;
|
||||
HashMap<GLTFSkeletonIndex, GLTFNodeIndex> skeleton_to_node;
|
||||
Map<GLTFSkeletonIndex, GLTFNodeIndex> skeleton_to_node;
|
||||
Vector<Ref<GLTFAnimation>> animations;
|
||||
HashMap<GLTFNodeIndex, Node *> scene_nodes;
|
||||
Map<GLTFNodeIndex, Node *> scene_nodes;
|
||||
|
||||
HashMap<ObjectID, GLTFSkeletonIndex> skeleton3d_to_gltf_skeleton;
|
||||
HashMap<ObjectID, HashMap<ObjectID, GLTFSkinIndex>> skin_and_skeleton3d_to_gltf_skin;
|
||||
Map<ObjectID, GLTFSkeletonIndex> skeleton3d_to_gltf_skeleton;
|
||||
Map<ObjectID, Map<ObjectID, GLTFSkinIndex>> skin_and_skeleton3d_to_gltf_skin;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
@ -111,9 +112,6 @@ 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);
|
||||
|
||||
@ -135,9 +133,6 @@ 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);
|
||||
|
||||
@ -176,21 +171,6 @@ 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
|
||||
|
@ -1,95 +0,0 @@
|
||||
#ifndef GLTF_TEMPLATE_CONVERT_H
|
||||
#define GLTF_TEMPLATE_CONVERT_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/array.h"
|
||||
#include "core/dictionary.h"
|
||||
#include "core/hash_set.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;
|
||||
const K *key = NULL;
|
||||
while ((key = p_inp.next(key))) {
|
||||
ret[*key] = p_inp[*key];
|
||||
}
|
||||
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,6 +1,5 @@
|
||||
#ifndef GLTF_TEXTURE_H
|
||||
#define GLTF_TEXTURE_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* gltf_texture.h */
|
||||
/*************************************************************************/
|
||||
@ -31,9 +30,10 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "../gltf_defines.h"
|
||||
#include "core/resource.h"
|
||||
|
||||
#include "gltf_document.h"
|
||||
|
||||
class GLTFTexture : public Resource {
|
||||
GDCLASS(GLTFTexture, Resource);
|
||||
|
160
modules/gltf/packed_scene_gltf.cpp
Normal file
160
modules/gltf/packed_scene_gltf.cpp
Normal file
@ -0,0 +1,160 @@
|
||||
/*************************************************************************/
|
||||
/* 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
|
@ -1,8 +1,7 @@
|
||||
#ifndef EDITOR_SCENE_IMPORTER_FBX_H
|
||||
#define EDITOR_SCENE_IMPORTER_FBX_H
|
||||
|
||||
#ifndef PACKED_SCENE_GLTF_H
|
||||
#define PACKED_SCENE_GLTF_H
|
||||
/*************************************************************************/
|
||||
/* editor_scene_importer_fbx.h */
|
||||
/* packed_scene_gltf.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
@ -33,26 +32,34 @@
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "editor/import/resource_importer_scene.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/resources/packed_scene.h"
|
||||
|
||||
class Animation;
|
||||
class Node;
|
||||
#include "gltf_state.h"
|
||||
|
||||
class EditorSceneFormatImporterFBX : public EditorSceneImporter {
|
||||
GDCLASS(EditorSceneFormatImporterFBX, EditorSceneImporter);
|
||||
class PackedSceneGLTF : public PackedScene {
|
||||
GDCLASS(PackedSceneGLTF, PackedScene);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
virtual uint32_t get_import_flags() const;
|
||||
virtual void get_extensions(List<String> *r_extensions) const;
|
||||
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 bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
|
||||
virtual void get_import_options(List<ResourceImporterScene::ImportOption> *r_options, int p_preset = 0) const;
|
||||
|
||||
EditorSceneFormatImporterFBX();
|
||||
~EditorSceneFormatImporterFBX();
|
||||
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 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>());
|
||||
};
|
||||
|
||||
#endif // TOOLS_ENABLED
|
||||
#endif // PACKED_SCENE_GLTF_H
|
||||
|
||||
#endif // EDITOR_SCENE_IMPORTER_FBX_H
|
||||
#endif // TOOLS_ENABLED
|
@ -28,153 +28,66 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "register_types.h"
|
||||
|
||||
#ifndef _3D_DISABLED
|
||||
|
||||
#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 "register_types.h"
|
||||
|
||||
#include "extensions/gltf_light.h"
|
||||
#include "extensions/gltf_spec_gloss.h"
|
||||
|
||||
#include "gltf_document_extension.h"
|
||||
#include "gltf_document_extension_convert_importer_mesh.h"
|
||||
#include "gltf_state.h"
|
||||
#include "gltf_accessor.h"
|
||||
#include "gltf_animation.h"
|
||||
#include "gltf_buffer_view.h"
|
||||
#include "gltf_camera.h"
|
||||
#include "gltf_document.h"
|
||||
#include "gltf_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
|
||||
|
||||
void register_gltf_types() {
|
||||
ClassDB::register_class<GLTFAccessor>();
|
||||
ClassDB::register_class<GLTFAnimation>();
|
||||
ClassDB::register_class<GLTFBufferView>();
|
||||
ClassDB::register_class<GLTFCamera>();
|
||||
ClassDB::register_class<GLTFMesh>();
|
||||
ClassDB::register_class<GLTFNode>();
|
||||
ClassDB::register_class<GLTFSkeleton>();
|
||||
ClassDB::register_class<GLTFSkin>();
|
||||
ClassDB::register_class<GLTFTexture>();
|
||||
#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<GLTFLight>();
|
||||
|
||||
ClassDB::register_class<GLTFDocument>();
|
||||
ClassDB::register_class<GLTFDocumentExtension>();
|
||||
ClassDB::register_class<GLTFDocumentExtensionConvertImporterMesh>();
|
||||
ClassDB::register_class<GLTFState>();
|
||||
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() {
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#include "core/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) {
|
||||
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);
|
||||
}
|
||||
|
||||
memdelete(da);
|
||||
}
|
||||
}
|
||||
#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,3 +1,5 @@
|
||||
#ifndef GLTF_REGISTER_TYPES_H
|
||||
#define GLTF_REGISTER_TYPES_H
|
||||
/*************************************************************************/
|
||||
/* register_types.h */
|
||||
/*************************************************************************/
|
||||
@ -28,5 +30,11 @@
|
||||
/* 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
|
||||
|
Loading…
Reference in New Issue
Block a user