GLTF: Support 64-bit sizes in glTF import and export

This commit is contained in:
Aaron Franke 2025-05-08 19:18:39 -07:00
parent 5dd76968d8
commit 61ff5f1bdd
No known key found for this signature in database
GPG key ID: 40A1750B977E56BF
10 changed files with 462 additions and 255 deletions

View file

@ -0,0 +1,124 @@
/**************************************************************************/
/* gltf_accessor.compat.inc */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef DISABLE_DEPRECATED
// 32-bit versions for compatibility.
GLTFBufferViewIndex GLTFAccessor::_get_buffer_view_bind_compat_106220() {
return get_buffer_view();
}
int GLTFAccessor::_get_byte_offset_bind_compat_106220() {
return get_byte_offset();
}
int GLTFAccessor::_get_component_type_bind_compat_106220() {
return (int)get_component_type();
}
void GLTFAccessor::_set_component_type_bind_compat_106220(int p_component_type) {
set_component_type((GLTFComponentType)p_component_type);
}
bool GLTFAccessor::_get_normalized_bind_compat_106220() {
return get_normalized();
}
int GLTFAccessor::_get_count_bind_compat_106220() {
return get_count();
}
GLTFAccessor::GLTFAccessorType GLTFAccessor::_get_accessor_type_bind_compat_106220() {
return get_accessor_type();
}
int GLTFAccessor::_get_type_bind_compat_106220() {
return (int)get_accessor_type();
}
Vector<double> GLTFAccessor::_get_min_bind_compat_106220() {
return get_min();
}
Vector<double> GLTFAccessor::_get_max_bind_compat_106220() {
return get_max();
}
int GLTFAccessor::_get_sparse_count_bind_compat_106220() {
return get_sparse_count();
}
int GLTFAccessor::_get_sparse_indices_buffer_view_bind_compat_106220() {
return get_sparse_indices_buffer_view();
}
int GLTFAccessor::_get_sparse_indices_byte_offset_bind_compat_106220() {
return get_sparse_indices_byte_offset();
}
int GLTFAccessor::_get_sparse_indices_component_type_bind_compat_106220() {
return (int)get_sparse_indices_component_type();
}
void GLTFAccessor::_set_sparse_indices_component_type_bind_compat_106220(int p_sparse_indices_component_type) {
set_sparse_indices_component_type((GLTFComponentType)p_sparse_indices_component_type);
}
int GLTFAccessor::_get_sparse_values_buffer_view_bind_compat_106220() {
return get_sparse_values_buffer_view();
}
int GLTFAccessor::_get_sparse_values_byte_offset_bind_compat_106220() {
return get_sparse_values_byte_offset();
}
void GLTFAccessor::_bind_compatibility_methods() {
// 32-bit versions for compatibility.
ClassDB::bind_compatibility_method(D_METHOD("get_buffer_view"), &GLTFAccessor::_get_buffer_view_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_byte_offset"), &GLTFAccessor::_get_byte_offset_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_component_type"), &GLTFAccessor::_get_component_type_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("set_component_type", "component_type"), &GLTFAccessor::_set_component_type_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_normalized"), &GLTFAccessor::_get_normalized_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_count"), &GLTFAccessor::_get_count_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_accessor_type"), &GLTFAccessor::_get_accessor_type_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_type"), &GLTFAccessor::_get_type_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_min"), &GLTFAccessor::_get_min_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_max"), &GLTFAccessor::_get_max_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_sparse_count"), &GLTFAccessor::_get_sparse_count_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_sparse_indices_buffer_view"), &GLTFAccessor::_get_sparse_indices_buffer_view_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_sparse_indices_byte_offset"), &GLTFAccessor::_get_sparse_indices_byte_offset_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_sparse_indices_component_type"), &GLTFAccessor::_get_sparse_indices_component_type_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("set_sparse_indices_component_type", "sparse_indices_component_type"), &GLTFAccessor::_set_sparse_indices_component_type_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_sparse_values_buffer_view"), &GLTFAccessor::_get_sparse_values_buffer_view_bind_compat_106220);
ClassDB::bind_compatibility_method(D_METHOD("get_sparse_values_byte_offset"), &GLTFAccessor::_get_sparse_values_byte_offset_bind_compat_106220);
}
#endif // DISABLE_DEPRECATED

View file

