Minor enhancements to the GLTF module (lights and docs)

This commit is contained in:
Aaron Franke 2022-09-17 22:16:22 -05:00
parent 908795301b
commit afe09ec914
No known key found for this signature in database
GPG Key ID: 40A1750B977E56BF
7 changed files with 44 additions and 29 deletions

View File

@ -7,7 +7,7 @@ env_gltf = env_modules.Clone()
# Godot source files # Godot source files
env_gltf.add_source_files(env.modules_sources, "*.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") env_gltf.add_source_files(env.modules_sources, "structures/*.cpp")
SConscript("extensions/SCsub")
if env["tools"]: if env["tools"]:
env_gltf.add_source_files(env.modules_sources, "editor/*.cpp") env_gltf.add_source_files(env.modules_sources, "editor/*.cpp")

View File

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?> <?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"> <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>
[GLTFDocument] extension class.
</brief_description> </brief_description>
<description> <description>
Extends the functionality of the [GLTFDocument] class by allowing you to run arbitrary code at various stages of GLTF import or export.
</description> </description>
<tutorials> <tutorials>
</tutorials> </tutorials>

View File

@ -1,10 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?> <?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="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description> <brief_description>
GLTF node class.
</brief_description> </brief_description>
<description> <description>
Represents a GLTF node. GLTF nodes may have names, transforms, children (other GLTF nodes), and more specialized properties (represented by their own classes).
</description> </description>
<tutorials> <tutorials>
<link title="GLTF scene and node spec">https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_004_ScenesNodes.md"</link>
</tutorials> </tutorials>
<members> <members>
<member name="camera" type="int" setter="set_camera" getter="get_camera" default="-1"> <member name="camera" type="int" setter="set_camera" getter="get_camera" default="-1">

View File

@ -0,0 +1,9 @@
#!/usr/bin/env python
Import("env")
Import("env_modules")
env_gltf = env_modules.Clone()
# Godot source files
env_gltf.add_source_files(env.modules_sources, "*.cpp")

View File

@ -66,9 +66,9 @@ using GLTFBufferIndex = int;
using GLTFBufferViewIndex = int; using GLTFBufferViewIndex = int;
using GLTFCameraIndex = int; using GLTFCameraIndex = int;
using GLTFImageIndex = int; using GLTFImageIndex = int;
using GLTFLightIndex = int;
using GLTFMaterialIndex = int; using GLTFMaterialIndex = int;
using GLTFMeshIndex = int; using GLTFMeshIndex = int;
using GLTFLightIndex = int;
using GLTFNodeIndex = int; using GLTFNodeIndex = int;
using GLTFSkeletonIndex = int; using GLTFSkeletonIndex = int;
using GLTFSkinIndex = int; using GLTFSkinIndex = int;

View File

