mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-03 01:19:38 +01:00
GLTF: Only list used extensions when they're actually used
This commit is contained in:
parent
aae204935b
commit
13b8c888a0
@ -217,15 +217,21 @@ Error GLTFDocument::serialize(Ref<GLTFState> state, Node *p_root, const String &
|
|||||||
}
|
}
|
||||||
|
|
||||||
Error GLTFDocument::_serialize_extensions(Ref<GLTFState> state) const {
|
Error GLTFDocument::_serialize_extensions(Ref<GLTFState> state) const {
|
||||||
const String texture_transform = "KHR_texture_transform";
|
|
||||||
const String punctual_lights = "KHR_lights_punctual";
|
|
||||||
Array extensions_used;
|
Array extensions_used;
|
||||||
extensions_used.push_back(punctual_lights);
|
|
||||||
extensions_used.push_back(texture_transform);
|
|
||||||
state->json["extensionsUsed"] = extensions_used;
|
|
||||||
Array extensions_required;
|
Array extensions_required;
|
||||||
extensions_required.push_back(texture_transform);
|
if (!state->lights.empty()) {
|
||||||
state->json["extensionsRequired"] = extensions_required;
|
extensions_used.push_back("KHR_lights_punctual");
|
||||||
|
}
|
||||||
|
if (state->use_khr_texture_transform) {
|
||||||
|
extensions_used.push_back("KHR_texture_transform");
|
||||||
|
extensions_required.push_back("KHR_texture_transform");
|
||||||
|
}
|
||||||
|
if (!extensions_used.empty()) {
|
||||||
|
state->json["extensionsUsed"] = extensions_used;
|
||||||
|
}
|
||||||
|
if (!extensions_required.empty()) {
|
||||||
|
state->json["extensionsRequired"] = extensions_required;
|
||||||
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3388,7 +3394,11 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
|
|||||||
}
|
}
|
||||||
if (gltf_texture_index != -1) {
|
if (gltf_texture_index != -1) {
|
||||||
bct["index"] = gltf_texture_index;
|
bct["index"] = gltf_texture_index;
|
||||||
bct["extensions"] = _serialize_texture_transform_uv1(material);
|
Dictionary extensions = _serialize_texture_transform_uv1(material);
|
||||||
|
if (!extensions.empty()) {
|
||||||
|
bct["extensions"] = extensions;
|
||||||
|
state->use_khr_texture_transform = true;
|
||||||
|
}
|
||||||
mr["baseColorTexture"] = bct;
|
mr["baseColorTexture"] = bct;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3527,7 +3537,11 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
|
|||||||
}
|
}
|
||||||
if (has_roughness || has_metalness) {
|
if (has_roughness || has_metalness) {
|
||||||
mrt["index"] = orm_texture_index;
|
mrt["index"] = orm_texture_index;
|
||||||
mrt["extensions"] = _serialize_texture_transform_uv1(material);
|
Dictionary extensions = _serialize_texture_transform_uv1(material);
|
||||||
|
if (!extensions.empty()) {
|
||||||
|
mrt["extensions"] = extensions;
|
||||||
|
state->use_khr_texture_transform = true;
|
||||||
|
}
|
||||||
mr["metallicRoughnessTexture"] = mrt;
|
mr["metallicRoughnessTexture"] = mrt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4647,6 +4661,9 @@ void GLTFDocument::_remove_duplicate_skins(Ref<GLTFState> state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Error GLTFDocument::_serialize_lights(Ref<GLTFState> state) {
|
Error GLTFDocument::_serialize_lights(Ref<GLTFState> state) {
|
||||||
|
if (state->lights.empty()) {
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
Array lights;
|
Array lights;
|
||||||
for (GLTFLightIndex i = 0; i < state->lights.size(); i++) {
|
for (GLTFLightIndex i = 0; i < state->lights.size(); i++) {
|
||||||
Dictionary d;
|
Dictionary d;
|
||||||
@ -4673,10 +4690,6 @@ Error GLTFDocument::_serialize_lights(Ref<GLTFState> state) {
|
|||||||
lights.push_back(d);
|
lights.push_back(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state->lights.size()) {
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
Dictionary extensions;
|
Dictionary extensions;
|
||||||
if (state->json.has("extensions")) {
|
if (state->json.has("extensions")) {
|
||||||
extensions = state->json["extensions"];
|
extensions = state->json["extensions"];
|
||||||
@ -6903,45 +6916,48 @@ Error GLTFDocument::parse(Ref<GLTFState> state, String p_path, bool p_read_binar
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary GLTFDocument::_serialize_texture_transform_uv2(Ref<SpatialMaterial> p_material) {
|
Dictionary _serialize_texture_transform_uv(Vector2 p_offset, Vector2 p_scale) {
|
||||||
Dictionary extension;
|
Dictionary texture_transform;
|
||||||
Ref<SpatialMaterial> mat = p_material;
|
bool is_offset = p_offset != Vector2(0.0, 0.0);
|
||||||
if (mat.is_valid()) {
|
if (is_offset) {
|
||||||
Dictionary texture_transform;
|
|
||||||
Array offset;
|
Array offset;
|
||||||
offset.resize(2);
|
offset.resize(2);
|
||||||
offset[0] = mat->get_uv2_offset().x;
|
offset[0] = p_offset.x;
|
||||||
offset[1] = mat->get_uv2_offset().y;
|
offset[1] = p_offset.y;
|
||||||
texture_transform["offset"] = offset;
|
texture_transform["offset"] = offset;
|
||||||
|
}
|
||||||
|
bool is_scaled = p_scale != Vector2(1.0, 1.0);
|
||||||
|
if (is_scaled) {
|
||||||
Array scale;
|
Array scale;
|
||||||
scale.resize(2);
|
scale.resize(2);
|
||||||
scale[0] = mat->get_uv2_scale().x;
|
scale[0] = p_scale.x;
|
||||||
scale[1] = mat->get_uv2_scale().y;
|
scale[1] = p_scale.y;
|
||||||
texture_transform["scale"] = scale;
|
texture_transform["scale"] = scale;
|
||||||
// Pandemonium doesn't support texture rotation
|
}
|
||||||
|
Dictionary extension;
|
||||||
|
// Note: Godot doesn't support texture rotation.
|
||||||
|
if (is_offset || is_scaled) {
|
||||||
extension["KHR_texture_transform"] = texture_transform;
|
extension["KHR_texture_transform"] = texture_transform;
|
||||||
}
|
}
|
||||||
return extension;
|
return extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary GLTFDocument::_serialize_texture_transform_uv1(Ref<SpatialMaterial> p_material) {
|
Dictionary GLTFDocument::_serialize_texture_transform_uv1(Ref<SpatialMaterial> p_material) {
|
||||||
Dictionary extension;
|
|
||||||
if (p_material.is_valid()) {
|
if (p_material.is_valid()) {
|
||||||
Dictionary texture_transform;
|
Vector3 offset = p_material->get_uv1_offset();
|
||||||
Array offset;
|
Vector3 scale = p_material->get_uv1_scale();
|
||||||
offset.resize(2);
|
return _serialize_texture_transform_uv(Vector2(offset.x, offset.y), Vector2(scale.x, scale.y));
|
||||||
offset[0] = p_material->get_uv1_offset().x;
|
|
||||||
offset[1] = p_material->get_uv1_offset().y;
|
|
||||||
texture_transform["offset"] = offset;
|
|
||||||
Array scale;
|
|
||||||
scale.resize(2);
|
|
||||||
scale[0] = p_material->get_uv1_scale().x;
|
|
||||||
scale[1] = p_material->get_uv1_scale().y;
|
|
||||||
texture_transform["scale"] = scale;
|
|
||||||
// Pandemonium doesn't support texture rotation
|
|
||||||
extension["KHR_texture_transform"] = texture_transform;
|
|
||||||
}
|
}
|
||||||
return extension;
|
return Dictionary();
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary GLTFDocument::_serialize_texture_transform_uv2(Ref<SpatialMaterial> p_material) {
|
||||||
|
if (p_material.is_valid()) {
|
||||||
|
Vector3 offset = p_material->get_uv2_offset();
|
||||||
|
Vector3 scale = p_material->get_uv2_scale();
|
||||||
|
return _serialize_texture_transform_uv(Vector2(offset.x, offset.y), Vector2(scale.x, scale.y));
|
||||||
|
}
|
||||||
|
return Dictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Error GLTFDocument::_serialize_version(Ref<GLTFState> state) {
|
Error GLTFDocument::_serialize_version(Ref<GLTFState> state) {
|
||||||
|
@ -63,6 +63,7 @@ class GLTFState : public Resource {
|
|||||||
Vector<uint8_t> glb_data;
|
Vector<uint8_t> glb_data;
|
||||||
|
|
||||||
bool use_named_skin_binds = false;
|
bool use_named_skin_binds = false;
|
||||||
|
bool use_khr_texture_transform = false;
|
||||||
bool use_legacy_names = false;
|
bool use_legacy_names = false;
|
||||||
uint32_t compress_flags = 0;
|
uint32_t compress_flags = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user