@ -29,6 +29,7 @@
/**************************************************************************/
#include "gltf_accessor.h"
#include "gltf_accessor.compat.inc"
void GLTFAccessor::_bind_methods() {
BIND_ENUM_CONSTANT(TYPE_SCALAR);
@ -100,7 +101,7 @@ void GLTFAccessor::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_values_byte_offset"), "set_sparse_values_byte_offset", "get_sparse_values_byte_offset"); // int
}
GLTFBufferViewIndex GLTFAccessor::get_buffer_view() {
GLTFBufferViewIndex GLTFAccessor::get_buffer_view() const {
return buffer_view;
}
@ -108,23 +109,23 @@ void GLTFAccessor::set_buffer_view(GLTFBufferViewIndex p_buffer_view) {
buffer_view = p_buffer_view;
}
int GLTFAccessor::get_byte_offset() {
int64_t GLTFAccessor::get_byte_offset() const {
return byte_offset;
}
void GLTFAccessor::set_byte_offset(int p_byte_offset) {
void GLTFAccessor::set_byte_offset(int64_t p_byte_offset) {
byte_offset = p_byte_offset;
}
int GLTFAccessor::get_component_type() {
GLTFAccessor::GLTFComponentType GLTFAccessor::get_component_type() const {
return component_type;
}
void GLTFAccessor::set_component_type(int p_component_type) {
void GLTFAccessor::set_component_type(GLTFComponentType p_component_type) {
component_type = (GLTFComponentType)p_component_type;
}
bool GLTFAccessor::get_normalized() {
bool GLTFAccessor::get_normalized() const {
return normalized;
}
@ -132,15 +133,15 @@ void GLTFAccessor::set_normalized(bool p_normalized) {
normalized = p_normalized;
}
int GLTFAccessor::get_count() {
int64_t GLTFAccessor::get_count() const {
return count;
}
void GLTFAccessor::set_count(int p_count) {
void GLTFAccessor::set_count(int64_t p_count) {
count = p_count;
}
GLTFAccessor::GLTFAccessorType GLTFAccessor::get_accessor_type() {
GLTFAccessor::GLTFAccessorType GLTFAccessor::get_accessor_type() const {
return accessor_type;
}
@ -148,7 +149,7 @@ void GLTFAccessor::set_accessor_type(GLTFAccessorType p_accessor_type) {
accessor_type = p_accessor_type;
}
int GLTFAccessor::get_type() {
int GLTFAccessor::get_type() const {
return (int)accessor_type;
}
@ -156,7 +157,7 @@ void GLTFAccessor::set_type(int p_accessor_type) {
accessor_type = (GLTFAccessorType)p_accessor_type; // TODO: Register enum
}
Vector<double> GLTFAccessor::get_min() {
Vector<double> GLTFAccessor::get_min() const {
return min;
}
@ -164,7 +165,7 @@ void GLTFAccessor::set_min(Vector<double> p_min) {
min = p_min;
}
Vector<double> GLTFAccessor::get_max() {
Vector<double> GLTFAccessor::get_max() const {
return max;
}
@ -172,50 +173,50 @@ void GLTFAccessor::set_max(Vector<double> p_max) {
max = p_max;
}
int GLTFAccessor::get_sparse_count() {
int64_t GLTFAccessor::get_sparse_count() const {
return sparse_count;
}
void GLTFAccessor::set_sparse_count(int p_sparse_count) {
void GLTFAccessor::set_sparse_count(int64_t p_sparse_count) {
sparse_count = p_sparse_count;
}
int GLTFAccessor::get_sparse_indices_buffer_view() {
GLTFBufferViewIndex GLTFAccessor::get_sparse_indices_buffer_view() const {
return sparse_indices_buffer_view;
}
void GLTFAccessor::set_sparse_indices_buffer_view(int p_sparse_indices_buffer_view) {
void GLTFAccessor::set_sparse_indices_buffer_view(GLTFBufferViewIndex p_sparse_indices_buffer_view) {
sparse_indices_buffer_view = p_sparse_indices_buffer_view;
}
int GLTFAccessor::get_sparse_indices_byte_offset() {
int64_t GLTFAccessor::get_sparse_indices_byte_offset() const {
return sparse_indices_byte_offset;
}
void GLTFAccessor::set_sparse_indices_byte_offset(int p_sparse_indices_byte_offset) {
void GLTFAccessor::set_sparse_indices_byte_offset(int64_t p_sparse_indices_byte_offset) {
sparse_indices_byte_offset = p_sparse_indices_byte_offset;
}
int GLTFAccessor::get_sparse_indices_component_type() {
GLTFAccessor::GLTFComponentType GLTFAccessor::get_sparse_indices_component_type() const {
return sparse_indices_component_type;
}
void GLTFAccessor::set_sparse_indices_component_type(int p_sparse_indices_component_type) {
void GLTFAccessor::set_sparse_indices_component_type(GLTFComponentType p_sparse_indices_component_type) {
sparse_indices_component_type = (GLTFComponentType)p_sparse_indices_component_type;
}
int GLTFAccessor::get_sparse_values_buffer_view() {
GLTFBufferViewIndex GLTFAccessor::get_sparse_values_buffer_view() const {
return sparse_values_buffer_view;
}
void GLTFAccessor::set_sparse_values_buffer_view(int p_sparse_values_buffer_view) {
void GLTFAccessor::set_sparse_values_buffer_view(GLTFBufferViewIndex p_sparse_values_buffer_view) {
sparse_values_buffer_view = p_sparse_values_buffer_view;
}
int GLTFAccessor::get_sparse_values_byte_offset() {
int64_t GLTFAccessor::get_sparse_values_byte_offset() const {
return sparse_values_byte_offset;
}
void GLTFAccessor::set_sparse_values_byte_offset(int p_sparse_values_byte_offset) {
void GLTFAccessor::set_sparse_values_byte_offset(int64_t p_sparse_values_byte_offset) {
sparse_values_byte_offset = p_sparse_values_byte_offset;
}

View file

@ -66,68 +66,90 @@ public:
private:
GLTFBufferViewIndex buffer_view = -1;
int byte_offset = 0;
int64_t byte_offset = 0;
GLTFComponentType component_type = COMPONENT_TYPE_NONE;
bool normalized = false;
int count = 0;
int64_t count = 0;
GLTFAccessorType accessor_type = GLTFAccessorType::TYPE_SCALAR;
Vector<double> min;
Vector<double> max;
int sparse_count = 0;
int sparse_indices_buffer_view = 0;
int sparse_indices_byte_offset = 0;
int64_t sparse_count = 0;
GLTFBufferViewIndex sparse_indices_buffer_view = 0;
int64_t sparse_indices_byte_offset = 0;
GLTFComponentType sparse_indices_component_type = COMPONENT_TYPE_NONE;
int sparse_values_buffer_view = 0;
int sparse_values_byte_offset = 0;
GLTFBufferViewIndex sparse_values_buffer_view = 0;
int64_t sparse_values_byte_offset = 0;
protected:
static void _bind_methods();
#ifndef DISABLE_DEPRECATED
// 32-bit and non-const versions for compatibility.
GLTFBufferViewIndex _get_buffer_view_bind_compat_106220();
int _get_byte_offset_bind_compat_106220();
int _get_component_type_bind_compat_106220();
void _set_component_type_bind_compat_106220(int p_component_type);
bool _get_normalized_bind_compat_106220();
int _get_count_bind_compat_106220();
GLTFAccessorType _get_accessor_type_bind_compat_106220();
int _get_type_bind_compat_106220();
Vector<double> _get_min_bind_compat_106220();
Vector<double> _get_max_bind_compat_106220();
int _get_sparse_count_bind_compat_106220();
int _get_sparse_indices_buffer_view_bind_compat_106220();
int _get_sparse_indices_byte_offset_bind_compat_106220();
int _get_sparse_indices_component_type_bind_compat_106220();
void _set_sparse_indices_component_type_bind_compat_106220(int p_sparse_indices_component_type);
int _get_sparse_values_buffer_view_bind_compat_106220();
int _get_sparse_values_byte_offset_bind_compat_106220();
static void _bind_compatibility_methods();
#endif // DISABLE_DEPRECATED
public:
GLTFBufferViewIndex get_buffer_view();
GLTFBufferViewIndex get_buffer_view() const;
void set_buffer_view(GLTFBufferViewIndex p_buffer_view);
int get_byte_offset();
void set_byte_offset(int p_byte_offset);
int64_t get_byte_offset() const;
void set_byte_offset(int64_t p_byte_offset);
int get_component_type();
void set_component_type(int p_component_type);
GLTFComponentType get_component_type() const;
void set_component_type(GLTFComponentType p_component_type);
bool get_normalized();
bool get_normalized() const;
void set_normalized(bool p_normalized);
int get_count();
void set_count(int p_count);
int64_t get_count() const;
void set_count(int64_t p_count);
GLTFAccessorType get_accessor_type();
GLTFAccessorType get_accessor_type() const;
void set_accessor_type(GLTFAccessorType p_accessor_type);
int get_type();
int get_type() const;
void set_type(int p_accessor_type);
Vector<double> get_min();
Vector<double> get_min() const;
void set_min(Vector<double> p_min);
Vector<double> get_max();
Vector<double> get_max() const;
void set_max(Vector<double> p_max);
int get_sparse_count();
void set_sparse_count(int p_sparse_count);
int64_t get_sparse_count() const;
void set_sparse_count(int64_t p_sparse_count);
int get_sparse_indices_buffer_view();
void set_sparse_indices_buffer_view(int p_sparse_indices_buffer_view);
GLTFBufferViewIndex get_sparse_indices_buffer_view() const;
void set_sparse_indices_buffer_view(GLTFBufferViewIndex p_sparse_indices_buffer_view);
int get_sparse_indices_byte_offset();
void set_sparse_indices_byte_offset(int p_sparse_indices_byte_offset);
int64_t get_sparse_indices_byte_offset() const;
void set_sparse_indices_byte_offset(int64_t p_sparse_indices_byte_offset);
int get_sparse_indices_component_type();
void set_sparse_indices_component_type(int p_sparse_indices_component_type);
GLTFComponentType get_sparse_indices_component_type() const;
void set_sparse_indices_component_type(GLTFComponentType p_sparse_indices_component_type);
int get_sparse_values_buffer_view();
void set_sparse_values_buffer_view(int p_sparse_values_buffer_view);
GLTFBufferViewIndex get_sparse_values_buffer_view() const;
void set_sparse_values_buffer_view(GLTFBufferViewIndex p_sparse_values_buffer_view);
int get_sparse_values_byte_offset();
void set_sparse_values_byte_offset(int p_sparse_values_byte_offset);
int64_t get_sparse_values_byte_offset() const;
void set_sparse_values_byte_offset(int64_t p_sparse_values_byte_offset);
};
VARIANT_ENUM_CAST(GLTFAccessor::GLTFAccessorType);

View file

@ -51,6 +51,7 @@ bool GLTFBufferView::_get_indices_bind_compat_86907() {
}
void GLTFBufferView::_bind_compatibility_methods() {
// Non-const versions for compatibility.
ClassDB::bind_compatibility_method(D_METHOD("get_buffer"), &GLTFBufferView::_get_buffer_bind_compat_86907);
ClassDB::bind_compatibility_method(D_METHOD("get_byte_offset"), &GLTFBufferView::_get_byte_offset_bind_compat_86907);
ClassDB::bind_compatibility_method(D_METHOD("get_byte_length"), &GLTFBufferView::_get_byte_length_bind_compat_86907);

View file

@ -65,27 +65,27 @@ void GLTFBufferView::set_buffer(GLTFBufferIndex p_buffer) {
buffer = p_buffer;
}
int GLTFBufferView::get_byte_offset() const {
int64_t GLTFBufferView::get_byte_offset() const {
return byte_offset;
}
void GLTFBufferView::set_byte_offset(int p_byte_offset) {
void GLTFBufferView::set_byte_offset(int64_t p_byte_offset) {
byte_offset = p_byte_offset;
}
int GLTFBufferView::get_byte_length() const {
int64_t GLTFBufferView::get_byte_length() const {
return byte_length;
}
void GLTFBufferView::set_byte_length(int p_byte_length) {
void GLTFBufferView::set_byte_length(int64_t p_byte_length) {
byte_length = p_byte_length;
}
int GLTFBufferView::get_byte_stride() const {
int64_t GLTFBufferView::get_byte_stride() const {
return byte_stride;
}
void GLTFBufferView::set_byte_stride(int p_byte_stride) {
void GLTFBufferView::set_byte_stride(int64_t p_byte_stride) {
byte_stride = p_byte_stride;
}

View file

@ -40,9 +40,9 @@ class GLTFBufferView : public Resource {
private:
GLTFBufferIndex buffer = -1;
int byte_offset = 0;
int byte_length = 0;
int byte_stride = -1;
int64_t byte_offset = 0;
int64_t byte_length = 0;
int64_t byte_stride = -1;
bool indices = false;
bool vertex_attributes = false;
@ -50,6 +50,7 @@ protected:
static void _bind_methods();
#ifndef DISABLE_DEPRECATED
// Non-const versions for compatibility.
GLTFBufferIndex _get_buffer_bind_compat_86907();
int _get_byte_offset_bind_compat_86907();
int _get_byte_length_bind_compat_86907();
@ -62,14 +63,14 @@ public:
GLTFBufferIndex get_buffer() const;
void set_buffer(GLTFBufferIndex p_buffer);
int get_byte_offset() const;
void set_byte_offset(int p_byte_offset);
int64_t get_byte_offset() const;
void set_byte_offset(int64_t p_byte_offset);
int get_byte_length() const;
void set_byte_length(int p_byte_length);
int64_t get_byte_length() const;
void set_byte_length(int64_t p_byte_length);
int get_byte_stride() const;
void set_byte_stride(int p_byte_stride);
int64_t get_byte_stride() const;
void set_byte_stride(int64_t p_byte_stride);
bool get_indices() const;
void set_indices(bool p_indices);