Path: blob/master/modules/gltf/structures/gltf_object_model_property.cpp
10278 views
/**************************************************************************/1/* gltf_object_model_property.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_object_model_property.h"3132#include "../gltf_template_convert.h"3334void GLTFObjectModelProperty::_bind_methods() {35BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_UNKNOWN);36BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_BOOL);37BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT);38BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT_ARRAY);39BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT2);40BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT3);41BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT4);42BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT2X2);43BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT3X3);44BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_FLOAT4X4);45BIND_ENUM_CONSTANT(GLTF_OBJECT_MODEL_TYPE_INT);4647ClassDB::bind_method(D_METHOD("append_node_path", "node_path"), &GLTFObjectModelProperty::append_node_path);48ClassDB::bind_method(D_METHOD("append_path_to_property", "node_path", "prop_name"), &GLTFObjectModelProperty::append_path_to_property);4950ClassDB::bind_method(D_METHOD("get_accessor_type"), &GLTFObjectModelProperty::get_accessor_type);51ClassDB::bind_method(D_METHOD("get_gltf_to_godot_expression"), &GLTFObjectModelProperty::get_gltf_to_godot_expression);52ClassDB::bind_method(D_METHOD("set_gltf_to_godot_expression", "gltf_to_godot_expr"), &GLTFObjectModelProperty::set_gltf_to_godot_expression);53ClassDB::bind_method(D_METHOD("get_godot_to_gltf_expression"), &GLTFObjectModelProperty::get_godot_to_gltf_expression);54ClassDB::bind_method(D_METHOD("set_godot_to_gltf_expression", "godot_to_gltf_expr"), &GLTFObjectModelProperty::set_godot_to_gltf_expression);55ClassDB::bind_method(D_METHOD("get_node_paths"), &GLTFObjectModelProperty::get_node_paths);56ClassDB::bind_method(D_METHOD("has_node_paths"), &GLTFObjectModelProperty::has_node_paths);57ClassDB::bind_method(D_METHOD("set_node_paths", "node_paths"), &GLTFObjectModelProperty::set_node_paths);58ClassDB::bind_method(D_METHOD("get_object_model_type"), &GLTFObjectModelProperty::get_object_model_type);59ClassDB::bind_method(D_METHOD("set_object_model_type", "type"), &GLTFObjectModelProperty::set_object_model_type);60ClassDB::bind_method(D_METHOD("get_json_pointers"), &GLTFObjectModelProperty::get_json_pointers_bind);61ClassDB::bind_method(D_METHOD("has_json_pointers"), &GLTFObjectModelProperty::has_json_pointers);62ClassDB::bind_method(D_METHOD("set_json_pointers", "json_pointers"), &GLTFObjectModelProperty::set_json_pointers_bind);63ClassDB::bind_method(D_METHOD("get_variant_type"), &GLTFObjectModelProperty::get_variant_type);64ClassDB::bind_method(D_METHOD("set_variant_type", "variant_type"), &GLTFObjectModelProperty::set_variant_type);65ClassDB::bind_method(D_METHOD("set_types", "variant_type", "obj_model_type"), &GLTFObjectModelProperty::set_types);6667ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gltf_to_godot_expression", PROPERTY_HINT_RESOURCE_TYPE, "Expression"), "set_gltf_to_godot_expression", "get_gltf_to_godot_expression"); // Ref<Expression>68ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "godot_to_gltf_expression", PROPERTY_HINT_RESOURCE_TYPE, "Expression"), "set_godot_to_gltf_expression", "get_godot_to_gltf_expression"); // Ref<Expression>69ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "node_paths", PROPERTY_HINT_TYPE_STRING, "NodePath"), "set_node_paths", "get_node_paths"); // TypedArray<NodePath>70ADD_PROPERTY(PropertyInfo(Variant::INT, "object_model_type"), "set_object_model_type", "get_object_model_type"); // GLTFObjectModelType71ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "json_pointers"), "set_json_pointers", "get_json_pointers"); // TypedArray<PackedStringArray>72ADD_PROPERTY(PropertyInfo(Variant::INT, "variant_type"), "set_variant_type", "get_variant_type"); // Variant::Type73}7475void GLTFObjectModelProperty::append_node_path(const NodePath &p_node_path) {76node_paths.push_back(p_node_path);77}7879void GLTFObjectModelProperty::append_path_to_property(const NodePath &p_node_path, const StringName &p_prop_name) {80Vector<StringName> node_names = p_node_path.get_names();81Vector<StringName> subpath = p_node_path.get_subnames();82subpath.append(p_prop_name);83node_paths.push_back(NodePath(node_names, subpath, false));84}8586GLTFAccessor::GLTFAccessorType GLTFObjectModelProperty::get_accessor_type() const {87switch (object_model_type) {88case GLTF_OBJECT_MODEL_TYPE_FLOAT2:89return GLTFAccessor::TYPE_VEC2;90case GLTF_OBJECT_MODEL_TYPE_FLOAT3:91return GLTFAccessor::TYPE_VEC3;92case GLTF_OBJECT_MODEL_TYPE_FLOAT4:93return GLTFAccessor::TYPE_VEC4;94case GLTF_OBJECT_MODEL_TYPE_FLOAT2X2:95return GLTFAccessor::TYPE_MAT2;96case GLTF_OBJECT_MODEL_TYPE_FLOAT3X3:97return GLTFAccessor::TYPE_MAT3;98case GLTF_OBJECT_MODEL_TYPE_FLOAT4X4:99return GLTFAccessor::TYPE_MAT4;100default:101return GLTFAccessor::TYPE_SCALAR;102}103}104105Ref<Expression> GLTFObjectModelProperty::get_gltf_to_godot_expression() const {106return gltf_to_godot_expr;107}108109void GLTFObjectModelProperty::set_gltf_to_godot_expression(Ref<Expression> p_gltf_to_godot_expr) {110gltf_to_godot_expr = p_gltf_to_godot_expr;111}112113Ref<Expression> GLTFObjectModelProperty::get_godot_to_gltf_expression() const {114return godot_to_gltf_expr;115}116117void GLTFObjectModelProperty::set_godot_to_gltf_expression(Ref<Expression> p_godot_to_gltf_expr) {118godot_to_gltf_expr = p_godot_to_gltf_expr;119}120121TypedArray<NodePath> GLTFObjectModelProperty::get_node_paths() const {122return node_paths;123}124125bool GLTFObjectModelProperty::has_node_paths() const {126return !node_paths.is_empty();127}128129void GLTFObjectModelProperty::set_node_paths(TypedArray<NodePath> p_node_paths) {130node_paths = p_node_paths;131}132133GLTFObjectModelProperty::GLTFObjectModelType GLTFObjectModelProperty::get_object_model_type() const {134return object_model_type;135}136137void GLTFObjectModelProperty::set_object_model_type(GLTFObjectModelType p_type) {138object_model_type = p_type;139}140141Vector<PackedStringArray> GLTFObjectModelProperty::get_json_pointers() const {142return json_pointers;143}144145bool GLTFObjectModelProperty::has_json_pointers() const {146return !json_pointers.is_empty();147}148149void GLTFObjectModelProperty::set_json_pointers(const Vector<PackedStringArray> &p_json_pointers) {150json_pointers = p_json_pointers;151}152153TypedArray<PackedStringArray> GLTFObjectModelProperty::get_json_pointers_bind() const {154return GLTFTemplateConvert::to_array(json_pointers);155}156157void GLTFObjectModelProperty::set_json_pointers_bind(const TypedArray<PackedStringArray> &p_json_pointers) {158GLTFTemplateConvert::set_from_array(json_pointers, p_json_pointers);159}160161Variant::Type GLTFObjectModelProperty::get_variant_type() const {162return variant_type;163}164165void GLTFObjectModelProperty::set_variant_type(Variant::Type p_variant_type) {166variant_type = p_variant_type;167}168169void GLTFObjectModelProperty::set_types(Variant::Type p_variant_type, GLTFObjectModelType p_obj_model_type) {170variant_type = p_variant_type;171object_model_type = p_obj_model_type;172}173174175