Path: blob/master/modules/gltf/structures/gltf_buffer_view.cpp
10278 views
/**************************************************************************/1/* gltf_buffer_view.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "gltf_buffer_view.h"31#include "gltf_buffer_view.compat.inc"3233#include "../gltf_state.h"3435void GLTFBufferView::_bind_methods() {36ClassDB::bind_method(D_METHOD("load_buffer_view_data", "state"), &GLTFBufferView::load_buffer_view_data);3738ClassDB::bind_method(D_METHOD("get_buffer"), &GLTFBufferView::get_buffer);39ClassDB::bind_method(D_METHOD("set_buffer", "buffer"), &GLTFBufferView::set_buffer);40ClassDB::bind_method(D_METHOD("get_byte_offset"), &GLTFBufferView::get_byte_offset);41ClassDB::bind_method(D_METHOD("set_byte_offset", "byte_offset"), &GLTFBufferView::set_byte_offset);42ClassDB::bind_method(D_METHOD("get_byte_length"), &GLTFBufferView::get_byte_length);43ClassDB::bind_method(D_METHOD("set_byte_length", "byte_length"), &GLTFBufferView::set_byte_length);44ClassDB::bind_method(D_METHOD("get_byte_stride"), &GLTFBufferView::get_byte_stride);45ClassDB::bind_method(D_METHOD("set_byte_stride", "byte_stride"), &GLTFBufferView::set_byte_stride);46ClassDB::bind_method(D_METHOD("get_indices"), &GLTFBufferView::get_indices);47ClassDB::bind_method(D_METHOD("set_indices", "indices"), &GLTFBufferView::set_indices);48ClassDB::bind_method(D_METHOD("get_vertex_attributes"), &GLTFBufferView::get_vertex_attributes);49ClassDB::bind_method(D_METHOD("set_vertex_attributes", "is_attributes"), &GLTFBufferView::set_vertex_attributes);5051ADD_PROPERTY(PropertyInfo(Variant::INT, "buffer"), "set_buffer", "get_buffer"); // GLTFBufferIndex52ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_offset"), "set_byte_offset", "get_byte_offset"); // int53ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_length"), "set_byte_length", "get_byte_length"); // int54ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_stride"), "set_byte_stride", "get_byte_stride"); // int55ADD_PROPERTY(PropertyInfo(Variant::BOOL, "indices"), "set_indices", "get_indices"); // bool56ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vertex_attributes"), "set_vertex_attributes", "get_vertex_attributes"); // bool57}5859GLTFBufferIndex GLTFBufferView::get_buffer() const {60return buffer;61}6263void GLTFBufferView::set_buffer(GLTFBufferIndex p_buffer) {64buffer = p_buffer;65}6667int64_t GLTFBufferView::get_byte_offset() const {68return byte_offset;69}7071void GLTFBufferView::set_byte_offset(int64_t p_byte_offset) {72byte_offset = p_byte_offset;73}7475int64_t GLTFBufferView::get_byte_length() const {76return byte_length;77}7879void GLTFBufferView::set_byte_length(int64_t p_byte_length) {80byte_length = p_byte_length;81}8283int64_t GLTFBufferView::get_byte_stride() const {84return byte_stride;85}8687void GLTFBufferView::set_byte_stride(int64_t p_byte_stride) {88byte_stride = p_byte_stride;89}9091bool GLTFBufferView::get_indices() const {92return indices;93}9495void GLTFBufferView::set_indices(bool p_indices) {96indices = p_indices;97}9899bool GLTFBufferView::get_vertex_attributes() const {100return vertex_attributes;101}102103void GLTFBufferView::set_vertex_attributes(bool p_attributes) {104vertex_attributes = p_attributes;105}106107Vector<uint8_t> GLTFBufferView::load_buffer_view_data(const Ref<GLTFState> p_state) const {108ERR_FAIL_COND_V(p_state.is_null(), Vector<uint8_t>());109ERR_FAIL_COND_V_MSG(byte_stride > 0, Vector<uint8_t>(), "Buffer views with byte stride are not yet supported by this method.");110const TypedArray<Vector<uint8_t>> &buffers = p_state->get_buffers();111ERR_FAIL_INDEX_V(buffer, buffers.size(), Vector<uint8_t>());112const PackedByteArray &buffer_data = buffers[buffer];113const int64_t byte_end = byte_offset + byte_length;114return buffer_data.slice(byte_offset, byte_end);115}116117118