More fixes.

This commit is contained in:
Relintai 2022-08-07 22:53:31 +02:00
parent ef5f5f6da4
commit 5ac0285ea4
14 changed files with 180 additions and 180 deletions

View File

@ -23,7 +23,7 @@
</member> </member>
<member name="position" type="Vector3" setter="set_position" getter="get_position" default="Vector3(0, 0, 0)"> <member name="position" type="Vector3" setter="set_position" getter="get_position" default="Vector3(0, 0, 0)">
</member> </member>
<member name="rotation" type="Quaternion" setter="set_rotation" getter="get_rotation" default="Quaternion(0, 0, 0, 1)"> <member name="rotation" type="Quat" setter="set_rotation" getter="get_rotation" default="Quat(0, 0, 0, 1)">
</member> </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>
@ -31,7 +31,7 @@
</member> </member>
<member name="skin" type="int" setter="set_skin" getter="get_skin" default="-1"> <member name="skin" type="int" setter="set_skin" getter="get_skin" default="-1">
</member> </member>
<member name="xform" type="Transform3D" setter="set_xform" getter="get_xform" default="Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)"> <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> </member>
</members> </members>
</class> </class>

View File

@ -44,7 +44,7 @@ void GLTFSpecGloss::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "diffuse_img"), "set_diffuse_img", "get_diffuse_img"); // Ref<Image> ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "diffuse_img"), "set_diffuse_img", "get_diffuse_img"); // Ref<Image>
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "diffuse_factor"), "set_diffuse_factor", "get_diffuse_factor"); // Color ADD_PROPERTY(PropertyInfo(Variant::COLOR, "diffuse_factor"), "set_diffuse_factor", "get_diffuse_factor"); // Color
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gloss_factor"), "set_gloss_factor", "get_gloss_factor"); // float ADD_PROPERTY(PropertyInfo(Variant::REAL, "gloss_factor"), "set_gloss_factor", "get_gloss_factor"); // float
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "specular_factor"), "set_specular_factor", "get_specular_factor"); // Color ADD_PROPERTY(PropertyInfo(Variant::COLOR, "specular_factor"), "set_specular_factor", "get_specular_factor"); // Color
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "spec_gloss_img"), "set_spec_gloss_img", "get_spec_gloss_img"); // Ref<Image> ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "spec_gloss_img"), "set_spec_gloss_img", "get_spec_gloss_img"); // Ref<Image>
} }

View File