@ -191,7 +191,7 @@ Error GLTFDocument::_serialize(Ref<GLTFState> state, const String &p_path) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP SERIALIZE SCENE */ /* STEP SERIALIZE LIGHTS */
err = _serialize_lights(state); err = _serialize_lights(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
@ -401,47 +401,47 @@ Error GLTFDocument::_serialize_nodes(Ref<GLTFState> state) {
Array nodes; Array nodes;
for (int i = 0; i < state->nodes.size(); i++) { for (int i = 0; i < state->nodes.size(); i++) {
Dictionary node; Dictionary node;
Ref<GLTFNode> n = state->nodes[i]; Ref<GLTFNode> gltf_node = state->nodes[i];
Dictionary extensions; Dictionary extensions;
node["extensions"] = extensions; node["extensions"] = extensions;
if (!n->get_name().is_empty()) { if (!gltf_node->get_name().is_empty()) {
node["name"] = n->get_name(); node["name"] = gltf_node->get_name();
} }
if (n->camera != -1) { if (gltf_node->camera != -1) {
node["camera"] = n->camera; node["camera"] = gltf_node->camera;
} }
if (n->light != -1) { if (gltf_node->light != -1) {
Dictionary lights_punctual; Dictionary lights_punctual;
extensions["KHR_lights_punctual"] = lights_punctual; extensions["KHR_lights_punctual"] = lights_punctual;
lights_punctual["light"] = n->light; lights_punctual["light"] = gltf_node->light;
} }
if (n->mesh != -1) { if (gltf_node->mesh != -1) {
node["mesh"] = n->mesh; node["mesh"] = gltf_node->mesh;
} }
if (n->skin != -1) { if (gltf_node->skin != -1) {
node["skin"] = n->skin; node["skin"] = gltf_node->skin;
} }
if (n->skeleton != -1 && n->skin < 0) { if (gltf_node->skeleton != -1 && gltf_node->skin < 0) {
} }
if (n->xform != Transform3D()) { if (gltf_node->xform != Transform3D()) {
node["matrix"] = _xform_to_array(n->xform); node["matrix"] = _xform_to_array(gltf_node->xform);
} }
if (!n->rotation.is_equal_approx(Quaternion())) { if (!gltf_node->rotation.is_equal_approx(Quaternion())) {
node["rotation"] = _quaternion_to_array(n->rotation); node["rotation"] = _quaternion_to_array(gltf_node->rotation);
} }
if (!n->scale.is_equal_approx(Vector3(1.0f, 1.0f, 1.0f))) { if (!gltf_node->scale.is_equal_approx(Vector3(1.0f, 1.0f, 1.0f))) {
node["scale"] = _vec3_to_arr(n->scale); node["scale"] = _vec3_to_arr(gltf_node->scale);
} }
if (!n->position.is_zero_approx()) { if (!gltf_node->position.is_zero_approx()) {
node["translation"] = _vec3_to_arr(n->position); node["translation"] = _vec3_to_arr(gltf_node->position);
} }
if (n->children.size()) { if (gltf_node->children.size()) {
Array children; Array children;
for (int j = 0; j < n->children.size(); j++) { for (int j = 0; j < gltf_node->children.size(); j++) {
children.push_back(n->children[j]); children.push_back(gltf_node->children[j]);
} }
node["children"] = children; node["children"] = children;
} }
@ -450,7 +450,7 @@ Error GLTFDocument::_serialize_nodes(Ref<GLTFState> state) {
Ref<GLTFDocumentExtension> ext = document_extensions[ext_i]; Ref<GLTFDocumentExtension> ext = document_extensions[ext_i];
ERR_CONTINUE(ext.is_null()); ERR_CONTINUE(ext.is_null());
ERR_CONTINUE(!state->scene_nodes.find(i)); ERR_CONTINUE(!state->scene_nodes.find(i));
Error err = ext->export_node(state, n, state->json, state->scene_nodes[i]); Error err = ext->export_node(state, gltf_node, node, state->scene_nodes[i]);
ERR_CONTINUE(err != OK); ERR_CONTINUE(err != OK);
} }
@ -5046,7 +5046,7 @@ ImporterMeshInstance3D *GLTFDocument::_generate_mesh_instance(Ref<GLTFState> sta
return mi; return mi;
} }
Node3D *GLTFDocument::_generate_light(Ref<GLTFState> state, const GLTFNodeIndex node_index) { Light3D *GLTFDocument::_generate_light(Ref<GLTFState> state, const GLTFNodeIndex node_index) {
Ref<GLTFNode> gltf_node = state->nodes[node_index]; Ref<GLTFNode> gltf_node = state->nodes[node_index];
ERR_FAIL_INDEX_V(gltf_node->light, state->lights.size(), nullptr); ERR_FAIL_INDEX_V(gltf_node->light, state->lights.size(), nullptr);
@ -5102,6 +5102,7 @@ Node3D *GLTFDocument::_generate_spatial(Ref<GLTFState> state, const GLTFNodeInde
return spatial; return spatial;
} }
void GLTFDocument::_convert_scene_node(Ref<GLTFState> state, Node *p_current, const GLTFNodeIndex p_gltf_parent, const GLTFNodeIndex p_gltf_root) { void GLTFDocument::_convert_scene_node(Ref<GLTFState> state, Node *p_current, const GLTFNodeIndex p_gltf_parent, const GLTFNodeIndex p_gltf_root) {
bool retflag = true; bool retflag = true;
_check_visibility(p_current, retflag); _check_visibility(p_current, retflag);

View File

@ -188,7 +188,7 @@ private:
const GLTFNodeIndex bone_index); const GLTFNodeIndex bone_index);
ImporterMeshInstance3D *_generate_mesh_instance(Ref<GLTFState> state, const GLTFNodeIndex node_index); ImporterMeshInstance3D *_generate_mesh_instance(Ref<GLTFState> state, const GLTFNodeIndex node_index);
Camera3D *_generate_camera(Ref<GLTFState> state, const GLTFNodeIndex node_index); Camera3D *_generate_camera(Ref<GLTFState> state, const GLTFNodeIndex node_index);
Node3D *_generate_light(Ref<GLTFState> state, const GLTFNodeIndex node_index); Light3D *_generate_light(Ref<GLTFState> state, const GLTFNodeIndex node_index);
Node3D *_generate_spatial(Ref<GLTFState> state, const GLTFNodeIndex node_index); Node3D *_generate_spatial(Ref<GLTFState> state, const GLTFNodeIndex node_index);
void _assign_scene_names(Ref<GLTFState> state); void _assign_scene_names(Ref<GLTFState> state);
template <class T> template <class T>