@ -44,9 +44,9 @@
#include "core/io/stream_peer.h" #include "core/io/stream_peer.h"
#include "core/math/disjoint_set.h" #include "core/math/disjoint_set.h"
#include "core/math/vector2.h" #include "core/math/vector2.h"
#include "core/variant/dictionary.h" #include "core/dictionary.h"
#include "core/variant/typed_array.h" #include "core/array.h"
#include "core/variant/variant.h" #include "core/variant.h"
#include "core/version.h" #include "core/version.h"
#include "drivers/png/png_driver_common.h" #include "drivers/png/png_driver_common.h"
#include "scene/2d/node_2d.h" #include "scene/2d/node_2d.h"
@ -339,7 +339,7 @@ static Vector3 _arr_to_vec3(const Array &p_array) {
return Vector3(p_array[0], p_array[1], p_array[2]); return Vector3(p_array[0], p_array[1], p_array[2]);
} }
static Array _quaternion_to_array(const Quaternion &p_quaternion) { static Array _quaternion_to_array(const Quat &p_quaternion) {
Array array; Array array;
array.resize(4); array.resize(4);
array[0] = p_quaternion.x; array[0] = p_quaternion.x;
@ -349,15 +349,15 @@ static Array _quaternion_to_array(const Quaternion &p_quaternion) {
return array; return array;
} }
static Quaternion _arr_to_quaternion(const Array &p_array) { static Quat _arr_to_quaternion(const Array &p_array) {
ERR_FAIL_COND_V(p_array.size() != 4, Quaternion()); ERR_FAIL_COND_V(p_array.size() != 4, Quat());
return Quaternion(p_array[0], p_array[1], p_array[2], p_array[3]); return Quat(p_array[0], p_array[1], p_array[2], p_array[3]);
} }
static Transform3D _arr_to_xform(const Array &p_array) { static Transform _arr_to_xform(const Array &p_array) {
ERR_FAIL_COND_V(p_array.size() != 16, Transform3D()); ERR_FAIL_COND_V(p_array.size() != 16, Transform());
Transform3D xform; Transform xform;
xform.basis.set_column(Vector3::AXIS_X, Vector3(p_array[0], p_array[1], p_array[2])); xform.basis.set_column(Vector3::AXIS_X, Vector3(p_array[0], p_array[1], p_array[2]));
xform.basis.set_column(Vector3::AXIS_Y, Vector3(p_array[4], p_array[5], p_array[6])); xform.basis.set_column(Vector3::AXIS_Y, Vector3(p_array[4], p_array[5], p_array[6]));
xform.basis.set_column(Vector3::AXIS_Z, Vector3(p_array[8], p_array[9], p_array[10])); xform.basis.set_column(Vector3::AXIS_Z, Vector3(p_array[8], p_array[9], p_array[10]));
@ -366,7 +366,7 @@ static Transform3D _arr_to_xform(const Array &p_array) {
return xform; return xform;
} }
static Vector<real_t> _xform_to_array(const Transform3D p_transform) { static Vector<real_t> _xform_to_array(const Transform p_transform) {
Vector<real_t> array; Vector<real_t> array;
array.resize(16); array.resize(16);
Vector3 axis_x = p_transform.get_basis().get_column(Vector3::AXIS_X); Vector3 axis_x = p_transform.get_basis().get_column(Vector3::AXIS_X);
@ -418,11 +418,11 @@ Error GLTFDocument::_serialize_nodes(Ref<GLTFState> state) {
} }
if (n->skeleton != -1 && n->skin < 0) { if (n->skeleton != -1 && n->skin < 0) {
} }
if (n->xform != Transform3D()) { if (n->xform != Transform()) {
node["matrix"] = _xform_to_array(n->xform); node["matrix"] = _xform_to_array(n->xform);
} }
if (!n->rotation.is_equal_approx(Quaternion())) { if (!n->rotation.is_equal_approx(Quat())) {
node["rotation"] = _quaternion_to_array(n->rotation); node["rotation"] = _quaternion_to_array(n->rotation);
} }
@ -1791,7 +1791,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_joints(Ref<GLTFState> state,
return state->accessors.size() - 1; return state->accessors.size() - 1;
} }
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_quaternions(Ref<GLTFState> state, const Vector<Quaternion> p_attribs, const bool p_for_vertex) { GLTFAccessorIndex GLTFDocument::_encode_accessor_as_quaternions(Ref<GLTFState> state, const Vector<Quat> p_attribs, const bool p_for_vertex) {
if (p_attribs.size() == 0) { if (p_attribs.size() == 0) {
return -1; return -1;
} }
@ -1806,7 +1806,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_quaternions(Ref<GLTFState> s
Vector<double> type_min; Vector<double> type_min;
type_min.resize(element_count); type_min.resize(element_count);
for (int i = 0; i < p_attribs.size(); i++) { for (int i = 0; i < p_attribs.size(); i++) {
Quaternion quaternion = p_attribs[i]; Quat quaternion = p_attribs[i];
attribs.write[(i * element_count) + 0] = Math::snapped(quaternion.x, CMP_NORMALIZE_TOLERANCE); attribs.write[(i * element_count) + 0] = Math::snapped(quaternion.x, CMP_NORMALIZE_TOLERANCE);
attribs.write[(i * element_count) + 1] = Math::snapped(quaternion.y, CMP_NORMALIZE_TOLERANCE); attribs.write[(i * element_count) + 1] = Math::snapped(quaternion.y, CMP_NORMALIZE_TOLERANCE);
attribs.write[(i * element_count) + 2] = Math::snapped(quaternion.z, CMP_NORMALIZE_TOLERANCE); attribs.write[(i * element_count) + 2] = Math::snapped(quaternion.z, CMP_NORMALIZE_TOLERANCE);
@ -1951,7 +1951,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec3(Ref<GLTFState> state, c
return state->accessors.size() - 1; return state->accessors.size() - 1;
} }
GLTFAccessorIndex GLTFDocument::_encode_accessor_as_xform(Ref<GLTFState> state, const Vector<Transform3D> p_attribs, const bool p_for_vertex) { GLTFAccessorIndex GLTFDocument::_encode_accessor_as_xform(Ref<GLTFState> state, const Vector<Transform> p_attribs, const bool p_for_vertex) {
if (p_attribs.size() == 0) { if (p_attribs.size() == 0) {
return -1; return -1;
} }
@ -1965,7 +1965,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_xform(Ref<GLTFState> state,
Vector<double> type_min; Vector<double> type_min;
type_min.resize(element_count); type_min.resize(element_count);
for (int i = 0; i < p_attribs.size(); i++) { for (int i = 0; i < p_attribs.size(); i++) {
Transform3D attrib = p_attribs[i]; Transform attrib = p_attribs[i];
Basis basis = attrib.get_basis(); Basis basis = attrib.get_basis();
Vector3 axis_0 = basis.get_column(Vector3::AXIS_X); Vector3 axis_0 = basis.get_column(Vector3::AXIS_X);
@ -2065,9 +2065,9 @@ Vector<Color> GLTFDocument::_decode_accessor_as_color(Ref<GLTFState> state, cons
} }
return ret; return ret;
} }
Vector<Quaternion> GLTFDocument::_decode_accessor_as_quaternion(Ref<GLTFState> state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { Vector<Quat> GLTFDocument::_decode_accessor_as_quaternion(Ref<GLTFState> state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) {
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
Vector<Quaternion> ret; Vector<Quat> ret;
if (attribs.size() == 0) { if (attribs.size() == 0) {
return ret; return ret;
@ -2079,7 +2079,7 @@ Vector<Quaternion> GLTFDocument::_decode_accessor_as_quaternion(Ref<GLTFState> s
ret.resize(ret_size); ret.resize(ret_size);
{ {
for (int i = 0; i < ret_size; i++) { for (int i = 0; i < ret_size; i++) {
ret.write[i] = Quaternion(attribs_ptr[i * 4 + 0], attribs_ptr[i * 4 + 1], attribs_ptr[i * 4 + 2], attribs_ptr[i * 4 + 3]).normalized(); ret.write[i] = Quat(attribs_ptr[i * 4 + 0], attribs_ptr[i * 4 + 1], attribs_ptr[i * 4 + 2], attribs_ptr[i * 4 + 3]).normalized();
} }
} }
return ret; return ret;
@ -2119,9 +2119,9 @@ Vector<Basis> GLTFDocument::_decode_accessor_as_basis(Ref<GLTFState> state, cons
return ret; return ret;
} }
Vector<Transform3D> GLTFDocument::_decode_accessor_as_xform(Ref<GLTFState> state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { Vector<Transform> GLTFDocument::_decode_accessor_as_xform(Ref<GLTFState> state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) {
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
Vector<Transform3D> ret; Vector<Transform> ret;
if (attribs.size() == 0) { if (attribs.size() == 0) {
return ret; return ret;
@ -2470,12 +2470,12 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) {
if (surface_i < instance_materials.size()) { if (surface_i < instance_materials.size()) {
v = instance_materials.get(surface_i); v = instance_materials.get(surface_i);
} }
Ref<BaseMaterial3D> mat = v; Ref<SpatialMaterial> mat = v;
if (!mat.is_valid()) { if (!mat.is_valid()) {
mat = import_mesh->get_surface_material(surface_i); mat = import_mesh->get_surface_material(surface_i);
} }
if (mat.is_valid()) { if (mat.is_valid()) {
HashMap<Ref<BaseMaterial3D>, GLTFMaterialIndex>::Iterator material_cache_i = state->material_cache.find(mat); HashMap<Ref<SpatialMaterial>, GLTFMaterialIndex>::Iterator material_cache_i = state->material_cache.find(mat);
if (material_cache_i && material_cache_i->value != -1) { if (material_cache_i && material_cache_i->value != -1) {
primitive["material"] = material_cache_i->value; primitive["material"] = material_cache_i->value;
} else { } else {
@ -2927,16 +2927,16 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) {
} }
} }
Ref<BaseMaterial3D> mat; Ref<SpatialMaterial> mat;
String mat_name; String mat_name;
if (!state->discard_meshes_and_materials) { if (!state->discard_meshes_and_materials) {
if (p.has("material")) { if (p.has("material")) {
const int material = p["material"]; const int material = p["material"];
ERR_FAIL_INDEX_V(material, state->materials.size(), ERR_FILE_CORRUPT); ERR_FAIL_INDEX_V(material, state->materials.size(), ERR_FILE_CORRUPT);
Ref<BaseMaterial3D> mat3d = state->materials[material]; Ref<SpatialMaterial> mat3d = state->materials[material];
ERR_FAIL_NULL_V(mat3d, ERR_FILE_CORRUPT); ERR_FAIL_NULL_V(mat3d, ERR_FILE_CORRUPT);
if (has_vertex_color) { if (has_vertex_color) {
mat3d->set_flag(BaseMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); mat3d->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
} }
mat = mat3d; mat = mat3d;
@ -2944,7 +2944,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) {
Ref<StandardMaterial3D> mat3d; Ref<StandardMaterial3D> mat3d;
mat3d.instantiate(); mat3d.instantiate();
if (has_vertex_color) { if (has_vertex_color) {
mat3d->set_flag(BaseMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); mat3d->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
} }
mat = mat3d; mat = mat3d;
} }
@ -3101,7 +3101,7 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_pat
!uri.begins_with("data:image/png;base64") && !uri.begins_with("data:image/png;base64") &&
!uri.begins_with("data:image/jpeg;base64")) { !uri.begins_with("data:image/jpeg;base64")) {
WARN_PRINT(vformat("glTF: Image index '%d' uses an unsupported URI data type: %s. Skipping it.", i, uri)); WARN_PRINT(vformat("glTF: Image index '%d' uses an unsupported URI data type: %s. Skipping it.", i, uri));
state->images.push_back(Ref<Texture2D>()); // Placeholder to keep count. state->images.push_back(Ref<Texture>()); // Placeholder to keep count.
continue; continue;
} }
data = _parse_base64_uri(uri); data = _parse_base64_uri(uri);
@ -3124,7 +3124,7 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_pat
// there could be a `.png` image which is actually JPEG), but there's no easy // there could be a `.png` image which is actually JPEG), but there's no easy
// API for that in Godot, so we'd have to load as a buffer (i.e. embedded in // API for that in Godot, so we'd have to load as a buffer (i.e. embedded in
// the material), so we do this only as fallback. // the material), so we do this only as fallback.
Ref<Texture2D> texture = ResourceLoader::load(uri); Ref<Texture> texture = ResourceLoader::load(uri);
if (texture.is_valid()) { if (texture.is_valid()) {
state->images.push_back(texture); state->images.push_back(texture);
continue; continue;
@ -3135,14 +3135,14 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_pat
data = FileAccess::get_file_as_array(uri); data = FileAccess::get_file_as_array(uri);
if (data.size() == 0) { if (data.size() == 0) {
WARN_PRINT(vformat("glTF: Image index '%d' couldn't be loaded as a buffer of MIME type '%s' from URI: %s. Skipping it.", i, mimetype, uri)); WARN_PRINT(vformat("glTF: Image index '%d' couldn't be loaded as a buffer of MIME type '%s' from URI: %s. Skipping it.", i, mimetype, uri));
state->images.push_back(Ref<Texture2D>()); // Placeholder to keep count. state->images.push_back(Ref<Texture>()); // Placeholder to keep count.
continue; continue;
} }
data_ptr = data.ptr(); data_ptr = data.ptr();
data_size = data.size(); data_size = data.size();
} else { } else {
WARN_PRINT(vformat("glTF: Image index '%d' couldn't be loaded from URI: %s. Skipping it.", i, uri)); WARN_PRINT(vformat("glTF: Image index '%d' couldn't be loaded from URI: %s. Skipping it.", i, uri));
state->images.push_back(Ref<Texture2D>()); // Placeholder to keep count. state->images.push_back(Ref<Texture>()); // Placeholder to keep count.
continue; continue;
} }
} }
@ -3195,7 +3195,7 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_pat
// Now we've done our best, fix your scenes. // Now we've done our best, fix your scenes.
if (img.is_null()) { if (img.is_null()) {
ERR_PRINT(vformat("glTF: Couldn't load image index '%d' with its given mimetype: %s.", i, mimetype)); ERR_PRINT(vformat("glTF: Couldn't load image index '%d' with its given mimetype: %s.", i, mimetype));
state->images.push_back(Ref<Texture2D>()); state->images.push_back(Ref<Texture>());
continue; continue;
} }
state->images.push_back(ImageTexture::create_from_image(img)); state->images.push_back(ImageTexture::create_from_image(img));
@ -3244,7 +3244,7 @@ Error GLTFDocument::_parse_textures(Ref<GLTFState> state) {
return OK; return OK;
} }
GLTFTextureIndex GLTFDocument::_set_texture(Ref<GLTFState> state, Ref<Texture2D> p_texture) { GLTFTextureIndex GLTFDocument::_set_texture(Ref<GLTFState> state, Ref<Texture> p_texture) {
ERR_FAIL_COND_V(p_texture.is_null(), -1); ERR_FAIL_COND_V(p_texture.is_null(), -1);
Ref<GLTFTexture> gltf_texture; Ref<GLTFTexture> gltf_texture;
gltf_texture.instantiate(); gltf_texture.instantiate();
@ -3257,11 +3257,11 @@ GLTFTextureIndex GLTFDocument::_set_texture(Ref<GLTFState> state, Ref<Texture2D>
return gltf_texture_i; return gltf_texture_i;
} }
Ref<Texture2D> GLTFDocument::_get_texture(Ref<GLTFState> state, const GLTFTextureIndex p_texture) { Ref<Texture> GLTFDocument::_get_texture(Ref<GLTFState> state, const GLTFTextureIndex p_texture) {
ERR_FAIL_INDEX_V(p_texture, state->textures.size(), Ref<Texture2D>()); ERR_FAIL_INDEX_V(p_texture, state->textures.size(), Ref<Texture>());
const GLTFImageIndex image = state->textures[p_texture]->get_src_image(); const GLTFImageIndex image = state->textures[p_texture]->get_src_image();
ERR_FAIL_INDEX_V(image, state->images.size(), Ref<Texture2D>()); ERR_FAIL_INDEX_V(image, state->images.size(), Ref<Texture>());
return state->images[image]; return state->images[image];
} }
@ -3271,7 +3271,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
for (int32_t i = 0; i < state->materials.size(); i++) { for (int32_t i = 0; i < state->materials.size(); i++) {
Dictionary d; Dictionary d;
Ref<BaseMaterial3D> material = state->materials[i]; Ref<SpatialMaterial> material = state->materials[i];
if (material.is_null()) { if (material.is_null()) {
materials.push_back(d); materials.push_back(d);
continue; continue;
@ -3292,7 +3292,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
} }
{ {
Dictionary bct; Dictionary bct;
Ref<Texture2D> albedo_texture = material->get_texture(BaseMaterial3D::TEXTURE_ALBEDO); Ref<Texture> albedo_texture = material->get_texture(SpatialMaterial::TEXTURE_ALBEDO);
GLTFTextureIndex gltf_texture_index = -1; GLTFTextureIndex gltf_texture_index = -1;
if (albedo_texture.is_valid() && albedo_texture->get_image().is_valid()) { if (albedo_texture.is_valid() && albedo_texture->get_image().is_valid()) {
@ -3312,17 +3312,17 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
mr["metallicFactor"] = material->get_metallic(); mr["metallicFactor"] = material->get_metallic();
mr["roughnessFactor"] = material->get_roughness(); mr["roughnessFactor"] = material->get_roughness();
bool has_roughness = material->get_texture(BaseMaterial3D::TEXTURE_ROUGHNESS).is_valid() && material->get_texture(BaseMaterial3D::TEXTURE_ROUGHNESS)->get_image().is_valid(); bool has_roughness = material->get_texture(SpatialMaterial::TEXTURE_ROUGHNESS).is_valid() && material->get_texture(SpatialMaterial::TEXTURE_ROUGHNESS)->get_image().is_valid();
bool has_ao = material->get_feature(BaseMaterial3D::FEATURE_AMBIENT_OCCLUSION) && material->get_texture(BaseMaterial3D::TEXTURE_AMBIENT_OCCLUSION).is_valid(); bool has_ao = material->get_feature(SpatialMaterial::FEATURE_AMBIENT_OCCLUSION) && material->get_texture(SpatialMaterial::TEXTURE_AMBIENT_OCCLUSION).is_valid();
bool has_metalness = material->get_texture(BaseMaterial3D::TEXTURE_METALLIC).is_valid() && material->get_texture(BaseMaterial3D::TEXTURE_METALLIC)->get_image().is_valid(); bool has_metalness = material->get_texture(SpatialMaterial::TEXTURE_METALLIC).is_valid() && material->get_texture(SpatialMaterial::TEXTURE_METALLIC)->get_image().is_valid();
if (has_ao || has_roughness || has_metalness) { if (has_ao || has_roughness || has_metalness) {
Dictionary mrt; Dictionary mrt;
Ref<Texture2D> roughness_texture = material->get_texture(BaseMaterial3D::TEXTURE_ROUGHNESS); Ref<Texture> roughness_texture = material->get_texture(SpatialMaterial::TEXTURE_ROUGHNESS);
BaseMaterial3D::TextureChannel roughness_channel = material->get_roughness_texture_channel(); SpatialMaterial::TextureChannel roughness_channel = material->get_roughness_texture_channel();
Ref<Texture2D> metallic_texture = material->get_texture(BaseMaterial3D::TEXTURE_METALLIC); Ref<Texture> metallic_texture = material->get_texture(SpatialMaterial::TEXTURE_METALLIC);
BaseMaterial3D::TextureChannel metalness_channel = material->get_metallic_texture_channel(); SpatialMaterial::TextureChannel metalness_channel = material->get_metallic_texture_channel();
Ref<Texture2D> ao_texture = material->get_texture(BaseMaterial3D::TEXTURE_AMBIENT_OCCLUSION); Ref<Texture> ao_texture = material->get_texture(SpatialMaterial::TEXTURE_AMBIENT_OCCLUSION);
BaseMaterial3D::TextureChannel ao_channel = material->get_ao_texture_channel(); SpatialMaterial::TextureChannel ao_channel = material->get_ao_texture_channel();
Ref<ImageTexture> orm_texture; Ref<ImageTexture> orm_texture;
orm_texture.instantiate(); orm_texture.instantiate();
Ref<Image> orm_image; Ref<Image> orm_image;
@ -3368,7 +3368,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
metallness_image->decompress(); metallness_image->decompress();
} }
} }
Ref<Texture2D> albedo_texture = material->get_texture(BaseMaterial3D::TEXTURE_ALBEDO); Ref<Texture> albedo_texture = material->get_texture(SpatialMaterial::TEXTURE_ALBEDO);
if (albedo_texture.is_valid() && albedo_texture->get_image().is_valid()) { if (albedo_texture.is_valid() && albedo_texture->get_image().is_valid()) {
height = albedo_texture->get_height(); height = albedo_texture->get_height();
width = albedo_texture->get_width(); width = albedo_texture->get_width();
@ -3387,35 +3387,35 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
for (int32_t w = 0; w < width; w++) { for (int32_t w = 0; w < width; w++) {
Color c = Color(1.0f, 1.0f, 1.0f); Color c = Color(1.0f, 1.0f, 1.0f);
if (has_ao) { if (has_ao) {
if (BaseMaterial3D::TextureChannel::TEXTURE_CHANNEL_RED == ao_channel) { if (SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_RED == ao_channel) {
c.r = ao_image->get_pixel(w, h).r; c.r = ao_image->get_pixel(w, h).r;
} else if (BaseMaterial3D::TextureChannel::TEXTURE_CHANNEL_GREEN == ao_channel) { } else if (SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_GREEN == ao_channel) {
c.r = ao_image->get_pixel(w, h).g; c.r = ao_image->get_pixel(w, h).g;
} else if (BaseMaterial3D::TextureChannel::TEXTURE_CHANNEL_BLUE == ao_channel) { } else if (SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_BLUE == ao_channel) {
c.r = ao_image->get_pixel(w, h).b; c.r = ao_image->get_pixel(w, h).b;
} else if (BaseMaterial3D::TextureChannel::TEXTURE_CHANNEL_ALPHA == ao_channel) { } else if (SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_ALPHA == ao_channel) {
c.r = ao_image->get_pixel(w, h).a; c.r = ao_image->get_pixel(w, h).a;
} }
} }
if (has_roughness) { if (has_roughness) {
if (BaseMaterial3D::TextureChannel::TEXTURE_CHANNEL_RED == roughness_channel) { if (SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_RED == roughness_channel) {
c.g = roughness_image->get_pixel(w, h).r; c.g = roughness_image->get_pixel(w, h).r;
} else if (BaseMaterial3D::TextureChannel::TEXTURE_CHANNEL_GREEN == roughness_channel) { } else if (SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_GREEN == roughness_channel) {
c.g = roughness_image->get_pixel(w, h).g; c.g = roughness_image->get_pixel(w, h).g;
} else if (BaseMaterial3D::TextureChannel::TEXTURE_CHANNEL_BLUE == roughness_channel) { } else if (SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_BLUE == roughness_channel) {
c.g = roughness_image->get_pixel(w, h).b; c.g = roughness_image->get_pixel(w, h).b;
} else if (BaseMaterial3D::TextureChannel::TEXTURE_CHANNEL_ALPHA == roughness_channel) { } else if (SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_ALPHA == roughness_channel) {
c.g = roughness_image->get_pixel(w, h).a; c.g = roughness_image->get_pixel(w, h).a;
} }
} }
if (has_metalness) { if (has_metalness) {
if (BaseMaterial3D::TextureChannel::TEXTURE_CHANNEL_RED == metalness_channel) { if (SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_RED == metalness_channel) {
c.b = metallness_image->get_pixel(w, h).r; c.b = metallness_image->get_pixel(w, h).r;
} else if (BaseMaterial3D::TextureChannel::TEXTURE_CHANNEL_GREEN == metalness_channel) { } else if (SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_GREEN == metalness_channel) {
c.b = metallness_image->get_pixel(w, h).g; c.b = metallness_image->get_pixel(w, h).g;
} else if (BaseMaterial3D::TextureChannel::TEXTURE_CHANNEL_BLUE == metalness_channel) { } else if (SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_BLUE == metalness_channel) {
c.b = metallness_image->get_pixel(w, h).b; c.b = metallness_image->get_pixel(w, h).b;
} else if (BaseMaterial3D::TextureChannel::TEXTURE_CHANNEL_ALPHA == metalness_channel) { } else if (SpatialMaterial::TextureChannel::TEXTURE_CHANNEL_ALPHA == metalness_channel) {
c.b = metallness_image->get_pixel(w, h).a; c.b = metallness_image->get_pixel(w, h).a;
} }
} }
@ -3447,12 +3447,12 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
d["pbrMetallicRoughness"] = mr; d["pbrMetallicRoughness"] = mr;
} }
if (material->get_feature(BaseMaterial3D::FEATURE_NORMAL_MAPPING)) { if (material->get_feature(SpatialMaterial::FEATURE_NORMAL_MAPPING)) {
Dictionary nt; Dictionary nt;
Ref<ImageTexture> tex; Ref<ImageTexture> tex;
tex.instantiate(); tex.instantiate();
{ {
Ref<Texture2D> normal_texture = material->get_texture(BaseMaterial3D::TEXTURE_NORMAL); Ref<Texture> normal_texture = material->get_texture(SpatialMaterial::TEXTURE_NORMAL);
if (normal_texture.is_valid()) { if (normal_texture.is_valid()) {
// Code for uncompressing RG normal maps // Code for uncompressing RG normal maps
Ref<Image> img = normal_texture->get_image(); Ref<Image> img = normal_texture->get_image();
@ -3491,7 +3491,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
} }
} }
if (material->get_feature(BaseMaterial3D::FEATURE_EMISSION)) { if (material->get_feature(SpatialMaterial::FEATURE_EMISSION)) {
const Color c = material->get_emission().linear_to_srgb(); const Color c = material->get_emission().linear_to_srgb();
Array arr; Array arr;
arr.push_back(c.r); arr.push_back(c.r);
@ -3499,9 +3499,9 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
arr.push_back(c.b); arr.push_back(c.b);
d["emissiveFactor"] = arr; d["emissiveFactor"] = arr;
} }
if (material->get_feature(BaseMaterial3D::FEATURE_EMISSION)) { if (material->get_feature(SpatialMaterial::FEATURE_EMISSION)) {
Dictionary et; Dictionary et;
Ref<Texture2D> emission_texture = material->get_texture(BaseMaterial3D::TEXTURE_EMISSION); Ref<Texture> emission_texture = material->get_texture(SpatialMaterial::TEXTURE_EMISSION);
GLTFTextureIndex gltf_texture_index = -1; GLTFTextureIndex gltf_texture_index = -1;
if (emission_texture.is_valid() && emission_texture->get_image().is_valid()) { if (emission_texture.is_valid() && emission_texture->get_image().is_valid()) {
emission_texture->set_name(material->get_name() + "_emission"); emission_texture->set_name(material->get_name() + "_emission");
@ -3513,14 +3513,14 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
d["emissiveTexture"] = et; d["emissiveTexture"] = et;
} }
} }
const bool ds = material->get_cull_mode() == BaseMaterial3D::CULL_DISABLED; const bool ds = material->get_cull_mode() == SpatialMaterial::CULL_DISABLED;
if (ds) { if (ds) {
d["doubleSided"] = ds; d["doubleSided"] = ds;
} }
if (material->get_transparency() == BaseMaterial3D::TRANSPARENCY_ALPHA_SCISSOR) { if (material->get_transparency() == SpatialMaterial::TRANSPARENCY_ALPHA_SCISSOR) {
d["alphaMode"] = "MASK"; d["alphaMode"] = "MASK";
d["alphaCutoff"] = material->get_alpha_scissor_threshold(); d["alphaCutoff"] = material->get_alpha_scissor_threshold();
} else if (material->get_transparency() != BaseMaterial3D::TRANSPARENCY_DISABLED) { } else if (material->get_transparency() != SpatialMaterial::TRANSPARENCY_DISABLED) {
d["alphaMode"] = "BLEND"; d["alphaMode"] = "BLEND";
} }
materials.push_back(d); materials.push_back(d);
@ -3550,7 +3550,7 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) {
} else { } else {
material->set_name(vformat("material_%s", itos(i))); material->set_name(vformat("material_%s", itos(i)));
} }
material->set_flag(BaseMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
Dictionary pbr_spec_gloss_extensions; Dictionary pbr_spec_gloss_extensions;
if (d.has("extensions")) { if (d.has("extensions")) {
pbr_spec_gloss_extensions = d["extensions"]; pbr_spec_gloss_extensions = d["extensions"];
@ -3564,10 +3564,10 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) {
if (sgm.has("diffuseTexture")) { if (sgm.has("diffuseTexture")) {
const Dictionary &diffuse_texture_dict = sgm["diffuseTexture"]; const Dictionary &diffuse_texture_dict = sgm["diffuseTexture"];
if (diffuse_texture_dict.has("index")) { if (diffuse_texture_dict.has("index")) {
Ref<Texture2D> diffuse_texture = _get_texture(state, diffuse_texture_dict["index"]); Ref<Texture> diffuse_texture = _get_texture(state, diffuse_texture_dict["index"]);
if (diffuse_texture.is_valid()) { if (diffuse_texture.is_valid()) {
spec_gloss->diffuse_img = diffuse_texture->get_image(); spec_gloss->diffuse_img = diffuse_texture->get_image();
material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, diffuse_texture); material->set_texture(SpatialMaterial::TEXTURE_ALBEDO, diffuse_texture);
} }
} }
} }
@ -3592,7 +3592,7 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) {
if (sgm.has("specularGlossinessTexture")) { if (sgm.has("specularGlossinessTexture")) {
const Dictionary &spec_gloss_texture = sgm["specularGlossinessTexture"]; const Dictionary &spec_gloss_texture = sgm["specularGlossinessTexture"];
if (spec_gloss_texture.has("index")) { if (spec_gloss_texture.has("index")) {
const Ref<Texture2D> orig_texture = _get_texture(state, spec_gloss_texture["index"]); const Ref<Texture> orig_texture = _get_texture(state, spec_gloss_texture["index"]);
if (orig_texture.is_valid()) { if (orig_texture.is_valid()) {
spec_gloss->spec_gloss_img = orig_texture->get_image(); spec_gloss->spec_gloss_img = orig_texture->get_image();
} }
@ -3612,7 +3612,7 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) {
if (mr.has("baseColorTexture")) { if (mr.has("baseColorTexture")) {
const Dictionary &bct = mr["baseColorTexture"]; const Dictionary &bct = mr["baseColorTexture"];
if (bct.has("index")) { if (bct.has("index")) {
material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, _get_texture(state, bct["index"])); material->set_texture(SpatialMaterial::TEXTURE_ALBEDO, _get_texture(state, bct["index"]));
} }
if (!mr.has("baseColorFactor")) { if (!mr.has("baseColorFactor")) {
material->set_albedo(Color(1, 1, 1)); material->set_albedo(Color(1, 1, 1));
@ -3635,11 +3635,11 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) {
if (mr.has("metallicRoughnessTexture")) { if (mr.has("metallicRoughnessTexture")) {
const Dictionary &bct = mr["metallicRoughnessTexture"]; const Dictionary &bct = mr["metallicRoughnessTexture"];
if (bct.has("index")) { if (bct.has("index")) {
const Ref<Texture2D> t = _get_texture(state, bct["index"]); const Ref<Texture> t = _get_texture(state, bct["index"]);
material->set_texture(BaseMaterial3D::TEXTURE_METALLIC, t); material->set_texture(SpatialMaterial::TEXTURE_METALLIC, t);
material->set_metallic_texture_channel(BaseMaterial3D::TEXTURE_CHANNEL_BLUE); material->set_metallic_texture_channel(SpatialMaterial::TEXTURE_CHANNEL_BLUE);
material->set_texture(BaseMaterial3D::TEXTURE_ROUGHNESS, t); material->set_texture(SpatialMaterial::TEXTURE_ROUGHNESS, t);
material->set_roughness_texture_channel(BaseMaterial3D::TEXTURE_CHANNEL_GREEN); material->set_roughness_texture_channel(SpatialMaterial::TEXTURE_CHANNEL_GREEN);
if (!mr.has("metallicFactor")) { if (!mr.has("metallicFactor")) {
material->set_metallic(1); material->set_metallic(1);
} }
@ -3653,8 +3653,8 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) {
if (d.has("normalTexture")) { if (d.has("normalTexture")) {
const Dictionary &bct = d["normalTexture"]; const Dictionary &bct = d["normalTexture"];
if (bct.has("index")) { if (bct.has("index")) {
material->set_texture(BaseMaterial3D::TEXTURE_NORMAL, _get_texture(state, bct["index"])); material->set_texture(SpatialMaterial::TEXTURE_NORMAL, _get_texture(state, bct["index"]));
material->set_feature(BaseMaterial3D::FEATURE_NORMAL_MAPPING, true); material->set_feature(SpatialMaterial::FEATURE_NORMAL_MAPPING, true);
} }
if (bct.has("scale")) { if (bct.has("scale")) {
material->set_normal_scale(bct["scale"]); material->set_normal_scale(bct["scale"]);
@ -3663,9 +3663,9 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) {
if (d.has("occlusionTexture")) { if (d.has("occlusionTexture")) {
const Dictionary &bct = d["occlusionTexture"]; const Dictionary &bct = d["occlusionTexture"];
if (bct.has("index")) { if (bct.has("index")) {
material->set_texture(BaseMaterial3D::TEXTURE_AMBIENT_OCCLUSION, _get_texture(state, bct["index"])); material->set_texture(SpatialMaterial::TEXTURE_AMBIENT_OCCLUSION, _get_texture(state, bct["index"]));
material->set_ao_texture_channel(BaseMaterial3D::TEXTURE_CHANNEL_RED); material->set_ao_texture_channel(SpatialMaterial::TEXTURE_CHANNEL_RED);
material->set_feature(BaseMaterial3D::FEATURE_AMBIENT_OCCLUSION, true); material->set_feature(SpatialMaterial::FEATURE_AMBIENT_OCCLUSION, true);
} }
} }
@ -3673,7 +3673,7 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) {
const Array &arr = d["emissiveFactor"]; const Array &arr = d["emissiveFactor"];
ERR_FAIL_COND_V(arr.size() != 3, ERR_PARSE_ERROR); ERR_FAIL_COND_V(arr.size() != 3, ERR_PARSE_ERROR);
const Color c = Color(arr[0], arr[1], arr[2]).linear_to_srgb(); const Color c = Color(arr[0], arr[1], arr[2]).linear_to_srgb();
material->set_feature(BaseMaterial3D::FEATURE_EMISSION, true); material->set_feature(SpatialMaterial::FEATURE_EMISSION, true);
material->set_emission(c); material->set_emission(c);
} }
@ -3681,8 +3681,8 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) {
if (d.has("emissiveTexture")) { if (d.has("emissiveTexture")) {
const Dictionary &bct = d["emissiveTexture"]; const Dictionary &bct = d["emissiveTexture"];
if (bct.has("index")) { if (bct.has("index")) {
material->set_texture(BaseMaterial3D::TEXTURE_EMISSION, _get_texture(state, bct["index"])); material->set_texture(SpatialMaterial::TEXTURE_EMISSION, _get_texture(state, bct["index"]));
material->set_feature(BaseMaterial3D::FEATURE_EMISSION, true); material->set_feature(SpatialMaterial::FEATURE_EMISSION, true);
material->set_emission(Color(0, 0, 0)); material->set_emission(Color(0, 0, 0));
} }
} }
@ -3690,15 +3690,15 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) {
if (d.has("doubleSided")) { if (d.has("doubleSided")) {
const bool ds = d["doubleSided"]; const bool ds = d["doubleSided"];
if (ds) { if (ds) {
material->set_cull_mode(BaseMaterial3D::CULL_DISABLED); material->set_cull_mode(SpatialMaterial::CULL_DISABLED);
} }
} }
if (d.has("alphaMode")) { if (d.has("alphaMode")) {
const String &am = d["alphaMode"]; const String &am = d["alphaMode"];
if (am == "BLEND") { if (am == "BLEND") {
material->set_transparency(BaseMaterial3D::TRANSPARENCY_ALPHA_DEPTH_PRE_PASS); material->set_transparency(SpatialMaterial::TRANSPARENCY_ALPHA_DEPTH_PRE_PASS);
} else if (am == "MASK") { } else if (am == "MASK") {
material->set_transparency(BaseMaterial3D::TRANSPARENCY_ALPHA_SCISSOR); material->set_transparency(SpatialMaterial::TRANSPARENCY_ALPHA_SCISSOR);
if (d.has("alphaCutoff")) { if (d.has("alphaCutoff")) {
material->set_alpha_scissor_threshold(d["alphaCutoff"]); material->set_alpha_scissor_threshold(d["alphaCutoff"]);
} else { } else {
@ -3714,7 +3714,7 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) {
return OK; return OK;
} }
void GLTFDocument::_set_texture_transform_uv1(const Dictionary &d, Ref<BaseMaterial3D> material) { void GLTFDocument::_set_texture_transform_uv1(const Dictionary &d, Ref<SpatialMaterial> material) {
if (d.has("extensions")) { if (d.has("extensions")) {
const Dictionary &extensions = d["extensions"]; const Dictionary &extensions = d["extensions"];
if (extensions.has("KHR_texture_transform")) { if (extensions.has("KHR_texture_transform")) {
@ -3734,7 +3734,7 @@ void GLTFDocument::_set_texture_transform_uv1(const Dictionary &d, Ref<BaseMater
} }
} }
void GLTFDocument::spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss, Ref<BaseMaterial3D> p_material) { void GLTFDocument::spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss, Ref<SpatialMaterial> p_material) {
if (r_spec_gloss->spec_gloss_img.is_null()) { if (r_spec_gloss->spec_gloss_img.is_null()) {
return; return;
} }
@ -3783,16 +3783,16 @@ void GLTFDocument::spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss, Re
} }
rm_img->generate_mipmaps(); rm_img->generate_mipmaps();
r_spec_gloss->diffuse_img->generate_mipmaps(); r_spec_gloss->diffuse_img->generate_mipmaps();
p_material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, ImageTexture::create_from_image(r_spec_gloss->diffuse_img)); p_material->set_texture(SpatialMaterial::TEXTURE_ALBEDO, ImageTexture::create_from_image(r_spec_gloss->diffuse_img));
Ref<ImageTexture> rm_image_texture = ImageTexture::create_from_image(rm_img); Ref<ImageTexture> rm_image_texture = ImageTexture::create_from_image(rm_img);
if (has_roughness) { if (has_roughness) {
p_material->set_texture(BaseMaterial3D::TEXTURE_ROUGHNESS, rm_image_texture); p_material->set_texture(SpatialMaterial::TEXTURE_ROUGHNESS, rm_image_texture);
p_material->set_roughness_texture_channel(BaseMaterial3D::TEXTURE_CHANNEL_GREEN); p_material->set_roughness_texture_channel(SpatialMaterial::TEXTURE_CHANNEL_GREEN);
} }
if (has_metal) { if (has_metal) {
p_material->set_texture(BaseMaterial3D::TEXTURE_METALLIC, rm_image_texture); p_material->set_texture(SpatialMaterial::TEXTURE_METALLIC, rm_image_texture);
p_material->set_metallic_texture_channel(BaseMaterial3D::TEXTURE_CHANNEL_BLUE); p_material->set_metallic_texture_channel(SpatialMaterial::TEXTURE_CHANNEL_BLUE);
} }
} }
@ -4459,7 +4459,7 @@ Error GLTFDocument::_create_skins(Ref<GLTFState> state) {
GLTFNodeIndex node = gltf_skin->joints_original[joint_i]; GLTFNodeIndex node = gltf_skin->joints_original[joint_i];
String bone_name = state->nodes[node]->get_name(); String bone_name = state->nodes[node]->get_name();
Transform3D xform; Transform xform;
if (has_ibms) { if (has_ibms) {
xform = gltf_skin->inverse_binds[joint_i]; xform = gltf_skin->inverse_binds[joint_i];
} }
@ -4503,8 +4503,8 @@ bool GLTFDocument::_skins_are_same(const Ref<Skin> skin_a, const Ref<Skin> skin_
return false; return false;
} }
Transform3D a_xform = skin_a->get_bind_pose(i); Transform a_xform = skin_a->get_bind_pose(i);
Transform3D b_xform = skin_b->get_bind_pose(i); Transform b_xform = skin_b->get_bind_pose(i);
if (a_xform != b_xform) { if (a_xform != b_xform) {
return false; return false;
@ -4786,7 +4786,7 @@ Error GLTFDocument::_serialize_animations(Ref<GLTFState> state) {
s["interpolation"] = interpolation_to_string(track.rotation_track.interpolation); s["interpolation"] = interpolation_to_string(track.rotation_track.interpolation);
Vector<real_t> times = Variant(track.rotation_track.times); Vector<real_t> times = Variant(track.rotation_track.times);
s["input"] = _encode_accessor_as_floats(state, times, false); s["input"] = _encode_accessor_as_floats(state, times, false);
Vector<Quaternion> values = track.rotation_track.values; Vector<Quat> values = track.rotation_track.values;
s["output"] = _encode_accessor_as_quaternions(state, values, false); s["output"] = _encode_accessor_as_quaternions(state, values, false);
samplers.push_back(s); samplers.push_back(s);
@ -5004,7 +5004,7 @@ Error GLTFDocument::_parse_animations(Ref<GLTFState> state) {
track->position_track.times = Variant(times); //convert via variant track->position_track.times = Variant(times); //convert via variant
track->position_track.values = Variant(positions); //convert via variant track->position_track.values = Variant(positions); //convert via variant
} else if (path == "rotation") { } else if (path == "rotation") {
const Vector<Quaternion> rotations = _decode_accessor_as_quaternion(state, output, false); const Vector<Quat> rotations = _decode_accessor_as_quaternion(state, output, false);
track->rotation_track.interpolation = interp; track->rotation_track.interpolation = interp;
track->rotation_track.times = Variant(times); //convert via variant track->rotation_track.times = Variant(times); //convert via variant
track->rotation_track.values = rotations; track->rotation_track.values = rotations;
@ -5264,7 +5264,7 @@ GLTFLightIndex GLTFDocument::_convert_light(Ref<GLTFState> state, Light *p_light
} }
void GLTFDocument::_convert_spatial(Ref<GLTFState> state, Node3D *p_spatial, Ref<GLTFNode> p_node) { void GLTFDocument::_convert_spatial(Ref<GLTFState> state, Node3D *p_spatial, Ref<GLTFNode> p_node) {
Transform3D xform = p_spatial->get_transform(); Transform xform = p_spatial->get_transform();
p_node->scale = xform.basis.get_scale(); p_node->scale = xform.basis.get_scale();
p_node->rotation = xform.basis.get_rotation_quaternion(); p_node->rotation = xform.basis.get_rotation_quaternion();
p_node->position = xform.origin; p_node->position = xform.origin;
@ -5421,13 +5421,13 @@ void GLTFDocument::_convert_multi_mesh_instance_to_gltf(
state->meshes.push_back(gltf_mesh); state->meshes.push_back(gltf_mesh);
for (int32_t instance_i = 0; instance_i < multi_mesh->get_instance_count(); for (int32_t instance_i = 0; instance_i < multi_mesh->get_instance_count();
instance_i++) { instance_i++) {
Transform3D transform; Transform transform;
if (multi_mesh->get_transform_format() == MultiMesh::TRANSFORM_2D) { if (multi_mesh->get_transform_format() == MultiMesh::TRANSFORM_2D) {
Transform2D xform_2d = multi_mesh->get_instance_transform_2d(instance_i); Transform2D xform_2d = multi_mesh->get_instance_transform_2d(instance_i);
transform.origin = transform.origin =
Vector3(xform_2d.get_origin().x, 0, xform_2d.get_origin().y); Vector3(xform_2d.get_origin().x, 0, xform_2d.get_origin().y);
real_t rotation = xform_2d.get_rotation(); real_t rotation = xform_2d.get_rotation();
Quaternion quaternion(Vector3(0, 1, 0), rotation); Quat quaternion(Vector3(0, 1, 0), rotation);
Size2 scale = xform_2d.get_scale(); Size2 scale = xform_2d.get_scale();
transform.basis.set_quaternion_scale(quaternion, transform.basis.set_quaternion_scale(quaternion,
Vector3(scale.x, 0, scale.y)); Vector3(scale.x, 0, scale.y));
@ -5464,7 +5464,7 @@ void GLTFDocument::_convert_skeleton_to_gltf(Skeleton *p_skeleton3d, Ref<GLTFSta
// Note that we cannot use _gen_unique_bone_name here, because glTF spec requires all node // Note that we cannot use _gen_unique_bone_name here, because glTF spec requires all node
// names to be unique regardless of whether or not they are used as joints. // names to be unique regardless of whether or not they are used as joints.
joint_node->set_name(_gen_unique_name(state, skeleton->get_bone_name(bone_i))); joint_node->set_name(_gen_unique_name(state, skeleton->get_bone_name(bone_i)));
Transform3D xform = skeleton->get_bone_pose(bone_i); Transform xform = skeleton->get_bone_pose(bone_i);
joint_node->scale = xform.basis.get_scale(); joint_node->scale = xform.basis.get_scale();
joint_node->rotation = xform.basis.get_rotation_quaternion(); joint_node->rotation = xform.basis.get_rotation_quaternion();
joint_node->position = xform.origin; joint_node->position = xform.origin;
@ -5700,24 +5700,24 @@ struct SceneFormatImporterGLTFInterpolate {
// thank you for existing, partial specialization // thank you for existing, partial specialization
template <> template <>
struct SceneFormatImporterGLTFInterpolate<Quaternion> { struct SceneFormatImporterGLTFInterpolate<Quat> {
Quaternion lerp(const Quaternion &a, const Quaternion &b, const float c) const { Quat lerp(const Quat &a, const Quat &b, const float c) const {
ERR_FAIL_COND_V_MSG(!a.is_normalized(), Quaternion(), "The quaternion \"a\" must be normalized."); ERR_FAIL_COND_V_MSG(!a.is_normalized(), Quat(), "The quaternion \"a\" must be normalized.");
ERR_FAIL_COND_V_MSG(!b.is_normalized(), Quaternion(), "The quaternion \"b\" must be normalized."); ERR_FAIL_COND_V_MSG(!b.is_normalized(), Quat(), "The quaternion \"b\" must be normalized.");
return a.slerp(b, c).normalized(); return a.slerp(b, c).normalized();
} }
Quaternion catmull_rom(const Quaternion &p0, const Quaternion &p1, const Quaternion &p2, const Quaternion &p3, const float c) { Quat catmull_rom(const Quat &p0, const Quat &p1, const Quat &p2, const Quat &p3, const float c) {
ERR_FAIL_COND_V_MSG(!p1.is_normalized(), Quaternion(), "The quaternion \"p1\" must be normalized."); ERR_FAIL_COND_V_MSG(!p1.is_normalized(), Quat(), "The quaternion \"p1\" must be normalized.");
ERR_FAIL_COND_V_MSG(!p2.is_normalized(), Quaternion(), "The quaternion \"p2\" must be normalized."); ERR_FAIL_COND_V_MSG(!p2.is_normalized(), Quat(), "The quaternion \"p2\" must be normalized.");
return p1.slerp(p2, c).normalized(); return p1.slerp(p2, c).normalized();
} }
Quaternion bezier(const Quaternion start, const Quaternion control_1, const Quaternion control_2, const Quaternion end, const float t) { Quat bezier(const Quat start, const Quat control_1, const Quat control_2, const Quat end, const float t) {
ERR_FAIL_COND_V_MSG(!start.is_normalized(), Quaternion(), "The start quaternion must be normalized."); ERR_FAIL_COND_V_MSG(!start.is_normalized(), Quat(), "The start quaternion must be normalized.");
ERR_FAIL_COND_V_MSG(!end.is_normalized(), Quaternion(), "The end quaternion must be normalized."); ERR_FAIL_COND_V_MSG(!end.is_normalized(), Quat(), "The end quaternion must be normalized.");
return start.slerp(end, t).normalized(); return start.slerp(end, t).normalized();
} }
@ -5896,10 +5896,10 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap,
} }
} }
if (track.rotation_track.values.size()) { if (track.rotation_track.values.size()) {
Quaternion base_rot = state->nodes[track_i.key]->rotation.normalized(); Quat base_rot = state->nodes[track_i.key]->rotation.normalized();
bool not_default = false; //discard the track if all it contains is default values bool not_default = false; //discard the track if all it contains is default values
for (int i = 0; i < track.rotation_track.times.size(); i++) { for (int i = 0; i < track.rotation_track.times.size(); i++) {
Quaternion value = track.rotation_track.values[track.rotation_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i].normalized(); Quat value = track.rotation_track.values[track.rotation_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i].normalized();
if (!value.is_equal_approx(base_rot)) { if (!value.is_equal_approx(base_rot)) {
not_default = true; not_default = true;
break; break;
@ -5939,7 +5939,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap,
double time = 0.0; double time = 0.0;
Vector3 base_pos; Vector3 base_pos;
Quaternion base_rot; Quat base_rot;
Vector3 base_scale = Vector3(1, 1, 1); Vector3 base_scale = Vector3(1, 1, 1);
//TODO REMOVE: //TODO REMOVE:
@ -5973,7 +5973,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap,
bool last = false; bool last = false;
while (true) { while (true) {
Vector3 pos = base_pos; Vector3 pos = base_pos;
Quaternion rot = base_rot; Quat rot = base_rot;
Vector3 scale = base_scale; Vector3 scale = base_scale;
//TODO DELETE //TODO DELETE
@ -5982,7 +5982,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap,
} }
if (track.rotation_track.times.size()) { if (track.rotation_track.times.size()) {
rot = _interpolate_track<Quaternion>(track.rotation_track.times, track.rotation_track.values, time, track.rotation_track.interpolation); rot = _interpolate_track<Quat>(track.rotation_track.times, track.rotation_track.values, time, track.rotation_track.interpolation);
} }
if (track.scale_track.times.size()) { if (track.scale_track.times.size()) {
@ -5997,7 +5997,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap,
} }
if (rotation_idx >= 0) { if (rotation_idx >= 0) {
rot = _interpolate_track<Quaternion>(track.rotation_track.times, track.rotation_track.values, time, track.rotation_track.interpolation); rot = _interpolate_track<Quat>(track.rotation_track.times, track.rotation_track.values, time, track.rotation_track.interpolation);
animation->rotation_track_insert_key(rotation_idx, time, rot); animation->rotation_track_insert_key(rotation_idx, time, rot);
} }
@ -6089,7 +6089,7 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) {
if (!mi) { if (!mi) {
continue; continue;
} }
Transform3D mi_xform = mi->get_transform(); Transform mi_xform = mi->get_transform();
node->scale = mi_xform.basis.get_scale(); node->scale = mi_xform.basis.get_scale();
node->rotation = mi_xform.basis.get_rotation_quaternion(); node->rotation = mi_xform.basis.get_rotation_quaternion();
node->position = mi_xform.origin; node->position = mi_xform.origin;
@ -6148,7 +6148,7 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) {
} }
for (int bind_i = 0, cnt = skin->get_bind_count(); bind_i < cnt; bind_i++) { for (int bind_i = 0, cnt = skin->get_bind_count(); bind_i < cnt; bind_i++) {
int bone_i = skin->get_bind_bone(bind_i); int bone_i = skin->get_bind_bone(bind_i);
Transform3D bind_pose = skin->get_bind_pose(bind_i); Transform bind_pose = skin->get_bind_pose(bind_i);
StringName bind_name = skin->get_bind_name(bind_i); StringName bind_name = skin->get_bind_name(bind_i);
if (bind_name != StringName()) { if (bind_name != StringName()) {
bone_i = bone_name_to_idx[bind_name]; bone_i = bone_name_to_idx[bind_name];
@ -6232,13 +6232,13 @@ void GLTFDocument::_process_mesh_instances(Ref<GLTFState> state, Node *scene_roo
mi->set_skin(state->skins.write[skin_i]->godot_skin); mi->set_skin(state->skins.write[skin_i]->godot_skin);
mi->set_skeleton_path(mi->get_path_to(skeleton)); mi->set_skeleton_path(mi->get_path_to(skeleton));
mi->set_transform(Transform3D()); mi->set_transform(Transform());
} }
} }
} }
//TODO DELETE //TODO DELETE
GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state, GLTFAnimation::Track p_track, Ref<Animation> p_animation, Transform3D p_bone_rest, int32_t p_track_i, GLTFNodeIndex p_node_i) { GLTFAnimation::Track GLTFDocument::_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) {
Animation::InterpolationType interpolation = p_animation->track_get_interpolation_type(p_track_i); Animation::InterpolationType interpolation = p_animation->track_get_interpolation_type(p_track_i);
GLTFAnimation::Interpolation gltf_interpolation = GLTFAnimation::INTERP_LINEAR; GLTFAnimation::Interpolation gltf_interpolation = GLTFAnimation::INTERP_LINEAR;
@ -6275,11 +6275,11 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state
p_track.rotation_track.interpolation = gltf_interpolation; p_track.rotation_track.interpolation = gltf_interpolation;
for (int32_t key_i = 0; key_i < key_count; key_i++) { for (int32_t key_i = 0; key_i < key_count; key_i++) {
Vector3 position; Vector3 position;
Quaternion rotation; Quat rotation;
Vector3 scale; Vector3 scale;
Error err = p_animation->transform_track_get_key(p_track_i, key_i, &position, &rotation, &scale); Error err = p_animation->transform_track_get_key(p_track_i, key_i, &position, &rotation, &scale);
ERR_CONTINUE(err != OK); ERR_CONTINUE(err != OK);
Transform3D xform; Transform xform;
xform.basis.set_quaternion_scale(rotation, scale); xform.basis.set_quaternion_scale(rotation, scale);
xform.origin = position; xform.origin = position;
xform = p_bone_rest * xform; xform = p_bone_rest * xform;
@ -6302,7 +6302,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state
p_track.rotation_track.values.resize(key_count); p_track.rotation_track.values.resize(key_count);
p_track.rotation_track.interpolation = gltf_interpolation; p_track.rotation_track.interpolation = gltf_interpolation;
for (int32_t key_i = 0; key_i < key_count; key_i++) { for (int32_t key_i = 0; key_i < key_count; key_i++) {
Transform3D xform = p_animation->track_get_key_value(p_track_i, key_i); Transform xform = p_animation->track_get_key_value(p_track_i, key_i);
p_track.position_track.values.write[key_i] = xform.get_origin(); p_track.position_track.values.write[key_i] = xform.get_origin();
p_track.rotation_track.values.write[key_i] = xform.basis.get_rotation_quaternion(); p_track.rotation_track.values.write[key_i] = xform.basis.get_rotation_quaternion();
p_track.scale_track.values.write[key_i] = xform.basis.get_scale(); p_track.scale_track.values.write[key_i] = xform.basis.get_scale();
@ -6316,7 +6316,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state
p_track.rotation_track.interpolation = gltf_interpolation; p_track.rotation_track.interpolation = gltf_interpolation;
for (int32_t key_i = 0; key_i < key_count; key_i++) { for (int32_t key_i = 0; key_i < key_count; key_i++) {
Quaternion rotation_track = p_animation->track_get_key_value(p_track_i, key_i); Quat rotation_track = p_animation->track_get_key_value(p_track_i, key_i);
p_track.rotation_track.values.write[key_i] = rotation_track; p_track.rotation_track.values.write[key_i] = rotation_track;
} }
} else if (path.find(":position") != -1) { } else if (path.find(":position") != -1) {
@ -6339,7 +6339,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state
for (int32_t key_i = 0; key_i < key_count; key_i++) { for (int32_t key_i = 0; key_i < key_count; key_i++) {
Vector3 rotation_radian = p_animation->track_get_key_value(p_track_i, key_i); Vector3 rotation_radian = p_animation->track_get_key_value(p_track_i, key_i);
p_track.rotation_track.values.write[key_i] = Quaternion(rotation_radian); p_track.rotation_track.values.write[key_i] = Quat(rotation_radian);
} }
} else if (path.find(":scale") != -1) { } else if (path.find(":scale") != -1) {
p_track.scale_track.times = times; p_track.scale_track.times = times;
@ -6468,7 +6468,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state
p_track.rotation_track.interpolation = gltf_interpolation; p_track.rotation_track.interpolation = gltf_interpolation;
p_track.rotation_track.values.resize(key_count); p_track.rotation_track.values.resize(key_count);
for (int32_t key_i = 0; key_i < key_count; key_i++) { for (int32_t key_i = 0; key_i < key_count; key_i++) {
Quaternion rotation; Quat rotation;
Error err = p_animation->rotation_track_get_key(p_track_i, key_i, &rotation); Error err = p_animation->rotation_track_get_key(p_track_i, key_i, &rotation);
ERR_CONTINUE(err != OK); ERR_CONTINUE(err != OK);
p_track.rotation_track.values.write[key_i] = rotation; p_track.rotation_track.values.write[key_i] = rotation;
@ -6494,7 +6494,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state
for (int32_t key_i = 0; key_i < key_count; key_i++) { for (int32_t key_i = 0; key_i < key_count; key_i++) {
Vector3 rotation_radian = p_animation->track_get_key_value(p_track_i, key_i); Vector3 rotation_radian = p_animation->track_get_key_value(p_track_i, key_i);
p_track.rotation_track.values.write[key_i] = Quaternion(rotation_radian); p_track.rotation_track.values.write[key_i] = Quat(rotation_radian);
} }
} else if (path.contains(":scale")) { } else if (path.contains(":scale")) {
p_track.scale_track.times = times; p_track.scale_track.times = times;
@ -6831,7 +6831,7 @@ Dictionary _serialize_texture_transform_uv(Vector2 p_offset, Vector2 p_scale) {
return extension; return extension;
} }
Dictionary GLTFDocument::_serialize_texture_transform_uv1(Ref<BaseMaterial3D> p_material) { Dictionary GLTFDocument::_serialize_texture_transform_uv1(Ref<SpatialMaterial> p_material) {
if (p_material.is_valid()) { if (p_material.is_valid()) {
Vector3 offset = p_material->get_uv1_offset(); Vector3 offset = p_material->get_uv1_offset();
Vector3 scale = p_material->get_uv1_scale(); Vector3 scale = p_material->get_uv1_scale();
@ -6840,7 +6840,7 @@ Dictionary GLTFDocument::_serialize_texture_transform_uv1(Ref<BaseMaterial3D> p_
return Dictionary(); return Dictionary();
} }
Dictionary GLTFDocument::_serialize_texture_transform_uv2(Ref<BaseMaterial3D> p_material) { Dictionary GLTFDocument::_serialize_texture_transform_uv2(Ref<SpatialMaterial> p_material) {
if (p_material.is_valid()) { if (p_material.is_valid()) {
Vector3 offset = p_material->get_uv2_offset(); Vector3 offset = p_material->get_uv2_offset();
Vector3 scale = p_material->get_uv2_scale(); Vector3 scale = p_material->get_uv2_scale();

View File

@ -35,14 +35,14 @@
#include "structures/gltf_animation.h" #include "structures/gltf_animation.h"
#include "scene/3d/bone_attachment.h" #include "scene/3d/bone_attachment.h"
#include "scene/3d/importer_mesh_instance.h" #include "scene/3d/importer_mesh_instance_3d.h"
#include "scene/3d/mesh_instance.h" #include "scene/3d/mesh_instance.h"
#include "scene/animation/animation_player.h" #include "scene/animation/animation_player.h"
#include "scene/resources/material.h" #include "scene/resources/material.h"
class GLTFDocument : public Resource { class GLTFDocument : public Resource {
GDCLASS(GLTFDocument, Resource); GDCLASS(GLTFDocument, Resource);
TypedArray<GLTFDocumentExtension> document_extensions; Vector<GLTFDocumentExtension> document_extensions;
private: private:
const float BAKE_FPS = 30.0f; const float BAKE_FPS = 30.0f;
@ -93,8 +93,8 @@ private:
String _gen_unique_bone_name(Ref<GLTFState> state, String _gen_unique_bone_name(Ref<GLTFState> state,
const GLTFSkeletonIndex skel_i, const GLTFSkeletonIndex skel_i,
const String &p_name); const String &p_name);
GLTFTextureIndex _set_texture(Ref<GLTFState> state, Ref<Texture2D> p_texture); GLTFTextureIndex _set_texture(Ref<GLTFState> state, Ref<Texture> p_texture);
Ref<Texture2D> _get_texture(Ref<GLTFState> state, Ref<Texture> _get_texture(Ref<GLTFState> state,
const GLTFTextureIndex p_texture); const GLTFTextureIndex p_texture);
Error _parse_json(const String &p_path, Ref<GLTFState> state); Error _parse_json(const String &p_path, Ref<GLTFState> state);
Error _parse_glb(FileAccess *f, Ref<GLTFState> state); Error _parse_glb(FileAccess *f, Ref<GLTFState> state);
@ -129,7 +129,7 @@ private:
Vector<Color> _decode_accessor_as_color(Ref<GLTFState> state, Vector<Color> _decode_accessor_as_color(Ref<GLTFState> state,
const GLTFAccessorIndex p_accessor, const GLTFAccessorIndex p_accessor,
const bool p_for_vertex); const bool p_for_vertex);
Vector<Quaternion> _decode_accessor_as_quaternion(Ref<GLTFState> state, Vector<Quat> _decode_accessor_as_quaternion(Ref<GLTFState> state,
const GLTFAccessorIndex p_accessor, const GLTFAccessorIndex p_accessor,
const bool p_for_vertex); const bool p_for_vertex);
Vector<Transform2D> _decode_accessor_as_xform2d(Ref<GLTFState> state, Vector<Transform2D> _decode_accessor_as_xform2d(Ref<GLTFState> state,
@ -138,7 +138,7 @@ private:
Vector<Basis> _decode_accessor_as_basis(Ref<GLTFState> state, Vector<Basis> _decode_accessor_as_basis(Ref<GLTFState> state,
const GLTFAccessorIndex p_accessor, const GLTFAccessorIndex p_accessor,
const bool p_for_vertex); const bool p_for_vertex);
Vector<Transform3D> _decode_accessor_as_xform(Ref<GLTFState> state, Vector<Transform> _decode_accessor_as_xform(Ref<GLTFState> state,
const GLTFAccessorIndex p_accessor, const GLTFAccessorIndex p_accessor,
const bool p_for_vertex); const bool p_for_vertex);
Error _parse_meshes(Ref<GLTFState> state); Error _parse_meshes(Ref<GLTFState> state);
@ -148,9 +148,9 @@ private:
Error _parse_images(Ref<GLTFState> state, const String &p_base_path); Error _parse_images(Ref<GLTFState> state, const String &p_base_path);
Error _parse_textures(Ref<GLTFState> state); Error _parse_textures(Ref<GLTFState> state);
Error _parse_materials(Ref<GLTFState> state); Error _parse_materials(Ref<GLTFState> state);
void _set_texture_transform_uv1(const Dictionary &d, Ref<BaseMaterial3D> material); void _set_texture_transform_uv1(const Dictionary &d, Ref<SpatialMaterial> material);
void spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss, void spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss,
Ref<BaseMaterial3D> p_material); Ref<SpatialMaterial> p_material);
static void spec_gloss_to_metal_base_color(const Color &p_specular_factor, static void spec_gloss_to_metal_base_color(const Color &p_specular_factor,
const Color &p_diffuse, const Color &p_diffuse,
Color &r_base_color, Color &r_base_color,
@ -194,7 +194,7 @@ private:
const float p_time, const float p_time,
const GLTFAnimation::Interpolation p_interp); const GLTFAnimation::Interpolation p_interp);
GLTFAccessorIndex _encode_accessor_as_quaternions(Ref<GLTFState> state, GLTFAccessorIndex _encode_accessor_as_quaternions(Ref<GLTFState> state,
const Vector<Quaternion> p_attribs, const Vector<Quat> p_attribs,
const bool p_for_vertex); const bool p_for_vertex);
GLTFAccessorIndex _encode_accessor_as_weights(Ref<GLTFState> state, GLTFAccessorIndex _encode_accessor_as_weights(Ref<GLTFState> state,
const Vector<Color> p_attribs, const Vector<Color> p_attribs,
@ -237,7 +237,7 @@ private:
const Vector<int32_t> p_attribs, const Vector<int32_t> p_attribs,
const bool p_for_vertex); const bool p_for_vertex);
GLTFAccessorIndex _encode_accessor_as_xform(Ref<GLTFState> state, GLTFAccessorIndex _encode_accessor_as_xform(Ref<GLTFState> state,
const Vector<Transform3D> p_attribs, const Vector<Transform> p_attribs,
const bool p_for_vertex); const bool p_for_vertex);
Error _encode_buffer_view(Ref<GLTFState> state, const double *src, Error _encode_buffer_view(Ref<GLTFState> state, const double *src,
const int count, const GLTFType type, const int count, const GLTFType type,
@ -259,8 +259,8 @@ private:
Error _encode_buffer_bins(Ref<GLTFState> state, const String &p_path); Error _encode_buffer_bins(Ref<GLTFState> state, const String &p_path);
Error _encode_buffer_glb(Ref<GLTFState> state, const String &p_path); Error _encode_buffer_glb(Ref<GLTFState> state, const String &p_path);
PackedByteArray _serialize_glb_buffer(Ref<GLTFState> state, Error *r_err); PackedByteArray _serialize_glb_buffer(Ref<GLTFState> state, Error *r_err);
Dictionary _serialize_texture_transform_uv1(Ref<BaseMaterial3D> p_material); Dictionary _serialize_texture_transform_uv1(Ref<SpatialMaterial> p_material);
Dictionary _serialize_texture_transform_uv2(Ref<BaseMaterial3D> p_material); Dictionary _serialize_texture_transform_uv2(Ref<SpatialMaterial> p_material);
Error _serialize_version(Ref<GLTFState> state); Error _serialize_version(Ref<GLTFState> state);
Error _serialize_file(Ref<GLTFState> state, const String p_path); Error _serialize_file(Ref<GLTFState> state, const String p_path);
Error _serialize_extensions(Ref<GLTFState> state) const; Error _serialize_extensions(Ref<GLTFState> state) const;

View File

@ -32,7 +32,7 @@
#include "gltf_state.h" #include "gltf_state.h"
#include "core/error/error_macros.h" #include "core/error_macros.h"
#include "scene/3d/mesh_instance.h" #include "scene/3d/mesh_instance.h"
#include "scene/resources/importer_mesh.h" #include "scene/resources/importer_mesh.h"

View File

@ -96,7 +96,7 @@ void GLTFState::_bind_methods() {
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::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, "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::STRING, "base_path"), "set_base_path", "get_base_path"); // String
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "root_nodes"), "set_root_nodes", "get_root_nodes"); // Vector<int> ADD_PROPERTY(PropertyInfo(Variant::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, "textures", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_textures", "get_textures"); // Vector<Ref<GLTFTexture>>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "images", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_images", "get_images"); // Vector<Ref<Texture> ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "images", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_images", "get_images"); // Vector<Ref<Texture>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "skins", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skins", "get_skins"); // Vector<Ref<GLTFSkin>> ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "skins", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skins", "get_skins"); // Vector<Ref<GLTFSkin>>

View File

@ -70,13 +70,13 @@ class GLTFState : public Resource {
Vector<Ref<GLTFMesh>> meshes; // meshes are loaded directly, no reason not to. Vector<Ref<GLTFMesh>> meshes; // meshes are loaded directly, no reason not to.
Vector<AnimationPlayer *> animation_players; Vector<AnimationPlayer *> animation_players;
HashMap<Ref<BaseMaterial3D>, GLTFMaterialIndex> material_cache; HashMap<Ref<SpatialMaterial>, GLTFMaterialIndex> material_cache;
Vector<Ref<BaseMaterial3D>> materials; Vector<Ref<SpatialMaterial>> materials;
String scene_name; String scene_name;
Vector<int> root_nodes; Vector<int> root_nodes;
Vector<Ref<GLTFTexture>> textures; Vector<Ref<GLTFTexture>> textures;
Vector<Ref<Texture2D>> images; Vector<Ref<Texture>> images;
Vector<Ref<GLTFSkin>> skins; Vector<Ref<GLTFSkin>> skins;
Vector<Ref<GLTFCamera>> cameras; Vector<Ref<GLTFCamera>> cameras;

View File

@ -56,7 +56,7 @@ public:
struct Track { struct Track {
Channel<Vector3> position_track; Channel<Vector3> position_track;
Channel<Quaternion> rotation_track; Channel<Quat> rotation_track;
Channel<Vector3> scale_track; Channel<Vector3> scale_track;
Vector<Channel<real_t>> weight_tracks; Vector<Channel<real_t>> weight_tracks;
}; };

View File

@ -41,7 +41,7 @@ void GLTFCamera::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_depth_near", "zdepth_near"), &GLTFCamera::set_depth_near); ClassDB::bind_method(D_METHOD("set_depth_near", "zdepth_near"), &GLTFCamera::set_depth_near);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "perspective"), "set_perspective", "get_perspective"); // bool ADD_PROPERTY(PropertyInfo(Variant::BOOL, "perspective"), "set_perspective", "get_perspective"); // bool
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fov_size"), "set_fov_size", "get_fov_size"); // float ADD_PROPERTY(PropertyInfo(Variant::REAL, "fov_size"), "set_fov_size", "get_fov_size"); // float
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth_far"), "set_depth_far", "get_depth_far"); // float ADD_PROPERTY(PropertyInfo(Variant::REAL, "depth_far"), "set_depth_far", "get_depth_far"); // float
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth_near"), "set_depth_near", "get_depth_near"); // float ADD_PROPERTY(PropertyInfo(Variant::REAL, "depth_near"), "set_depth_near", "get_depth_near"); // float
} }

View File

@ -60,16 +60,16 @@ void GLTFNode::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "parent"), "set_parent", "get_parent"); // GLTFNodeIndex ADD_PROPERTY(PropertyInfo(Variant::INT, "parent"), "set_parent", "get_parent"); // GLTFNodeIndex
ADD_PROPERTY(PropertyInfo(Variant::INT, "height"), "set_height", "get_height"); // int ADD_PROPERTY(PropertyInfo(Variant::INT, "height"), "set_height", "get_height"); // int
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "xform"), "set_xform", "get_xform"); // Transform3D ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "xform"), "set_xform", "get_xform"); // Transform
ADD_PROPERTY(PropertyInfo(Variant::INT, "mesh"), "set_mesh", "get_mesh"); // GLTFMeshIndex ADD_PROPERTY(PropertyInfo(Variant::INT, "mesh"), "set_mesh", "get_mesh"); // GLTFMeshIndex
ADD_PROPERTY(PropertyInfo(Variant::INT, "camera"), "set_camera", "get_camera"); // GLTFCameraIndex ADD_PROPERTY(PropertyInfo(Variant::INT, "camera"), "set_camera", "get_camera"); // GLTFCameraIndex
ADD_PROPERTY(PropertyInfo(Variant::INT, "skin"), "set_skin", "get_skin"); // GLTFSkinIndex 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::INT, "skeleton"), "set_skeleton", "get_skeleton"); // GLTFSkeletonIndex
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "joint"), "set_joint", "get_joint"); // bool 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, "position"), "set_position", "get_position"); // Vector3
ADD_PROPERTY(PropertyInfo(Variant::QUATERNION, "rotation"), "set_rotation", "get_rotation"); // Quaternion 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::VECTOR3, "scale"), "set_scale", "get_scale"); // Vector3
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "children"), "set_children", "get_children"); // Vector<int> ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "children"), "set_children", "get_children"); // Vector<int>
ADD_PROPERTY(PropertyInfo(Variant::INT, "light"), "set_light", "get_light"); // GLTFLightIndex ADD_PROPERTY(PropertyInfo(Variant::INT, "light"), "set_light", "get_light"); // GLTFLightIndex
} }
@ -89,11 +89,11 @@ void GLTFNode::set_height(int p_height) {
height = p_height; height = p_height;
} }
Transform3D GLTFNode::get_xform() { Transform GLTFNode::get_xform() {
return xform; return xform;
} }
void GLTFNode::set_xform(Transform3D p_xform) { void GLTFNode::set_xform(Transform p_xform) {
xform = p_xform; xform = p_xform;
} }
@ -145,11 +145,11 @@ void GLTFNode::set_position(Vector3 p_position) {
position = p_position; position = p_position;
} }
Quaternion GLTFNode::get_rotation() { Quat GLTFNode::get_rotation() {
return rotation; return rotation;
} }
void GLTFNode::set_rotation(Quaternion p_rotation) { void GLTFNode::set_rotation(Quat p_rotation) {
rotation = p_rotation; rotation = p_rotation;
} }

View File

@ -42,14 +42,14 @@ private:
// matrices need to be transformed to this // matrices need to be transformed to this
GLTFNodeIndex parent = -1; GLTFNodeIndex parent = -1;
int height = -1; int height = -1;
Transform3D xform; Transform xform;
GLTFMeshIndex mesh = -1; GLTFMeshIndex mesh = -1;
GLTFCameraIndex camera = -1; GLTFCameraIndex camera = -1;
GLTFSkinIndex skin = -1; GLTFSkinIndex skin = -1;
GLTFSkeletonIndex skeleton = -1; GLTFSkeletonIndex skeleton = -1;
bool joint = false; bool joint = false;
Vector3 position; Vector3 position;
Quaternion rotation; Quat rotation;
Vector3 scale = Vector3(1, 1, 1); Vector3 scale = Vector3(1, 1, 1);
Vector<int> children; Vector<int> children;
GLTFLightIndex light = -1; GLTFLightIndex light = -1;
@ -64,8 +64,8 @@ public:
int get_height(); int get_height();
void set_height(int p_height); void set_height(int p_height);
Transform3D get_xform(); Transform get_xform();
void set_xform(Transform3D p_xform); void set_xform(Transform p_xform);
GLTFMeshIndex get_mesh(); GLTFMeshIndex get_mesh();
void set_mesh(GLTFMeshIndex p_mesh); void set_mesh(GLTFMeshIndex p_mesh);
@ -85,8 +85,8 @@ public:
Vector3 get_position(); Vector3 get_position();
void set_position(Vector3 p_position); void set_position(Vector3 p_position);
Quaternion get_rotation(); Quat get_rotation();
void set_rotation(Quaternion p_rotation); void set_rotation(Quat p_rotation);
Vector3 get_scale(); Vector3 get_scale();
void set_scale(Vector3 p_scale); void set_scale(Vector3 p_scale);

View File

@ -46,8 +46,8 @@ void GLTFSkeleton::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_bone_attachment_count"), &GLTFSkeleton::get_bone_attachment_count); 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); ClassDB::bind_method(D_METHOD("get_bone_attachment", "idx"), &GLTFSkeleton::get_bone_attachment);
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "joints"), "set_joints", "get_joints"); // Vector<GLTFNodeIndex> ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "joints"), "set_joints", "get_joints"); // Vector<GLTFNodeIndex>
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "roots"), "set_roots", "get_roots"); // Vector<GLTFNodeIndex> ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "roots"), "set_roots", "get_roots"); // Vector<GLTFNodeIndex>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "unique_names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_unique_names", "get_unique_names"); // Set<String> ADD_PROPERTY(PropertyInfo(Variant::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, "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,
} }

View File

@ -56,11 +56,11 @@ void GLTFSkin::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_godot_skin", "godot_skin"), &GLTFSkin::set_godot_skin); ClassDB::bind_method(D_METHOD("set_godot_skin", "godot_skin"), &GLTFSkin::set_godot_skin);
ADD_PROPERTY(PropertyInfo(Variant::INT, "skin_root"), "set_skin_root", "get_skin_root"); // GLTFNodeIndex ADD_PROPERTY(PropertyInfo(Variant::INT, "skin_root"), "set_skin_root", "get_skin_root"); // GLTFNodeIndex
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "joints_original"), "set_joints_original", "get_joints_original"); // Vector<GLTFNodeIndex> ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "joints_original"), "set_joints_original", "get_joints_original"); // Vector<GLTFNodeIndex>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "inverse_binds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_inverse_binds", "get_inverse_binds"); // Vector<Transform3D> ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "inverse_binds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_inverse_binds", "get_inverse_binds"); // Vector<Transform>
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "joints"), "set_joints", "get_joints"); // Vector<GLTFNodeIndex> ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "joints"), "set_joints", "get_joints"); // Vector<GLTFNodeIndex>
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "non_joints"), "set_non_joints", "get_non_joints"); // Vector<GLTFNodeIndex> ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "non_joints"), "set_non_joints", "get_non_joints"); // Vector<GLTFNodeIndex>
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "roots"), "set_roots", "get_roots"); // Vector<GLTFNodeIndex> ADD_PROPERTY(PropertyInfo(Variant::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::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_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::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,

View File

@ -43,7 +43,7 @@ private:
GLTFNodeIndex skin_root = -1; GLTFNodeIndex skin_root = -1;
Vector<GLTFNodeIndex> joints_original; Vector<GLTFNodeIndex> joints_original;
Vector<Transform3D> inverse_binds; Vector<Transform> inverse_binds;
// Note: joints + non_joints should form a complete subtree, or subtrees // Note: joints + non_joints should form a complete subtree, or subtrees
// with a common parent // with a common parent