Add exporting glTF2.

* Support KHR_texture_transform.
* Support exporting glTF2
* Support exporting instanced scenes
* Extract into a gltf state and gltf document
* Add a tools menu for exporting gltf2
This commit is contained in:
K. S. Ernest (iFire) Lee 2020-12-21 07:39:32 -08:00
parent 8ad0ff8ae5
commit 4b4efd2674
45 changed files with 10426 additions and 4091 deletions

View file

@ -91,7 +91,6 @@
#include "editor/export_template_manager.h"
#include "editor/filesystem_dock.h"
#include "editor/import/editor_import_collada.h"
#include "editor/import/editor_scene_importer_gltf.h"
#include "editor/import/resource_importer_bitmask.h"
#include "editor/import/resource_importer_csv.h"
#include "editor/import/resource_importer_csv_translation.h"
@ -103,6 +102,7 @@
#include "editor/import/resource_importer_texture.h"
#include "editor/import/resource_importer_texture_atlas.h"
#include "editor/import/resource_importer_wav.h"
#include "editor/import/scene_importer_mesh_node_3d.h"
#include "editor/import_dock.h"
#include "editor/multi_node_edit.h"
#include "editor/node_dock.h"
@ -3673,7 +3673,7 @@ void EditorNode::register_editor_types() {
ClassDB::register_class<EditorFeatureProfile>();
ClassDB::register_class<EditorSpinSlider>();
ClassDB::register_class<EditorSceneImporterMesh>();
ClassDB::register_class<EditorSceneImporterMeshNode>();
ClassDB::register_class<EditorSceneImporterMeshNode3D>();
ClassDB::register_virtual_class<FileSystemDock>();
@ -5712,10 +5712,6 @@ EditorNode::EditorNode() {
import_obj2.instance();
import_scene->add_importer(import_obj2);
Ref<EditorSceneImporterGLTF> import_gltf;
import_gltf.instance();
import_scene->add_importer(import_gltf);
Ref<EditorSceneImporterESCN> import_escn;
import_escn.instance();
import_scene->add_importer(import_escn);

View file

@ -33,6 +33,7 @@
#include "core/os/os.h"
#include "editor/editor_node.h"
#include "editor/import/collada.h"
#include "editor/import/scene_importer_mesh_node_3d.h"
#include "scene/3d/camera_3d.h"
#include "scene/3d/light_3d.h"
#include "scene/3d/mesh_instance_3d.h"
@ -278,8 +279,8 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) {
node = memnew(Path3D);
} else {
//mesh since nothing else
node = memnew(EditorSceneImporterMeshNode);
//Object::cast_to<EditorSceneImporterMeshNode>(node)->set_flag(GeometryInstance3D::FLAG_USE_BAKED_LIGHT, true);
node = memnew(EditorSceneImporterMeshNode3D);
//Object::cast_to<EditorSceneImporterMeshNode3D>(node)->set_flag(GeometryInstance3D::FLAG_USE_BAKED_LIGHT, true);
}
} break;
case Collada::Node::TYPE_SKELETON: {
@ -1003,10 +1004,10 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres
}
}
if (Object::cast_to<EditorSceneImporterMeshNode>(node)) {
if (Object::cast_to<EditorSceneImporterMeshNode3D>(node)) {
Collada::NodeGeometry *ng2 = static_cast<Collada::NodeGeometry *>(p_node);
EditorSceneImporterMeshNode *mi = Object::cast_to<EditorSceneImporterMeshNode>(node);
EditorSceneImporterMeshNode3D *mi = Object::cast_to<EditorSceneImporterMeshNode3D>(node);
ERR_FAIL_COND_V(!mi, ERR_BUG);

File diff suppressed because it is too large Load diff

View file

@ -1,384 +0,0 @@
/*************************************************************************/
/* editor_scene_importer_gltf.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 EDITOR_SCENE_IMPORTER_GLTF_H
#define EDITOR_SCENE_IMPORTER_GLTF_H
#include "editor/import/resource_importer_scene.h"
#include "scene/3d/light_3d.h"
#include "scene/3d/node_3d.h"
#include "scene/3d/skeleton_3d.h"
class AnimationPlayer;
class BoneAttachment3D;
class EditorSceneImporterMeshNode;
class EditorSceneImporterGLTF : public EditorSceneImporter {
GDCLASS(EditorSceneImporterGLTF, EditorSceneImporter);
typedef int GLTFAccessorIndex;
typedef int GLTFAnimationIndex;
typedef int GLTFBufferIndex;
typedef int GLTFBufferViewIndex;
typedef int GLTFCameraIndex;
typedef int GLTFImageIndex;
typedef int GLTFMaterialIndex;
typedef int GLTFMeshIndex;
typedef int GLTFLightIndex;
typedef int GLTFNodeIndex;
typedef int GLTFSkeletonIndex;
typedef int GLTFSkinIndex;
typedef int GLTFTextureIndex;
enum {
ARRAY_BUFFER = 34962,
ELEMENT_ARRAY_BUFFER = 34963,
TYPE_BYTE = 5120,
TYPE_UNSIGNED_BYTE = 5121,
TYPE_SHORT = 5122,
TYPE_UNSIGNED_SHORT = 5123,
TYPE_UNSIGNED_INT = 5125,
TYPE_FLOAT = 5126,
COMPONENT_TYPE_BYTE = 5120,
COMPONENT_TYPE_UNSIGNED_BYTE = 5121,
COMPONENT_TYPE_SHORT = 5122,
COMPONENT_TYPE_UNSIGNED_SHORT = 5123,
COMPONENT_TYPE_INT = 5125,
COMPONENT_TYPE_FLOAT = 5126,
};
String _get_component_type_name(const uint32_t p_component);
int _get_component_type_size(const int component_type);
enum GLTFType {
TYPE_SCALAR,
TYPE_VEC2,
TYPE_VEC3,
TYPE_VEC4,
TYPE_MAT2,
TYPE_MAT3,
TYPE_MAT4,
};
String _get_type_name(const GLTFType p_component);
struct GLTFNode {
//matrices need to be transformed to this
GLTFNodeIndex parent = -1;
int height = -1;
Transform xform;
String name;
GLTFMeshIndex mesh = -1;
GLTFCameraIndex camera = -1;
GLTFSkinIndex skin = -1;
GLTFSkeletonIndex skeleton = -1;
bool joint = false;
Vector3 translation;
Quat rotation;
Vector3 scale = Vector3(1, 1, 1);
Vector<int> children;
GLTFNodeIndex fake_joint_parent = -1;
GLTFLightIndex light = -1;
};
struct GLTFBufferView {
GLTFBufferIndex buffer = -1;
int byte_offset = 0;
int byte_length = 0;
int byte_stride = 0;
bool indices = false;
//matrices need to be transformed to this
};
struct GLTFAccessor {
GLTFBufferViewIndex buffer_view = 0;
int byte_offset = 0;
int component_type = 0;
bool normalized = false;
int count = 0;
GLTFType type = GLTFType::TYPE_SCALAR;
float min = 0;
float max = 0;
int sparse_count = 0;
int sparse_indices_buffer_view = 0;
int sparse_indices_byte_offset = 0;
int sparse_indices_component_type = 0;
int sparse_values_buffer_view = 0;
int sparse_values_byte_offset = 0;
};
struct GLTFTexture {
GLTFImageIndex src_image;
};
struct GLTFSkeleton {
// The *synthesized* skeletons joints
Vector<GLTFNodeIndex> joints;
// The roots of the skeleton. If there are multiple, each root must have the same parent
// (ie roots are siblings)
Vector<GLTFNodeIndex> roots;
// The created Skeleton for the scene
Skeleton3D *godot_skeleton = nullptr;
// Set of unique bone names for the skeleton
Set<String> unique_names;
};
struct GLTFSkin {
String name;
// The "skeleton" property defined in the gltf spec. -1 = Scene Root
GLTFNodeIndex skin_root = -1;
Vector<GLTFNodeIndex> joints_original;
Vector<Transform> inverse_binds;
// Note: joints + non_joints should form a complete subtree, or subtrees with a common parent
// All nodes that are skins that are caught in-between the original joints
// (inclusive of joints_original)
Vector<GLTFNodeIndex> joints;
// All Nodes that are caught in-between skin joint nodes, and are not defined
// as joints by any skin
Vector<GLTFNodeIndex> non_joints;
// The roots of the skin. In the case of multiple roots, their parent *must*
// be the same (the roots must be siblings)
Vector<GLTFNodeIndex> roots;
// The GLTF Skeleton this Skin points to (after we determine skeletons)
GLTFSkeletonIndex skeleton = -1;
// A mapping from the joint indices (in the order of joints_original) to the
// Godot Skeleton's bone_indices
Map<int, int> joint_i_to_bone_i;
Map<int, StringName> joint_i_to_name;
// The Actual Skin that will be created as a mapping between the IBM's of this skin
// to the generated skeleton for the mesh instances.
Ref<Skin> godot_skin;
};
struct GLTFMesh {
Ref<EditorSceneImporterMesh> mesh;
Vector<float> blend_weights;
};
struct GLTFCamera {
bool perspective = true;
float fov_size = 75;
float zfar = 4000;
float znear = 0.05;
};
struct GLTFLight {
Color color = Color(1.0f, 1.0f, 1.0f);
float intensity = 1.0f;
String type = "";
float range = Math_INF;
float inner_cone_angle = 0.0f;
float outer_cone_angle = Math_PI / 4.0;
};
struct GLTFAnimation {
bool loop = false;
enum Interpolation {
INTERP_LINEAR,
INTERP_STEP,
INTERP_CATMULLROMSPLINE,
INTERP_CUBIC_SPLINE
};
template <class T>
struct Channel {
Interpolation interpolation;
Vector<float> times;
Vector<T> values;
};
struct Track {
Channel<Vector3> translation_track;
Channel<Quat> rotation_track;
Channel<Vector3> scale_track;
Vector<Channel<float>> weight_tracks;
};
String name;
Map<int, Track> tracks;
};
struct GLTFState {
Dictionary json;
int major_version = 0;
int minor_version = 0;
Vector<uint8_t> glb_data;
bool use_named_skin_binds = false;
Vector<GLTFNode *> nodes;
Vector<Vector<uint8_t>> buffers;
Vector<GLTFBufferView> buffer_views;
Vector<GLTFAccessor> accessors;
Vector<GLTFMesh> meshes; //meshes are loaded directly, no reason not to.
Vector<Ref<StandardMaterial3D>> materials;
String scene_name;
Vector<int> root_nodes;
Vector<GLTFTexture> textures;
Vector<Ref<Texture2D>> images;
Vector<GLTFSkin> skins;
Vector<GLTFCamera> cameras;
Vector<GLTFLight> lights;
Set<String> unique_names;
Vector<GLTFSkeleton> skeletons;
Vector<GLTFAnimation> animations;
Map<GLTFNodeIndex, Node *> scene_nodes;
// EditorSceneImporter::ImportFlags
uint32_t import_flags;
~GLTFState() {
for (int i = 0; i < nodes.size(); i++) {
memdelete(nodes[i]);
}
}
};
String _sanitize_scene_name(const String &name);
String _gen_unique_name(GLTFState &state, const String &p_name);
String _sanitize_bone_name(const String &name);
String _gen_unique_bone_name(GLTFState &state, const GLTFSkeletonIndex skel_i, const String &p_name);
Ref<Texture2D> _get_texture(GLTFState &state, const GLTFTextureIndex p_texture);
Error _parse_json(const String &p_path, GLTFState &state);
Error _parse_glb(const String &p_path, GLTFState &state);
Error _parse_scenes(GLTFState &state);
Error _parse_nodes(GLTFState &state);
void _compute_node_heights(GLTFState &state);
Error _parse_buffers(GLTFState &state, const String &p_base_path);
Error _parse_buffer_views(GLTFState &state);
GLTFType _get_type_from_str(const String &p_string);
Error _parse_accessors(GLTFState &state);
Error _decode_buffer_view(GLTFState &state, double *dst, const GLTFBufferViewIndex p_buffer_view, const int skip_every, const int skip_bytes, const int element_size, const int count, const GLTFType type, const int component_count, const int component_type, const int component_size, const bool normalized, const int byte_offset, const bool for_vertex);
Vector<double> _decode_accessor(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
Vector<float> _decode_accessor_as_floats(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
Vector<int> _decode_accessor_as_ints(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
Vector<Vector2> _decode_accessor_as_vec2(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
Vector<Vector3> _decode_accessor_as_vec3(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
Vector<Color> _decode_accessor_as_color(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
Vector<Quat> _decode_accessor_as_quat(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
Vector<Transform2D> _decode_accessor_as_xform2d(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
Vector<Basis> _decode_accessor_as_basis(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
Vector<Transform> _decode_accessor_as_xform(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex);
Error _parse_meshes(GLTFState &state);
Error _parse_images(GLTFState &state, const String &p_base_path);
Error _parse_textures(GLTFState &state);
Error _parse_materials(GLTFState &state);
GLTFNodeIndex _find_highest_node(GLTFState &state, const Vector<GLTFNodeIndex> &subset);
bool _capture_nodes_in_skin(GLTFState &state, GLTFSkin &skin, const GLTFNodeIndex node_index);
void _capture_nodes_for_multirooted_skin(GLTFState &state, GLTFSkin &skin);
Error _expand_skin(GLTFState &state, GLTFSkin &skin);
Error _verify_skin(GLTFState &state, GLTFSkin &skin);
Error _parse_skins(GLTFState &state);
Error _determine_skeletons(GLTFState &state);
Error _reparent_non_joint_skeleton_subtrees(GLTFState &state, GLTFSkeleton &skeleton, const Vector<GLTFNodeIndex> &non_joints);
Error _reparent_to_fake_joint(GLTFState &state, GLTFSkeleton &skeleton, const GLTFNodeIndex node_index);
Error _determine_skeleton_roots(GLTFState &state, const GLTFSkeletonIndex skel_i);
Error _create_skeletons(GLTFState &state);
Error _map_skin_joints_indices_to_skeleton_bone_indices(GLTFState &state);
Error _create_skins(GLTFState &state);
bool _skins_are_same(const Ref<Skin> &skin_a, const Ref<Skin> &skin_b);
void _remove_duplicate_skins(GLTFState &state);
Error _parse_cameras(GLTFState &state);
Error _parse_lights(GLTFState &state);
Error _parse_animations(GLTFState &state);
BoneAttachment3D *_generate_bone_attachment(GLTFState &state, Skeleton3D *skeleton, const GLTFNodeIndex node_index);
EditorSceneImporterMeshNode *_generate_mesh_instance(GLTFState &state, Node *scene_parent, const GLTFNodeIndex node_index);
Camera3D *_generate_camera(GLTFState &state, Node *scene_parent, const GLTFNodeIndex node_index);
Light3D *_generate_light(GLTFState &state, Node *scene_parent, const GLTFNodeIndex node_index);
Node3D *_generate_spatial(GLTFState &state, Node *scene_parent, const GLTFNodeIndex node_index);
void _generate_scene_node(GLTFState &state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index);
Node3D *_generate_scene(GLTFState &state, const int p_bake_fps);
void _process_mesh_instances(GLTFState &state, Node3D *scene_root);
void _assign_scene_names(GLTFState &state);
template <class T>
T _interpolate_track(const Vector<float> &p_times, const Vector<T> &p_values, const float p_time, const GLTFAnimation::Interpolation p_interp);
void _import_animation(GLTFState &state, AnimationPlayer *ap, const GLTFAnimationIndex index, const int bake_fps);
public:
virtual uint32_t get_import_flags() const override;
virtual void get_extensions(List<String> *r_extensions) const override;
virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps = nullptr, Error *r_err = nullptr) override;
virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) override;
EditorSceneImporterGLTF();
};
#endif // EDITOR_SCENE_IMPORTER_GLTF_H

View file

@ -32,6 +32,8 @@
#include "core/io/resource_saver.h"
#include "core/os/file_access.h"
#include "editor/import/scene_importer_mesh.h"
#include "editor/import/scene_importer_mesh_node_3d.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/node_3d.h"
#include "scene/resources/mesh.h"
@ -444,7 +446,7 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, in
mesh->add_surface(m->surface_get_primitive_type(i), m->surface_get_arrays(i), Array(), Dictionary(), m->surface_get_material(i));
}
EditorSceneImporterMeshNode *mi = memnew(EditorSceneImporterMeshNode);
EditorSceneImporterMeshNode3D *mi = memnew(EditorSceneImporterMeshNode3D);
mi->set_mesh(mesh);
mi->set_name(E->get()->get_name());
scene->add_child(mi);

View file

@ -32,6 +32,7 @@
#include "core/io/resource_saver.h"
#include "editor/editor_node.h"
#include "editor/import/scene_importer_mesh_node_3d.h"
#include "scene/3d/collision_shape_3d.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/navigation_3d.h"
@ -120,345 +121,6 @@ void EditorSceneImporter::_bind_methods() {
BIND_CONSTANT(IMPORT_USE_COMPRESSION);
}
////////////////////////////////////////////////
void EditorSceneImporterMesh::add_blend_shape(const String &p_name) {
ERR_FAIL_COND(surfaces.size() > 0);
blend_shapes.push_back(p_name);
}
int EditorSceneImporterMesh::get_blend_shape_count() const {
return blend_shapes.size();
}
String EditorSceneImporterMesh::get_blend_shape_name(int p_blend_shape) const {
ERR_FAIL_INDEX_V(p_blend_shape, blend_shapes.size(), String());
return blend_shapes[p_blend_shape];
}
void EditorSceneImporterMesh::set_blend_shape_mode(Mesh::BlendShapeMode p_blend_shape_mode) {
blend_shape_mode = p_blend_shape_mode;
}
Mesh::BlendShapeMode EditorSceneImporterMesh::get_blend_shape_mode() const {
return blend_shape_mode;
}
void EditorSceneImporterMesh::add_surface(Mesh::PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, const Dictionary &p_lods, const Ref<Material> &p_material, const String &p_name) {
ERR_FAIL_COND(p_blend_shapes.size() != blend_shapes.size());
ERR_FAIL_COND(p_arrays.size() != Mesh::ARRAY_MAX);
Surface s;
s.primitive = p_primitive;
s.arrays = p_arrays;
s.name = p_name;
for (int i = 0; i < blend_shapes.size(); i++) {
Array bsdata = p_blend_shapes[i];
ERR_FAIL_COND(bsdata.size() != Mesh::ARRAY_MAX);
Surface::BlendShape bs;
bs.arrays = bsdata;
s.blend_shape_data.push_back(bs);
}
List<Variant> lods;
p_lods.get_key_list(&lods);
for (List<Variant>::Element *E = lods.front(); E; E = E->next()) {
ERR_CONTINUE(!E->get().is_num());
Surface::LOD lod;
lod.distance = E->get();
lod.indices = p_lods[E->get()];
ERR_CONTINUE(lod.indices.size() == 0);
s.lods.push_back(lod);
}
s.material = p_material;
surfaces.push_back(s);
mesh.unref();
}
int EditorSceneImporterMesh::get_surface_count() const {
return surfaces.size();
}
Mesh::PrimitiveType EditorSceneImporterMesh::get_surface_primitive_type(int p_surface) {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Mesh::PRIMITIVE_MAX);
return surfaces[p_surface].primitive;
}
Array EditorSceneImporterMesh::get_surface_arrays(int p_surface) const {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array());
return surfaces[p_surface].arrays;
}
String EditorSceneImporterMesh::get_surface_name(int p_surface) const {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), String());
return surfaces[p_surface].name;
}
Array EditorSceneImporterMesh::get_surface_blend_shape_arrays(int p_surface, int p_blend_shape) const {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array());
ERR_FAIL_INDEX_V(p_blend_shape, surfaces[p_surface].blend_shape_data.size(), Array());
return surfaces[p_surface].blend_shape_data[p_blend_shape].arrays;
}
int EditorSceneImporterMesh::get_surface_lod_count(int p_surface) const {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), 0);
return surfaces[p_surface].lods.size();
}
Vector<int> EditorSceneImporterMesh::get_surface_lod_indices(int p_surface, int p_lod) const {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Vector<int>());
ERR_FAIL_INDEX_V(p_lod, surfaces[p_surface].lods.size(), Vector<int>());
return surfaces[p_surface].lods[p_lod].indices;
}
float EditorSceneImporterMesh::get_surface_lod_size(int p_surface, int p_lod) const {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), 0);
ERR_FAIL_INDEX_V(p_lod, surfaces[p_surface].lods.size(), 0);
return surfaces[p_surface].lods[p_lod].distance;
}
Ref<Material> EditorSceneImporterMesh::get_surface_material(int p_surface) const {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Ref<Material>());
return surfaces[p_surface].material;
}
void EditorSceneImporterMesh::generate_lods() {
if (!SurfaceTool::simplify_func) {
return;
}
for (int i = 0; i < surfaces.size(); i++) {
if (surfaces[i].primitive != Mesh::PRIMITIVE_TRIANGLES) {
continue;
}
surfaces.write[i].lods.clear();
Vector<Vector3> vertices = surfaces[i].arrays[RS::ARRAY_VERTEX];
Vector<int> indices = surfaces[i].arrays[RS::ARRAY_INDEX];
if (indices.size() == 0) {
continue; //no lods if no indices
}
uint32_t vertex_count = vertices.size();
const Vector3 *vertices_ptr = vertices.ptr();
int min_indices = 10;
int index_target = indices.size() / 2;
print_line("total: " + itos(indices.size()));
while (index_target > min_indices) {
float error;
Vector<int> new_indices;
new_indices.resize(indices.size());
size_t new_len = SurfaceTool::simplify_func((unsigned int *)new_indices.ptrw(), (const unsigned int *)indices.ptr(), indices.size(), (const float *)vertices_ptr, vertex_count, sizeof(Vector3), index_target, 1e20, &error);
print_line("shoot for " + itos(index_target) + ", got " + itos(new_len) + " distance " + rtos(error));
if ((int)new_len > (index_target * 120 / 100)) {
break; // 20 percent tolerance
}
new_indices.resize(new_len);
Surface::LOD lod;
lod.distance = error;
lod.indices = new_indices;
surfaces.write[i].lods.push_back(lod);
index_target /= 2;
}
}
}
bool EditorSceneImporterMesh::has_mesh() const {
return mesh.is_valid();
}
Ref<ArrayMesh> EditorSceneImporterMesh::get_mesh() {
ERR_FAIL_COND_V(surfaces.size() == 0, Ref<ArrayMesh>());
if (mesh.is_null()) {
mesh.instance();
for (int i = 0; i < blend_shapes.size(); i++) {
mesh->add_blend_shape(blend_shapes[i]);
}
mesh->set_blend_shape_mode(blend_shape_mode);
for (int i = 0; i < surfaces.size(); i++) {
Array bs_data;
if (surfaces[i].blend_shape_data.size()) {
for (int j = 0; j < surfaces[i].blend_shape_data.size(); j++) {
bs_data.push_back(surfaces[i].blend_shape_data[j].arrays);
}
}
Dictionary lods;
if (surfaces[i].lods.size()) {
for (int j = 0; j < surfaces[i].lods.size(); j++) {
lods[surfaces[i].lods[j].distance] = surfaces[i].lods[j].indices;
}
}
mesh->add_surface_from_arrays(surfaces[i].primitive, surfaces[i].arrays, bs_data, lods);
if (surfaces[i].material.is_valid()) {
mesh->surface_set_material(mesh->get_surface_count() - 1, surfaces[i].material);
}
if (surfaces[i].name != String()) {
mesh->surface_set_name(mesh->get_surface_count() - 1, surfaces[i].name);
}
}
}
return mesh;
}
void EditorSceneImporterMesh::clear() {
surfaces.clear();
blend_shapes.clear();
mesh.unref();
}
void EditorSceneImporterMesh::_set_data(const Dictionary &p_data) {
clear();
if (p_data.has("blend_shape_names")) {
blend_shapes = p_data["blend_shape_names"];
}
if (p_data.has("surfaces")) {
Array surface_arr = p_data["surfaces"];
for (int i = 0; i < surface_arr.size(); i++) {
Dictionary s = surface_arr[i];
ERR_CONTINUE(!s.has("primitive"));
ERR_CONTINUE(!s.has("arrays"));
Mesh::PrimitiveType prim = Mesh::PrimitiveType(int(s["primitive"]));
ERR_CONTINUE(prim >= Mesh::PRIMITIVE_MAX);
Array arr = s["arrays"];
Dictionary lods;
String name;
if (s.has("name")) {
name = s["name"];
}
if (s.has("lods")) {
lods = s["lods"];
}
Array blend_shapes;
if (s.has("blend_shapes")) {
blend_shapes = s["blend_shapes"];
}
Ref<Material> material;
if (s.has("material")) {
material = s["material"];
}
add_surface(prim, arr, blend_shapes, lods, material, name);
}
}
}
Dictionary EditorSceneImporterMesh::_get_data() const {
Dictionary data;
if (blend_shapes.size()) {
data["blend_shape_names"] = blend_shapes;
}
Array surface_arr;
for (int i = 0; i < surfaces.size(); i++) {
Dictionary d;
d["primitive"] = surfaces[i].primitive;
d["arrays"] = surfaces[i].arrays;
if (surfaces[i].blend_shape_data.size()) {
Array bs_data;
for (int j = 0; j < surfaces[i].blend_shape_data.size(); j++) {
bs_data.push_back(surfaces[i].blend_shape_data[j].arrays);
}
d["blend_shapes"] = bs_data;
}
if (surfaces[i].lods.size()) {
Dictionary lods;
for (int j = 0; j < surfaces[i].lods.size(); j++) {
lods[surfaces[i].lods[j].distance] = surfaces[i].lods[j].indices;
}
d["lods"] = lods;
}
if (surfaces[i].material.is_valid()) {
d["material"] = surfaces[i].material;
}
if (surfaces[i].name != String()) {
d["name"] = surfaces[i].name;
}
surface_arr.push_back(d);
}
data["surfaces"] = surface_arr;
return data;
}
void EditorSceneImporterMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_blend_shape", "name"), &EditorSceneImporterMesh::add_blend_shape);
ClassDB::bind_method(D_METHOD("get_blend_shape_count"), &EditorSceneImporterMesh::get_blend_shape_count);
ClassDB::bind_method(D_METHOD("get_blend_shape_name", "blend_shape_idx"), &EditorSceneImporterMesh::get_blend_shape_name);
ClassDB::bind_method(D_METHOD("set_blend_shape_mode", "mode"), &EditorSceneImporterMesh::set_blend_shape_mode);
ClassDB::bind_method(D_METHOD("get_blend_shape_mode"), &EditorSceneImporterMesh::get_blend_shape_mode);
ClassDB::bind_method(D_METHOD("add_surface", "primitive", "arrays", "blend_shapes", "lods", "material"), &EditorSceneImporterMesh::add_surface, DEFVAL(Array()), DEFVAL(Dictionary()), DEFVAL(Ref<Material>()), DEFVAL(String()));
ClassDB::bind_method(D_METHOD("get_surface_count"), &EditorSceneImporterMesh::get_surface_count);
ClassDB::bind_method(D_METHOD("get_surface_primitive_type", "surface_idx"), &EditorSceneImporterMesh::get_surface_primitive_type);
ClassDB::bind_method(D_METHOD("get_surface_name", "surface_idx"), &EditorSceneImporterMesh::get_surface_name);
ClassDB::bind_method(D_METHOD("get_surface_arrays", "surface_idx"), &EditorSceneImporterMesh::get_surface_arrays);
ClassDB::bind_method(D_METHOD("get_surface_blend_shape_arrays", "surface_idx", "blend_shape_idx"), &EditorSceneImporterMesh::get_surface_blend_shape_arrays);
ClassDB::bind_method(D_METHOD("get_surface_lod_count", "surface_idx"), &EditorSceneImporterMesh::get_surface_lod_count);
ClassDB::bind_method(D_METHOD("get_surface_lod_size", "surface_idx", "lod_idx"), &EditorSceneImporterMesh::get_surface_lod_size);
ClassDB::bind_method(D_METHOD("get_surface_lod_indices", "surface_idx", "lod_idx"), &EditorSceneImporterMesh::get_surface_lod_indices);
ClassDB::bind_method(D_METHOD("get_surface_material", "surface_idx"), &EditorSceneImporterMesh::get_surface_material);
ClassDB::bind_method(D_METHOD("get_mesh"), &EditorSceneImporterMesh::get_mesh);
ClassDB::bind_method(D_METHOD("clear"), &EditorSceneImporterMesh::clear);
ClassDB::bind_method(D_METHOD("_set_data", "data"), &EditorSceneImporterMesh::_set_data);
ClassDB::bind_method(D_METHOD("_get_data"), &EditorSceneImporterMesh::_get_data);
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_data", "_get_data");
}
void EditorSceneImporterMeshNode::set_mesh(const Ref<EditorSceneImporterMesh> &p_mesh) {
mesh = p_mesh;
}
Ref<EditorSceneImporterMesh> EditorSceneImporterMeshNode::get_mesh() const {
return mesh;
}
void EditorSceneImporterMeshNode::set_skin(const Ref<Skin> &p_skin) {
skin = p_skin;
}
Ref<Skin> EditorSceneImporterMeshNode::get_skin() const {
return skin;
}
void EditorSceneImporterMeshNode::set_surface_material(int p_idx, const Ref<Material> &p_material) {
ERR_FAIL_COND(p_idx < 0);
if (p_idx >= surface_materials.size()) {
surface_materials.resize(p_idx + 1);
}
surface_materials.write[p_idx] = p_material;
}
Ref<Material> EditorSceneImporterMeshNode::get_surface_material(int p_idx) const {
ERR_FAIL_COND_V(p_idx < 0, Ref<Material>());
if (p_idx >= surface_materials.size()) {
return Ref<Material>();
}
return surface_materials[p_idx];
}
void EditorSceneImporterMeshNode::set_skeleton_path(const NodePath &p_path) {
skeleton_path = p_path;
}
NodePath EditorSceneImporterMeshNode::get_skeleton_path() const {
return skeleton_path;
}
void EditorSceneImporterMeshNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &EditorSceneImporterMeshNode::set_mesh);
ClassDB::bind_method(D_METHOD("get_mesh"), &EditorSceneImporterMeshNode::get_mesh);
ClassDB::bind_method(D_METHOD("set_skin", "skin"), &EditorSceneImporterMeshNode::set_skin);
ClassDB::bind_method(D_METHOD("get_skin"), &EditorSceneImporterMeshNode::get_skin);
ClassDB::bind_method(D_METHOD("set_skeleton_path", "skeleton_path"), &EditorSceneImporterMeshNode::set_skeleton_path);
ClassDB::bind_method(D_METHOD("get_skeleton_path"), &EditorSceneImporterMeshNode::get_skeleton_path);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "EditorSceneImporterMesh"), "set_mesh", "get_mesh");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skin", PROPERTY_HINT_RESOURCE_TYPE, "Skin"), "set_skin", "get_skin");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton"), "set_skeleton_path", "get_skeleton_path");
}
/////////////////////////////////
void EditorScenePostImport::_bind_methods() {
BIND_VMETHOD(MethodInfo(Variant::OBJECT, "post_import", PropertyInfo(Variant::OBJECT, "scene")));
@ -1560,27 +1222,30 @@ Ref<Animation> ResourceImporterScene::import_animation_from_other_importer(Edito
}
void ResourceImporterScene::_generate_meshes(Node *p_node, bool p_generate_lods) {
EditorSceneImporterMeshNode *src_mesh = Object::cast_to<EditorSceneImporterMeshNode>(p_node);
if (src_mesh != nullptr) {
EditorSceneImporterMeshNode3D *src_mesh_node = Object::cast_to<EditorSceneImporterMeshNode3D>(p_node);
if (src_mesh_node) {
//is mesh
MeshInstance3D *mesh_node = memnew(MeshInstance3D);
mesh_node->set_transform(src_mesh->get_transform());
mesh_node->set_skin(src_mesh->get_skin());
mesh_node->set_skeleton_path(src_mesh->get_skeleton_path());
Ref<ArrayMesh> mesh;
if (!src_mesh->get_mesh()->has_mesh()) {
if (p_generate_lods) {
src_mesh->get_mesh()->generate_lods();
mesh_node->set_name(src_mesh_node->get_name());
mesh_node->set_transform(src_mesh_node->get_transform());
mesh_node->set_skin(src_mesh_node->get_skin());
mesh_node->set_skeleton_path(src_mesh_node->get_skeleton_path());
if (src_mesh_node->get_mesh().is_valid()) {
Ref<ArrayMesh> mesh;
if (!src_mesh_node->get_mesh()->has_mesh()) {
//do mesh processing
if (p_generate_lods) {
src_mesh_node->get_mesh()->generate_lods();
}
}
mesh = src_mesh_node->get_mesh()->get_mesh();
if (mesh.is_valid()) {
mesh_node->set_mesh(mesh);
for (int i = 0; i < mesh->get_surface_count(); i++) {
mesh_node->set_surface_material(i, src_mesh_node->get_surface_material(i));
}
}
//do mesh processing
}
mesh = src_mesh->get_mesh()->get_mesh();
mesh_node->set_mesh(mesh);
for (int i = 0; i < mesh->get_surface_count(); i++) {
mesh_node->set_surface_material(i, src_mesh->get_surface_material(i));
}
p_node->replace_by(mesh_node);
memdelete(p_node);
p_node = mesh_node;

View file

@ -90,92 +90,6 @@ public:
EditorScenePostImport();
};
// The following classes are used by importers instead of ArrayMesh and MeshInstance3D
// so the data is not reginstered (hence, quality loss), importing happens faster and
// its easier to modify before saving
class EditorSceneImporterMesh : public Resource {
GDCLASS(EditorSceneImporterMesh, Resource)
struct Surface {
Mesh::PrimitiveType primitive;
Array arrays;
struct BlendShape {
Array arrays;
};
Vector<BlendShape> blend_shape_data;
struct LOD {
Vector<int> indices;
float distance;
};
Vector<LOD> lods;
Ref<Material> material;
String name;
};
Vector<Surface> surfaces;
Vector<String> blend_shapes;
Mesh::BlendShapeMode blend_shape_mode = Mesh::BLEND_SHAPE_MODE_NORMALIZED;
Ref<ArrayMesh> mesh;
protected:
void _set_data(const Dictionary &p_data);
Dictionary _get_data() const;
static void _bind_methods();
public:
void add_blend_shape(const String &p_name);
int get_blend_shape_count() const;
String get_blend_shape_name(int p_blend_shape) const;
void add_surface(Mesh::PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes = Array(), const Dictionary &p_lods = Dictionary(), const Ref<Material> &p_material = Ref<Material>(), const String &p_name = String());
int get_surface_count() const;
void set_blend_shape_mode(Mesh::BlendShapeMode p_blend_shape_mode);
Mesh::BlendShapeMode get_blend_shape_mode() const;
Mesh::PrimitiveType get_surface_primitive_type(int p_surface);
String get_surface_name(int p_surface) const;
Array get_surface_arrays(int p_surface) const;
Array get_surface_blend_shape_arrays(int p_surface, int p_blend_shape) const;
int get_surface_lod_count(int p_surface) const;
Vector<int> get_surface_lod_indices(int p_surface, int p_lod) const;
float get_surface_lod_size(int p_surface, int p_lod) const;
Ref<Material> get_surface_material(int p_surface) const;
void generate_lods();
bool has_mesh() const;
Ref<ArrayMesh> get_mesh();
void clear();
};
class EditorSceneImporterMeshNode : public Node3D {
GDCLASS(EditorSceneImporterMeshNode, Node3D)
Ref<EditorSceneImporterMesh> mesh;
Ref<Skin> skin;
NodePath skeleton_path;
Vector<Ref<Material>> surface_materials;
protected:
static void _bind_methods();
public:
void set_mesh(const Ref<EditorSceneImporterMesh> &p_mesh);
Ref<EditorSceneImporterMesh> get_mesh() const;
void set_skin(const Ref<Skin> &p_skin);
Ref<Skin> get_skin() const;
void set_surface_material(int p_idx, const Ref<Material> &p_material);
Ref<Material> get_surface_material(int p_idx) const;
void set_skeleton_path(const NodePath &p_path);
NodePath get_skeleton_path() const;
};
class ResourceImporterScene : public ResourceImporter {
GDCLASS(ResourceImporterScene, ResourceImporter);

View file

@ -0,0 +1,320 @@
/*************************************************************************/
/* scene_importer_mesh.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "scene_importer_mesh.h"
#include "scene/resources/surface_tool.h"
void EditorSceneImporterMesh::add_blend_shape(const String &p_name) {
ERR_FAIL_COND(surfaces.size() > 0);
blend_shapes.push_back(p_name);
}
int EditorSceneImporterMesh::get_blend_shape_count() const {
return blend_shapes.size();
}
String EditorSceneImporterMesh::get_blend_shape_name(int p_blend_shape) const {
ERR_FAIL_INDEX_V(p_blend_shape, blend_shapes.size(), String());
return blend_shapes[p_blend_shape];
}
void EditorSceneImporterMesh::set_blend_shape_mode(Mesh::BlendShapeMode p_blend_shape_mode) {
blend_shape_mode = p_blend_shape_mode;
}
Mesh::BlendShapeMode EditorSceneImporterMesh::get_blend_shape_mode() const {
return blend_shape_mode;
}
void EditorSceneImporterMesh::add_surface(Mesh::PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, const Dictionary &p_lods, const Ref<Material> &p_material, const String &p_name) {
ERR_FAIL_COND(p_blend_shapes.size() != blend_shapes.size());
ERR_FAIL_COND(p_arrays.size() != Mesh::ARRAY_MAX);
Surface s;
s.primitive = p_primitive;
s.arrays = p_arrays;
s.name = p_name;
for (int i = 0; i < blend_shapes.size(); i++) {
Array bsdata = p_blend_shapes[i];
ERR_FAIL_COND(bsdata.size() != Mesh::ARRAY_MAX);
Surface::BlendShape bs;
bs.arrays = bsdata;
s.blend_shape_data.push_back(bs);
}
List<Variant> lods;
p_lods.get_key_list(&lods);
for (List<Variant>::Element *E = lods.front(); E; E = E->next()) {
ERR_CONTINUE(!E->get().is_num());
Surface::LOD lod;
lod.distance = E->get();
lod.indices = p_lods[E->get()];
ERR_CONTINUE(lod.indices.size() == 0);
s.lods.push_back(lod);
}
s.material = p_material;
surfaces.push_back(s);
mesh.unref();
}
int EditorSceneImporterMesh::get_surface_count() const {
return surfaces.size();
}
Mesh::PrimitiveType EditorSceneImporterMesh::get_surface_primitive_type(int p_surface) {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Mesh::PRIMITIVE_MAX);
return surfaces[p_surface].primitive;
}
Array EditorSceneImporterMesh::get_surface_arrays(int p_surface) const {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array());
return surfaces[p_surface].arrays;
}
String EditorSceneImporterMesh::get_surface_name(int p_surface) const {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), String());
return surfaces[p_surface].name;
}
Array EditorSceneImporterMesh::get_surface_blend_shape_arrays(int p_surface, int p_blend_shape) const {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array());
ERR_FAIL_INDEX_V(p_blend_shape, surfaces[p_surface].blend_shape_data.size(), Array());
return surfaces[p_surface].blend_shape_data[p_blend_shape].arrays;
}
int EditorSceneImporterMesh::get_surface_lod_count(int p_surface) const {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), 0);
return surfaces[p_surface].lods.size();
}
Vector<int> EditorSceneImporterMesh::get_surface_lod_indices(int p_surface, int p_lod) const {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Vector<int>());
ERR_FAIL_INDEX_V(p_lod, surfaces[p_surface].lods.size(), Vector<int>());
return surfaces[p_surface].lods[p_lod].indices;
}
float EditorSceneImporterMesh::get_surface_lod_size(int p_surface, int p_lod) const {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), 0);
ERR_FAIL_INDEX_V(p_lod, surfaces[p_surface].lods.size(), 0);
return surfaces[p_surface].lods[p_lod].distance;
}
Ref<Material> EditorSceneImporterMesh::get_surface_material(int p_surface) const {
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Ref<Material>());
return surfaces[p_surface].material;
}
void EditorSceneImporterMesh::generate_lods() {
if (!SurfaceTool::simplify_func) {
return;
}
for (int i = 0; i < surfaces.size(); i++) {
if (surfaces[i].primitive != Mesh::PRIMITIVE_TRIANGLES) {
continue;
}
surfaces.write[i].lods.clear();
Vector<Vector3> vertices = surfaces[i].arrays[RS::ARRAY_VERTEX];
Vector<int> indices = surfaces[i].arrays[RS::ARRAY_INDEX];
if (indices.size() == 0) {
continue; //no lods if no indices
}
uint32_t vertex_count = vertices.size();
const Vector3 *vertices_ptr = vertices.ptr();
int min_indices = 10;
int index_target = indices.size() / 2;
print_line("total: " + itos(indices.size()));
while (index_target > min_indices) {
float error;
Vector<int> new_indices;
new_indices.resize(indices.size());
size_t new_len = SurfaceTool::simplify_func((unsigned int *)new_indices.ptrw(), (const unsigned int *)indices.ptr(), indices.size(), (const float *)vertices_ptr, vertex_count, sizeof(Vector3), index_target, 1e20, &error);
print_line("shoot for " + itos(index_target) + ", got " + itos(new_len) + " distance " + rtos(error));
if ((int)new_len > (index_target * 120 / 100)) {
break; // 20 percent tolerance
}
new_indices.resize(new_len);
Surface::LOD lod;
lod.distance = error;
lod.indices = new_indices;
surfaces.write[i].lods.push_back(lod);
index_target /= 2;
}
}
}
bool EditorSceneImporterMesh::has_mesh() const {
return mesh.is_valid();
}
Ref<ArrayMesh> EditorSceneImporterMesh::get_mesh() {
ERR_FAIL_COND_V(surfaces.size() == 0, Ref<ArrayMesh>());
if (mesh.is_null()) {
mesh.instance();
for (int i = 0; i < blend_shapes.size(); i++) {
mesh->add_blend_shape(blend_shapes[i]);
}
mesh->set_blend_shape_mode(blend_shape_mode);
for (int i = 0; i < surfaces.size(); i++) {
Array bs_data;
if (surfaces[i].blend_shape_data.size()) {
for (int j = 0; j < surfaces[i].blend_shape_data.size(); j++) {
bs_data.push_back(surfaces[i].blend_shape_data[j].arrays);
}
}
Dictionary lods;
if (surfaces[i].lods.size()) {
for (int j = 0; j < surfaces[i].lods.size(); j++) {
lods[surfaces[i].lods[j].distance] = surfaces[i].lods[j].indices;
}
}
mesh->add_surface_from_arrays(surfaces[i].primitive, surfaces[i].arrays, bs_data, lods);
if (surfaces[i].material.is_valid()) {
mesh->surface_set_material(mesh->get_surface_count() - 1, surfaces[i].material);
}
if (surfaces[i].name != String()) {
mesh->surface_set_name(mesh->get_surface_count() - 1, surfaces[i].name);
}
}
}
return mesh;
}
void EditorSceneImporterMesh::clear() {
surfaces.clear();
blend_shapes.clear();
mesh.unref();
}
void EditorSceneImporterMesh::_set_data(const Dictionary &p_data) {
clear();
if (p_data.has("blend_shape_names")) {
blend_shapes = p_data["blend_shape_names"];
}
if (p_data.has("surfaces")) {
Array surface_arr = p_data["surfaces"];
for (int i = 0; i < surface_arr.size(); i++) {
Dictionary s = surface_arr[i];
ERR_CONTINUE(!s.has("primitive"));
ERR_CONTINUE(!s.has("arrays"));
Mesh::PrimitiveType prim = Mesh::PrimitiveType(int(s["primitive"]));
ERR_CONTINUE(prim >= Mesh::PRIMITIVE_MAX);
Array arr = s["arrays"];
Dictionary lods;
String name;
if (s.has("name")) {
name = s["name"];
}
if (s.has("lods")) {
lods = s["lods"];
}
Array blend_shapes;
if (s.has("blend_shapes")) {
blend_shapes = s["blend_shapes"];
}
Ref<Material> material;
if (s.has("material")) {
material = s["material"];
}
add_surface(prim, arr, blend_shapes, lods, material, name);
}
}
}
Dictionary EditorSceneImporterMesh::_get_data() const {
Dictionary data;
if (blend_shapes.size()) {
data["blend_shape_names"] = blend_shapes;
}
Array surface_arr;
for (int i = 0; i < surfaces.size(); i++) {
Dictionary d;
d["primitive"] = surfaces[i].primitive;
d["arrays"] = surfaces[i].arrays;
if (surfaces[i].blend_shape_data.size()) {
Array bs_data;
for (int j = 0; j < surfaces[i].blend_shape_data.size(); j++) {
bs_data.push_back(surfaces[i].blend_shape_data[j].arrays);
}
d["blend_shapes"] = bs_data;
}
if (surfaces[i].lods.size()) {
Dictionary lods;
for (int j = 0; j < surfaces[i].lods.size(); j++) {
lods[surfaces[i].lods[j].distance] = surfaces[i].lods[j].indices;
}
d["lods"] = lods;
}
if (surfaces[i].material.is_valid()) {
d["material"] = surfaces[i].material;
}
if (surfaces[i].name != String()) {
d["name"] = surfaces[i].name;
}
surface_arr.push_back(d);
}
data["surfaces"] = surface_arr;
return data;
}
void EditorSceneImporterMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_blend_shape", "name"), &EditorSceneImporterMesh::add_blend_shape);
ClassDB::bind_method(D_METHOD("get_blend_shape_count"), &EditorSceneImporterMesh::get_blend_shape_count);
ClassDB::bind_method(D_METHOD("get_blend_shape_name", "blend_shape_idx"), &EditorSceneImporterMesh::get_blend_shape_name);
ClassDB::bind_method(D_METHOD("set_blend_shape_mode", "mode"), &EditorSceneImporterMesh::set_blend_shape_mode);
ClassDB::bind_method(D_METHOD("get_blend_shape_mode"), &EditorSceneImporterMesh::get_blend_shape_mode);
ClassDB::bind_method(D_METHOD("add_surface", "primitive", "arrays", "blend_shapes", "lods", "material"), &EditorSceneImporterMesh::add_surface, DEFVAL(Array()), DEFVAL(Dictionary()), DEFVAL(Ref<Material>()), DEFVAL(String()));
ClassDB::bind_method(D_METHOD("get_surface_count"), &EditorSceneImporterMesh::get_surface_count);
ClassDB::bind_method(D_METHOD("get_surface_primitive_type", "surface_idx"), &EditorSceneImporterMesh::get_surface_primitive_type);
ClassDB::bind_method(D_METHOD("get_surface_name", "surface_idx"), &EditorSceneImporterMesh::get_surface_name);
ClassDB::bind_method(D_METHOD("get_surface_arrays", "surface_idx"), &EditorSceneImporterMesh::get_surface_arrays);
ClassDB::bind_method(D_METHOD("get_surface_blend_shape_arrays", "surface_idx", "blend_shape_idx"), &EditorSceneImporterMesh::get_surface_blend_shape_arrays);
ClassDB::bind_method(D_METHOD("get_surface_lod_count", "surface_idx"), &EditorSceneImporterMesh::get_surface_lod_count);
ClassDB::bind_method(D_METHOD("get_surface_lod_size", "surface_idx", "lod_idx"), &EditorSceneImporterMesh::get_surface_lod_size);
ClassDB::bind_method(D_METHOD("get_surface_lod_indices", "surface_idx", "lod_idx"), &EditorSceneImporterMesh::get_surface_lod_indices);
ClassDB::bind_method(D_METHOD("get_surface_material", "surface_idx"), &EditorSceneImporterMesh::get_surface_material);
ClassDB::bind_method(D_METHOD("get_mesh"), &EditorSceneImporterMesh::get_mesh);
ClassDB::bind_method(D_METHOD("clear"), &EditorSceneImporterMesh::clear);
ClassDB::bind_method(D_METHOD("_set_data", "data"), &EditorSceneImporterMesh::_set_data);
ClassDB::bind_method(D_METHOD("_get_data"), &EditorSceneImporterMesh::_get_data);
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_data", "_get_data");
}

View file

@ -0,0 +1,96 @@
/*************************************************************************/
/* scene_importer_mesh.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 EDITOR_SCENE_IMPORTER_MESH_H
#define EDITOR_SCENE_IMPORTER_MESH_H
#include "core/io/resource.h"
#include "scene/resources/mesh.h"
// The following classes are used by importers instead of ArrayMesh and MeshInstance3D
// so the data is not registered (hence, quality loss), importing happens faster and
// its easier to modify before saving
class EditorSceneImporterMesh : public Resource {
GDCLASS(EditorSceneImporterMesh, Resource)
struct Surface {
Mesh::PrimitiveType primitive;
Array arrays;
struct BlendShape {
Array arrays;
};
Vector<BlendShape> blend_shape_data;
struct LOD {
Vector<int> indices;
float distance;
};
Vector<LOD> lods;
Ref<Material> material;
String name;
};
Vector<Surface> surfaces;
Vector<String> blend_shapes;
Mesh::BlendShapeMode blend_shape_mode = Mesh::BLEND_SHAPE_MODE_NORMALIZED;
Ref<ArrayMesh> mesh;
protected:
void _set_data(const Dictionary &p_data);
Dictionary _get_data() const;
static void _bind_methods();
public:
void add_blend_shape(const String &p_name);
int get_blend_shape_count() const;
String get_blend_shape_name(int p_blend_shape) const;
void add_surface(Mesh::PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes = Array(), const Dictionary &p_lods = Dictionary(), const Ref<Material> &p_material = Ref<Material>(), const String &p_name = String());
int get_surface_count() const;
void set_blend_shape_mode(Mesh::BlendShapeMode p_blend_shape_mode);
Mesh::BlendShapeMode get_blend_shape_mode() const;
Mesh::PrimitiveType get_surface_primitive_type(int p_surface);
String get_surface_name(int p_surface) const;
Array get_surface_arrays(int p_surface) const;
Array get_surface_blend_shape_arrays(int p_surface, int p_blend_shape) const;
int get_surface_lod_count(int p_surface) const;
Vector<int> get_surface_lod_indices(int p_surface, int p_lod) const;
float get_surface_lod_size(int p_surface, int p_lod) const;
Ref<Material> get_surface_material(int p_surface) const;
void generate_lods();
bool has_mesh() const;
Ref<ArrayMesh> get_mesh();
void clear();
};
#endif // EDITOR_SCENE_IMPORTER_MESH_H

View file

@ -0,0 +1,83 @@
/*************************************************************************/
/* scene_importer_mesh_node_3d.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "scene_importer_mesh_node_3d.h"
void EditorSceneImporterMeshNode3D::set_mesh(const Ref<EditorSceneImporterMesh> &p_mesh) {
mesh = p_mesh;
}
Ref<EditorSceneImporterMesh> EditorSceneImporterMeshNode3D::get_mesh() const {
return mesh;
}
void EditorSceneImporterMeshNode3D::set_skin(const Ref<Skin> &p_skin) {
skin = p_skin;
}
Ref<Skin> EditorSceneImporterMeshNode3D::get_skin() const {
return skin;
}
void EditorSceneImporterMeshNode3D::set_surface_material(int p_idx, const Ref<Material> &p_material) {
ERR_FAIL_COND(p_idx < 0);
if (p_idx >= surface_materials.size()) {
surface_materials.resize(p_idx + 1);
}
surface_materials.write[p_idx] = p_material;
}
Ref<Material> EditorSceneImporterMeshNode3D::get_surface_material(int p_idx) const {
ERR_FAIL_COND_V(p_idx < 0, Ref<Material>());
if (p_idx >= surface_materials.size()) {
return Ref<Material>();
}
return surface_materials[p_idx];
}
void EditorSceneImporterMeshNode3D::set_skeleton_path(const NodePath &p_path) {
skeleton_path = p_path;
}
NodePath EditorSceneImporterMeshNode3D::get_skeleton_path() const {
return skeleton_path;
}
void EditorSceneImporterMeshNode3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &EditorSceneImporterMeshNode3D::set_mesh);
ClassDB::bind_method(D_METHOD("get_mesh"), &EditorSceneImporterMeshNode3D::get_mesh);
ClassDB::bind_method(D_METHOD("set_skin", "skin"), &EditorSceneImporterMeshNode3D::set_skin);
ClassDB::bind_method(D_METHOD("get_skin"), &EditorSceneImporterMeshNode3D::get_skin);
ClassDB::bind_method(D_METHOD("set_skeleton_path", "skeleton_path"), &EditorSceneImporterMeshNode3D::set_skeleton_path);
ClassDB::bind_method(D_METHOD("get_skeleton_path"), &EditorSceneImporterMeshNode3D::get_skeleton_path);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "EditorSceneImporterMesh"), "set_mesh", "get_mesh");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skin", PROPERTY_HINT_RESOURCE_TYPE, "Skin"), "set_skin", "get_skin");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton"), "set_skeleton_path", "get_skeleton_path");
}

View file

@ -0,0 +1,64 @@
/*************************************************************************/
/* scene_importer_mesh_node_3d.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 EDITOR_SCENE_IMPORTER_MESH_NODE_3D_H
#define EDITOR_SCENE_IMPORTER_MESH_NODE_3D_H
#include "editor/import/scene_importer_mesh.h"
#include "scene/3d/node_3d.h"
#include "scene/resources/skin.h"
class EditorSceneImporterMesh;
class EditorSceneImporterMeshNode3D : public Node3D {
GDCLASS(EditorSceneImporterMeshNode3D, Node3D)
Ref<EditorSceneImporterMesh> mesh;
Ref<Skin> skin;
NodePath skeleton_path;
Vector<Ref<Material>> surface_materials;
protected:
static void _bind_methods();
public:
void set_mesh(const Ref<EditorSceneImporterMesh> &p_mesh);
Ref<EditorSceneImporterMesh> get_mesh() const;
void set_skin(const Ref<Skin> &p_skin);
Ref<Skin> get_skin() const;
void set_surface_material(int p_idx, const Ref<Material> &p_material);
Ref<Material> get_surface_material(int p_idx) const;
void set_skeleton_path(const NodePath &p_path);
NodePath get_skeleton_path() const;
};
#endif

10
modules/gltf/SCsub Normal file
View file

@ -0,0 +1,10 @@
#!/usr/bin/env python
Import("env")
Import("env_modules")
env_gltf = env_modules.Clone()
env_gltf.Prepend(CPPPATH=["."])
# Godot's own source files
env_gltf.add_source_files(env.modules_sources, "*.cpp")

6
modules/gltf/config.py Normal file
View file

@ -0,0 +1,6 @@
def can_build(env, platform):
return env["tools"] and not env["disable_3d"]
def configure(env):
pass

View file

@ -0,0 +1,90 @@
/*************************************************************************/
/* editor_scene_exporter_gltf_plugin.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "editor_scene_exporter_gltf_plugin.h"
#include "core/config/project_settings.h"
#include "core/object/object.h"
#include "core/templates/vector.h"
#include "editor/editor_file_system.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/gui/check_box.h"
#include "scene/main/node.h"
#include "editor/editor_node.h"
String SceneExporterGLTFPlugin::get_name() const {
return "ConvertGLTF2";
}
bool SceneExporterGLTFPlugin::has_main_screen() const {
return false;
}
SceneExporterGLTFPlugin::SceneExporterGLTFPlugin(EditorNode *p_node) {
editor = p_node;
convert_gltf2.instance();
file_export_lib = memnew(EditorFileDialog);
editor->get_gui_base()->add_child(file_export_lib);
file_export_lib->connect("file_selected", callable_mp(this, &SceneExporterGLTFPlugin::_gltf2_dialog_action));
file_export_lib->set_title(TTR("Export Library"));
file_export_lib->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
file_export_lib->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
file_export_lib->clear_filters();
file_export_lib->add_filter("*.glb");
file_export_lib->add_filter("*.gltf");
file_export_lib->set_title(TTR("Export Mesh GLTF2"));
String gltf_scene_name = TTR("Export GLTF...");
add_tool_menu_item(gltf_scene_name, callable_mp(this, &SceneExporterGLTFPlugin::convert_scene_to_gltf2));
}
void SceneExporterGLTFPlugin::_gltf2_dialog_action(String p_file) {
Node *root = editor->get_tree()->get_edited_scene_root();
if (!root) {
editor->show_accept(TTR("This operation can't be done without a scene."), TTR("OK"));
return;
}
List<String> deps;
convert_gltf2->save_scene(root, p_file, p_file, 0, 1000.0f, &deps);
EditorFileSystem::get_singleton()->scan_changes();
}
void SceneExporterGLTFPlugin::convert_scene_to_gltf2() {
Node *root = editor->get_tree()->get_edited_scene_root();
if (!root) {
editor->show_accept(TTR("This operation can't be done without a scene."), TTR("OK"));
return;
}
String filename = String(root->get_filename().get_file().get_basename());
if (filename.empty()) {
filename = root->get_name();
}
file_export_lib->set_current_file(filename + String(".gltf"));
file_export_lib->popup_centered_ratio();
}

View file

@ -0,0 +1,52 @@
/*************************************************************************/
/* editor_scene_exporter_gltf_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 EDITOR_SCENE_EXPORTER_GLTF_PLUGIN_H
#define EDITOR_SCENE_EXPORTER_GLTF_PLUGIN_H
#include "editor/editor_plugin.h"
#include "editor_scene_importer_gltf.h"
class SceneExporterGLTFPlugin : public EditorPlugin {
GDCLASS(SceneExporterGLTFPlugin, EditorPlugin);
Ref<PackedSceneGLTF> convert_gltf2;
EditorNode *editor = nullptr;
EditorFileDialog *file_export_lib = nullptr;
void _gltf2_dialog_action(String p_file);
void convert_scene_to_gltf2();
public:
virtual String get_name() const override;
bool has_main_screen() const override;
SceneExporterGLTFPlugin(class EditorNode *p_node);
};
#endif // EDITOR_SCENE_EXPORTER_GLTF_PLUGIN_H

View file

@ -0,0 +1,180 @@
/*************************************************************************/
/* editor_scene_importer_gltf.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "core/crypto/crypto_core.h"
#include "core/io/json.h"
#include "core/math/disjoint_set.h"
#include "core/math/math_defs.h"
#include "core/os/file_access.h"
#include "core/os/os.h"
#include "editor/import/resource_importer_scene.h"
#include "modules/gltf/gltf_state.h"
#include "modules/regex/regex.h"
#include "scene/3d/bone_attachment_3d.h"
#include "scene/3d/camera_3d.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/animation/animation_player.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/surface_tool.h"
#include "modules/gltf/editor_scene_importer_gltf.h"
uint32_t EditorSceneImporterGLTF::get_import_flags() const {
return ImportFlags::IMPORT_SCENE | ImportFlags::IMPORT_ANIMATION;
}
void EditorSceneImporterGLTF::get_extensions(List<String> *r_extensions) const {
r_extensions->push_back("gltf");
r_extensions->push_back("glb");
}
Node *EditorSceneImporterGLTF::import_scene(const String &p_path,
uint32_t p_flags, int p_bake_fps,
List<String> *r_missing_deps,
Error *r_err) {
Ref<PackedSceneGLTF> importer;
importer.instance();
return importer->import_scene(p_path, p_flags, p_bake_fps, r_missing_deps, r_err, Ref<GLTFState>());
}
Ref<Animation> EditorSceneImporterGLTF::import_animation(const String &p_path,
uint32_t p_flags,
int p_bake_fps) {
return Ref<Animation>();
}
void PackedSceneGLTF::_bind_methods() {
ClassDB::bind_method(
D_METHOD("export_gltf", "node", "path", "flags", "bake_fps"),
&PackedSceneGLTF::export_gltf, DEFVAL(0), DEFVAL(1000.0f));
ClassDB::bind_method(D_METHOD("pack_gltf", "path", "flags", "bake_fps", "state"),
&PackedSceneGLTF::pack_gltf, DEFVAL(0), DEFVAL(1000.0f), DEFVAL(Ref<GLTFState>()));
ClassDB::bind_method(D_METHOD("import_gltf_scene", "path", "flags", "bake_fps", "state"),
&PackedSceneGLTF::import_gltf_scene, DEFVAL(0), DEFVAL(1000.0f), DEFVAL(Ref<GLTFState>()));
}
Node *PackedSceneGLTF::import_gltf_scene(const String &p_path, uint32_t p_flags, float p_bake_fps, Ref<GLTFState> r_state) {
Error err = FAILED;
List<String> deps;
return import_scene(p_path, p_flags, p_bake_fps, &deps, &err, r_state);
}
Node *PackedSceneGLTF::import_scene(const String &p_path, uint32_t p_flags,
int p_bake_fps,
List<String> *r_missing_deps,
Error *r_err,
Ref<GLTFState> r_state) {
if (r_state == Ref<GLTFState>()) {
r_state.instance();
}
r_state->use_named_skin_binds =
p_flags & EditorSceneImporter::IMPORT_USE_NAMED_SKIN_BINDS;
Ref<GLTFDocument> gltf_document;
gltf_document.instance();
Error err = gltf_document->parse(r_state, p_path);
*r_err = err;
ERR_FAIL_COND_V(err != Error::OK, nullptr);
Node3D *root = memnew(Node3D);
for (int32_t root_i = 0; root_i < r_state->root_nodes.size(); root_i++) {
gltf_document->_generate_scene_node(r_state, root, root, r_state->root_nodes[root_i]);
}
gltf_document->_process_mesh_instances(r_state, root);
if (r_state->animations.size()) {
AnimationPlayer *ap = memnew(AnimationPlayer);
root->add_child(ap);
ap->set_owner(root);
for (int i = 0; i < r_state->animations.size(); i++) {
gltf_document->_import_animation(r_state, ap, i, p_bake_fps);
}
}
return cast_to<Node3D>(root);
}
void PackedSceneGLTF::pack_gltf(String p_path, int32_t p_flags,
real_t p_bake_fps, Ref<GLTFState> r_state) {
Error err = FAILED;
List<String> deps;
Node *root = import_scene(p_path, p_flags, p_bake_fps, &deps, &err, r_state);
ERR_FAIL_COND(err != OK);
pack(root);
}
void PackedSceneGLTF::save_scene(Node *p_node, const String &p_path,
const String &p_src_path, uint32_t p_flags,
int p_bake_fps, List<String> *r_missing_deps,
Error *r_err) {
Error err = FAILED;
if (r_err) {
*r_err = err;
}
Ref<GLTFDocument> gltf_document;
gltf_document.instance();
Ref<GLTFState> state;
state.instance();
err = gltf_document->serialize(state, p_node, p_path);
if (r_err) {
*r_err = err;
}
}
void PackedSceneGLTF::_build_parent_hierachy(Ref<GLTFState> state) {
// build the hierarchy
for (GLTFNodeIndex node_i = 0; node_i < state->nodes.size(); node_i++) {
for (int j = 0; j < state->nodes[node_i]->children.size(); j++) {
GLTFNodeIndex child_i = state->nodes[node_i]->children[j];
ERR_FAIL_INDEX(child_i, state->nodes.size());
if (state->nodes.write[child_i]->parent != -1) {
continue;
}
state->nodes.write[child_i]->parent = node_i;
}
}
}
Error PackedSceneGLTF::export_gltf(Node *p_root, String p_path,
int32_t p_flags,
real_t p_bake_fps) {
ERR_FAIL_COND_V(!p_root, FAILED);
List<String> deps;
Error err;
String path = p_path;
int32_t flags = p_flags;
real_t baked_fps = p_bake_fps;
Ref<PackedSceneGLTF> exporter;
exporter.instance();
exporter->save_scene(p_root, path, "", flags, baked_fps, &deps, &err);
int32_t error_code = err;
if (error_code != 0) {
return Error(error_code);
}
return OK;
}

View file

@ -0,0 +1,96 @@
/*************************************************************************/
/* editor_scene_importer_gltf.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 EDITOR_SCENE_IMPORTER_GLTF_H
#define EDITOR_SCENE_IMPORTER_GLTF_H
#include "core/config/project_settings.h"
#include "core/io/json.h"
#include "core/object/object.h"
#include "core/templates/vector.h"
#include "editor/import/resource_importer_scene.h"
#include "modules/csg/csg_shape.h"
#include "modules/gridmap/grid_map.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/multimesh_instance_3d.h"
#include "scene/3d/node_3d.h"
#include "scene/3d/skeleton_3d.h"
#include "scene/animation/animation_player.h"
#include "scene/gui/check_box.h"
#include "scene/main/node.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/surface_tool.h"
#include "gltf_document.h"
#include "gltf_state.h"
class AnimationPlayer;
class BoneAttachment;
class EditorSceneImporterMeshNode3D;
#ifdef TOOLS_ENABLED
class EditorSceneImporterGLTF : public EditorSceneImporter {
GDCLASS(EditorSceneImporterGLTF, EditorSceneImporter);
public:
virtual uint32_t get_import_flags() const override;
virtual void get_extensions(List<String> *r_extensions) const override;
virtual Node *import_scene(const String &p_path, uint32_t p_flags,
int p_bake_fps,
List<String> *r_missing_deps = NULL,
Error *r_err = NULL) override;
virtual Ref<Animation> import_animation(const String &p_path,
uint32_t p_flags, int p_bake_fps) override;
};
#endif
class PackedSceneGLTF : public PackedScene {
GDCLASS(PackedSceneGLTF, PackedScene);
protected:
static void _bind_methods();
public:
virtual void save_scene(Node *p_node, const String &p_path, const String &p_src_path,
uint32_t p_flags, int p_bake_fps,
List<String> *r_missing_deps, Error *r_err = NULL);
virtual void _build_parent_hierachy(Ref<GLTFState> state);
virtual Error export_gltf(Node *p_root, String p_path, int32_t p_flags = 0,
real_t p_bake_fps = 1000.0f);
virtual Node *import_scene(const String &p_path, uint32_t p_flags,
int p_bake_fps,
List<String> *r_missing_deps,
Error *r_err,
Ref<GLTFState> r_state);
virtual Node *import_gltf_scene(const String &p_path, uint32_t p_flags, float p_bake_fps, Ref<GLTFState> r_state = Ref<GLTFState>());
virtual void pack_gltf(String p_path, int32_t p_flags = 0,
real_t p_bake_fps = 1000.0f, Ref<GLTFState> r_state = Ref<GLTFState>());
};
#endif // EDITOR_SCENE_IMPORTER_GLTF_H

View file

@ -0,0 +1,189 @@
/*************************************************************************/
/* gltf_accessor.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "gltf_accessor.h"
void GLTFAccessor::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_buffer_view"), &GLTFAccessor::get_buffer_view);
ClassDB::bind_method(D_METHOD("set_buffer_view", "buffer_view"), &GLTFAccessor::set_buffer_view);
ClassDB::bind_method(D_METHOD("get_byte_offset"), &GLTFAccessor::get_byte_offset);
ClassDB::bind_method(D_METHOD("set_byte_offset", "byte_offset"), &GLTFAccessor::set_byte_offset);
ClassDB::bind_method(D_METHOD("get_component_type"), &GLTFAccessor::get_component_type);
ClassDB::bind_method(D_METHOD("set_component_type", "component_type"), &GLTFAccessor::set_component_type);
ClassDB::bind_method(D_METHOD("get_normalized"), &GLTFAccessor::get_normalized);
ClassDB::bind_method(D_METHOD("set_normalized", "normalized"), &GLTFAccessor::set_normalized);
ClassDB::bind_method(D_METHOD("get_count"), &GLTFAccessor::get_count);
ClassDB::bind_method(D_METHOD("set_count", "count"), &GLTFAccessor::set_count);
ClassDB::bind_method(D_METHOD("get_type"), &GLTFAccessor::get_type);
ClassDB::bind_method(D_METHOD("set_type", "type"), &GLTFAccessor::set_type);
ClassDB::bind_method(D_METHOD("get_min"), &GLTFAccessor::get_min);
ClassDB::bind_method(D_METHOD("set_min", "min"), &GLTFAccessor::set_min);
ClassDB::bind_method(D_METHOD("get_max"), &GLTFAccessor::get_max);
ClassDB::bind_method(D_METHOD("set_max", "max"), &GLTFAccessor::set_max);
ClassDB::bind_method(D_METHOD("get_sparse_count"), &GLTFAccessor::get_sparse_count);
ClassDB::bind_method(D_METHOD("set_sparse_count", "sparse_count"), &GLTFAccessor::set_sparse_count);
ClassDB::bind_method(D_METHOD("get_sparse_indices_buffer_view"), &GLTFAccessor::get_sparse_indices_buffer_view);
ClassDB::bind_method(D_METHOD("set_sparse_indices_buffer_view", "sparse_indices_buffer_view"), &GLTFAccessor::set_sparse_indices_buffer_view);
ClassDB::bind_method(D_METHOD("get_sparse_indices_byte_offset"), &GLTFAccessor::get_sparse_indices_byte_offset);
ClassDB::bind_method(D_METHOD("set_sparse_indices_byte_offset", "sparse_indices_byte_offset"), &GLTFAccessor::set_sparse_indices_byte_offset);
ClassDB::bind_method(D_METHOD("get_sparse_indices_component_type"), &GLTFAccessor::get_sparse_indices_component_type);
ClassDB::bind_method(D_METHOD("set_sparse_indices_component_type", "sparse_indices_component_type"), &GLTFAccessor::set_sparse_indices_component_type);
ClassDB::bind_method(D_METHOD("get_sparse_values_buffer_view"), &GLTFAccessor::get_sparse_values_buffer_view);
ClassDB::bind_method(D_METHOD("set_sparse_values_buffer_view", "sparse_values_buffer_view"), &GLTFAccessor::set_sparse_values_buffer_view);
ClassDB::bind_method(D_METHOD("get_sparse_values_byte_offset"), &GLTFAccessor::get_sparse_values_byte_offset);
ClassDB::bind_method(D_METHOD("set_sparse_values_byte_offset", "sparse_values_byte_offset"), &GLTFAccessor::set_sparse_values_byte_offset);
ADD_PROPERTY(PropertyInfo(Variant::INT, "buffer_view"), "set_buffer_view", "get_buffer_view"); // GLTFBufferViewIndex
ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_offset"), "set_byte_offset", "get_byte_offset"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "component_type"), "set_component_type", "get_component_type"); // int
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "normalized"), "set_normalized", "get_normalized"); // bool
ADD_PROPERTY(PropertyInfo(Variant::INT, "count"), "set_count", "get_count"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "type"), "set_type", "get_type"); // GLTFDocument::GLTFType
ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT64_ARRAY, "min"), "set_min", "get_min"); // Vector<real_t>
ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT64_ARRAY, "max"), "set_max", "get_max"); // Vector<real_t>
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_count"), "set_sparse_count", "get_sparse_count"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_indices_buffer_view"), "set_sparse_indices_buffer_view", "get_sparse_indices_buffer_view"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_indices_byte_offset"), "set_sparse_indices_byte_offset", "get_sparse_indices_byte_offset"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_indices_component_type"), "set_sparse_indices_component_type", "get_sparse_indices_component_type"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "sparse_values_buffer_view"), "set_sparse_values_buffer_view", "get_sparse_values_buffer_view"); // int
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() {
return buffer_view;
}
void GLTFAccessor::set_buffer_view(GLTFBufferViewIndex p_buffer_view) {
buffer_view = p_buffer_view;
}
int GLTFAccessor::get_byte_offset() {
return byte_offset;
}
void GLTFAccessor::set_byte_offset(int p_byte_offset) {
byte_offset = p_byte_offset;
}
int GLTFAccessor::get_component_type() {
return component_type;
}
void GLTFAccessor::set_component_type(int p_component_type) {
component_type = p_component_type;
}
bool GLTFAccessor::get_normalized() {
return normalized;
}
void GLTFAccessor::set_normalized(bool p_normalized) {
normalized = p_normalized;
}
int GLTFAccessor::get_count() {
return count;
}
void GLTFAccessor::set_count(int p_count) {
count = p_count;
}
int GLTFAccessor::get_type() {
return (int)type;
}
void GLTFAccessor::set_type(int p_type) {
type = (GLTFDocument::GLTFType)p_type; // TODO: Register enum
}
Vector<double> GLTFAccessor::get_min() {
return min;
}
void GLTFAccessor::set_min(Vector<double> p_min) {
min = p_min;
}
Vector<double> GLTFAccessor::get_max() {
return max;
}
void GLTFAccessor::set_max(Vector<double> p_max) {
max = p_max;
}
int GLTFAccessor::get_sparse_count() {
return sparse_count;
}
void GLTFAccessor::set_sparse_count(int p_sparse_count) {
sparse_count = p_sparse_count;
}
int GLTFAccessor::get_sparse_indices_buffer_view() {
return sparse_indices_buffer_view;
}
void GLTFAccessor::set_sparse_indices_buffer_view(int p_sparse_indices_buffer_view) {
sparse_indices_buffer_view = p_sparse_indices_buffer_view;
}
int GLTFAccessor::get_sparse_indices_byte_offset() {
return sparse_indices_byte_offset;
}
void GLTFAccessor::set_sparse_indices_byte_offset(int p_sparse_indices_byte_offset) {
sparse_indices_byte_offset = p_sparse_indices_byte_offset;
}
int GLTFAccessor::get_sparse_indices_component_type() {
return sparse_indices_component_type;
}
void GLTFAccessor::set_sparse_indices_component_type(int p_sparse_indices_component_type) {
sparse_indices_component_type = p_sparse_indices_component_type;
}
int GLTFAccessor::get_sparse_values_buffer_view() {
return sparse_values_buffer_view;
}
void GLTFAccessor::set_sparse_values_buffer_view(int p_sparse_values_buffer_view) {
sparse_values_buffer_view = p_sparse_values_buffer_view;
}
int GLTFAccessor::get_sparse_values_byte_offset() {
return sparse_values_byte_offset;
}
void GLTFAccessor::set_sparse_values_byte_offset(int p_sparse_values_byte_offset) {
sparse_values_byte_offset = p_sparse_values_byte_offset;
}

View file

@ -0,0 +1,104 @@
/*************************************************************************/
/* gltf_accessor.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 GLTF_ACCESSOR_H
#define GLTF_ACCESSOR_H
#include "core/io/resource.h"
#include "gltf_document.h"
struct GLTFAccessor : public Resource {
GDCLASS(GLTFAccessor, Resource);
friend class GLTFDocument;
private:
GLTFBufferViewIndex buffer_view = 0;
int byte_offset = 0;
int component_type = 0;
bool normalized = false;
int count = 0;
GLTFDocument::GLTFType
type = GLTFDocument::TYPE_SCALAR;
Vector<double> min;
Vector<double> max;
int sparse_count = 0;
int sparse_indices_buffer_view = 0;
int sparse_indices_byte_offset = 0;
int sparse_indices_component_type = 0;
int sparse_values_buffer_view = 0;
int sparse_values_byte_offset = 0;
protected:
static void _bind_methods();
public:
GLTFBufferViewIndex get_buffer_view();
void set_buffer_view(GLTFBufferViewIndex p_buffer_view);
int get_byte_offset();
void set_byte_offset(int p_byte_offset);
int get_component_type();
void set_component_type(int p_component_type);
bool get_normalized();
void set_normalized(bool p_normalized);
int get_count();
void set_count(int p_count);
int get_type();
void set_type(int p_type);
Vector<double> get_min();
void set_min(Vector<double> p_min);
Vector<double> get_max();
void set_max(Vector<double> p_max);
int get_sparse_count();
void set_sparse_count(int p_sparse_count);
int get_sparse_indices_buffer_view();
void set_sparse_indices_buffer_view(int p_sparse_indices_buffer_view);
int get_sparse_indices_byte_offset();
void set_sparse_indices_byte_offset(int p_sparse_indices_byte_offset);
int get_sparse_indices_component_type();
void set_sparse_indices_component_type(int p_sparse_indices_component_type);
int get_sparse_values_buffer_view();
void set_sparse_values_buffer_view(int p_sparse_values_buffer_view);
int get_sparse_values_byte_offset();
void set_sparse_values_byte_offset(int p_sparse_values_byte_offset);
};
#endif // GLTF_ACCESSOR_H

View file

@ -0,0 +1,53 @@
/*************************************************************************/
/* gltf_animation.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "gltf_animation.h"
void GLTFAnimation::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_loop"), &GLTFAnimation::get_loop);
ClassDB::bind_method(D_METHOD("set_loop", "loop"), &GLTFAnimation::set_loop);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop"), "set_loop", "get_loop"); // bool
}
bool GLTFAnimation::get_loop() const {
return loop;
}
void GLTFAnimation::set_loop(bool p_val) {
loop = p_val;
}
Map<int, GLTFAnimation::Track> &GLTFAnimation::get_tracks() {
return tracks;
}
GLTFAnimation::GLTFAnimation() {
}

View file

@ -0,0 +1,74 @@
/*************************************************************************/
/* gltf_animation.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 GLTF_ANIMATION_H
#define GLTF_ANIMATION_H
#include "core/io/resource.h"
class GLTFAnimation : public Resource {
GDCLASS(GLTFAnimation, Resource);
protected:
static void _bind_methods();
public:
enum Interpolation {
INTERP_LINEAR,
INTERP_STEP,
INTERP_CATMULLROMSPLINE,
INTERP_CUBIC_SPLINE,
};
template <class T>
struct Channel {
Interpolation interpolation;
Vector<float> times;
Vector<T> values;
};
struct Track {
Channel<Vector3> translation_track;
Channel<Quat> rotation_track;
Channel<Vector3> scale_track;
Vector<Channel<float>> weight_tracks;
};
public:
bool get_loop() const;
void set_loop(bool p_val);
Map<int, GLTFAnimation::Track> &get_tracks();
GLTFAnimation();
private:
bool loop = false;
Map<int, Track> tracks;
};
#endif // GLTF_ANIMATION_H

View file

@ -0,0 +1,90 @@
/*************************************************************************/
/* gltf_buffer_view.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "gltf_buffer_view.h"
void GLTFBufferView::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_buffer"), &GLTFBufferView::get_buffer);
ClassDB::bind_method(D_METHOD("set_buffer", "buffer"), &GLTFBufferView::set_buffer);
ClassDB::bind_method(D_METHOD("get_byte_offset"), &GLTFBufferView::get_byte_offset);
ClassDB::bind_method(D_METHOD("set_byte_offset", "byte_offset"), &GLTFBufferView::set_byte_offset);
ClassDB::bind_method(D_METHOD("get_byte_length"), &GLTFBufferView::get_byte_length);
ClassDB::bind_method(D_METHOD("set_byte_length", "byte_length"), &GLTFBufferView::set_byte_length);
ClassDB::bind_method(D_METHOD("get_byte_stride"), &GLTFBufferView::get_byte_stride);
ClassDB::bind_method(D_METHOD("set_byte_stride", "byte_stride"), &GLTFBufferView::set_byte_stride);
ClassDB::bind_method(D_METHOD("get_indices"), &GLTFBufferView::get_indices);
ClassDB::bind_method(D_METHOD("set_indices", "indices"), &GLTFBufferView::set_indices);
ADD_PROPERTY(PropertyInfo(Variant::INT, "buffer"), "set_buffer", "get_buffer"); // GLTFBufferIndex
ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_offset"), "set_byte_offset", "get_byte_offset"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_length"), "set_byte_length", "get_byte_length"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "byte_stride"), "set_byte_stride", "get_byte_stride"); // int
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "indices"), "set_indices", "get_indices"); // bool
}
GLTFBufferIndex GLTFBufferView::get_buffer() {
return buffer;
}
void GLTFBufferView::set_buffer(GLTFBufferIndex p_buffer) {
buffer = p_buffer;
}
int GLTFBufferView::get_byte_offset() {
return byte_offset;
}
void GLTFBufferView::set_byte_offset(int p_byte_offset) {
byte_offset = p_byte_offset;
}
int GLTFBufferView::get_byte_length() {
return byte_length;
}
void GLTFBufferView::set_byte_length(int p_byte_length) {
byte_length = p_byte_length;
}
int GLTFBufferView::get_byte_stride() {
return byte_stride;
}
void GLTFBufferView::set_byte_stride(int p_byte_stride) {
byte_stride = p_byte_stride;
}
bool GLTFBufferView::get_indices() {
return indices;
}
void GLTFBufferView::set_indices(bool p_indices) {
indices = p_indices;
}

View file

@ -0,0 +1,68 @@
/*************************************************************************/
/* gltf_buffer_view.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 GLTF_BUFFER_VIEW_H
#define GLTF_BUFFER_VIEW_H
#include "core/io/resource.h"
#include "gltf_document.h"
class GLTFBufferView : public Resource {
GDCLASS(GLTFBufferView, Resource);
friend class GLTFDocument;
private:
GLTFBufferIndex buffer = -1;
int byte_offset = 0;
int byte_length = 0;
int byte_stride = -1;
bool indices = false;
protected:
static void _bind_methods();
public:
GLTFBufferIndex get_buffer();
void set_buffer(GLTFBufferIndex p_buffer);
int get_byte_offset();
void set_byte_offset(int p_byte_offset);
int get_byte_length();
void set_byte_length(int p_byte_length);
int get_byte_stride();
void set_byte_stride(int p_byte_stride);
bool get_indices();
void set_indices(bool p_indices);
// matrices need to be transformed to this
};
#endif // GLTF_BUFFER_VIEW_H

View file

@ -0,0 +1,47 @@
/*************************************************************************/
/* gltf_camera.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "gltf_camera.h"
void GLTFCamera::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_perspective"), &GLTFCamera::get_perspective);
ClassDB::bind_method(D_METHOD("set_perspective", "perspective"), &GLTFCamera::set_perspective);
ClassDB::bind_method(D_METHOD("get_fov_size"), &GLTFCamera::get_fov_size);
ClassDB::bind_method(D_METHOD("set_fov_size", "fov_size"), &GLTFCamera::set_fov_size);
ClassDB::bind_method(D_METHOD("get_zfar"), &GLTFCamera::get_zfar);
ClassDB::bind_method(D_METHOD("set_zfar", "zfar"), &GLTFCamera::set_zfar);
ClassDB::bind_method(D_METHOD("get_znear"), &GLTFCamera::get_znear);
ClassDB::bind_method(D_METHOD("set_znear", "znear"), &GLTFCamera::set_znear);
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::FLOAT, "zfar"), "set_zfar", "get_zfar"); // float
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "znear"), "set_znear", "get_znear"); // float
}

View file

@ -0,0 +1,58 @@
/*************************************************************************/
/* gltf_camera.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 GLTF_CAMERA_H
#define GLTF_CAMERA_H
#include "core/io/resource.h"
class GLTFCamera : public Resource {
GDCLASS(GLTFCamera, Resource);
private:
bool perspective = true;
float fov_size = 75;
float zfar = 4000;
float znear = 0.05;
protected:
static void _bind_methods();
public:
bool get_perspective() const { return perspective; }
void set_perspective(bool p_val) { perspective = p_val; }
float get_fov_size() const { return fov_size; }
void set_fov_size(float p_val) { fov_size = p_val; }
float get_zfar() const { return zfar; }
void set_zfar(float p_val) { zfar = p_val; }
float get_znear() const { return znear; }
void set_znear(float p_val) { znear = p_val; }
};
#endif // GLTF_CAMERA_H

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,427 @@
/*************************************************************************/
/* gltf_document.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 GLTF_DOCUMENT_H
#define GLTF_DOCUMENT_H
#include "editor/import/resource_importer_scene.h"
#include "editor/import/scene_importer_mesh_node_3d.h"
#include "gltf_animation.h"
#include "scene/2d/node_2d.h"
#include "scene/3d/bone_attachment_3d.h"
#include "scene/3d/light_3d.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/node_3d.h"
#include "scene/3d/skeleton_3d.h"
#include "scene/animation/animation_player.h"
#include "scene/resources/material.h"
#include "scene/resources/texture.h"
class GLTFState;
class GLTFSkin;
class GLTFNode;
class GLTFSpecGloss;
class GLTFSkeleton;
using GLTFAccessorIndex = int;
using GLTFAnimationIndex = int;
using GLTFBufferIndex = int;
using GLTFBufferViewIndex = int;
using GLTFCameraIndex = int;
using GLTFImageIndex = int;
using GLTFMaterialIndex = int;
using GLTFMeshIndex = int;
using GLTFLightIndex = int;
using GLTFNodeIndex = int;
using GLTFSkeletonIndex = int;
using GLTFSkinIndex = int;
using GLTFTextureIndex = int;
class GLTFDocument : public Resource {
GDCLASS(GLTFDocument, Resource);
friend class GLTFState;
friend class GLTFSkin;
friend class GLTFSkeleton;
public:
enum GLTFType {
TYPE_SCALAR,
TYPE_VEC2,
TYPE_VEC3,
TYPE_VEC4,
TYPE_MAT2,
TYPE_MAT3,
TYPE_MAT4,
};
enum {
ARRAY_BUFFER = 34962,
ELEMENT_ARRAY_BUFFER = 34963,
TYPE_BYTE = 5120,
TYPE_UNSIGNED_BYTE = 5121,
TYPE_SHORT = 5122,
TYPE_UNSIGNED_SHORT = 5123,
TYPE_UNSIGNED_INT = 5125,
TYPE_FLOAT = 5126,
COMPONENT_TYPE_BYTE = 5120,
COMPONENT_TYPE_UNSIGNED_BYTE = 5121,
COMPONENT_TYPE_SHORT = 5122,
COMPONENT_TYPE_UNSIGNED_SHORT = 5123,
COMPONENT_TYPE_INT = 5125,
COMPONENT_TYPE_FLOAT = 5126,
};
private:
template <class T>
static Array to_array(const Vector<T> &p_inp) {
Array ret;
for (int i = 0; i < p_inp.size(); i++) {
ret.push_back(p_inp[i]);
}
return ret;
}
template <class T>
static Array to_array(const Set<T> &p_inp) {
Array ret;
typename Set<T>::Element *elem = p_inp.front();
while (elem) {
ret.push_back(elem->get());
elem = elem->next();
}
return ret;
}
template <class T>
static void set_from_array(Vector<T> &r_out, const Array &p_inp) {
r_out.clear();
for (int i = 0; i < p_inp.size(); i++) {
r_out.push_back(p_inp[i]);
}
}
template <class T>
static void set_from_array(Set<T> &r_out, const Array &p_inp) {
r_out.clear();
for (int i = 0; i < p_inp.size(); i++) {
r_out.insert(p_inp[i]);
}
}
template <class K, class V>
static Dictionary to_dict(const Map<K, V> &p_inp) {
Dictionary ret;
for (typename Map<K, V>::Element *E = p_inp.front(); E; E = E->next()) {
ret[E->key()] = E->value();
}
return ret;
}
template <class K, class V>
static void set_from_dict(Map<K, V> &r_out, const Dictionary &p_inp) {
r_out.clear();
Array keys = p_inp.keys();
for (int i = 0; i < keys.size(); i++) {
r_out[keys[i]] = p_inp[keys[i]];
}
}
double _filter_number(double p_float);
String _get_component_type_name(const uint32_t p_component);
int _get_component_type_size(const int component_type);
Error _parse_scenes(Ref<GLTFState> state);
Error _parse_nodes(Ref<GLTFState> state);
String _get_type_name(const GLTFType p_component);
String _get_accessor_type_name(const GLTFDocument::GLTFType p_type);
String _sanitize_scene_name(const String &name);
String _gen_unique_name(Ref<GLTFState> state, const String &p_name);
String _sanitize_bone_name(const String &name);
String _gen_unique_bone_name(Ref<GLTFState> state,
const GLTFSkeletonIndex skel_i,
const String &p_name);
GLTFTextureIndex _set_texture(Ref<GLTFState> state, Ref<Texture2D> p_texture);
Ref<Texture2D> _get_texture(Ref<GLTFState> state,
const GLTFTextureIndex p_texture);
Error _parse_json(const String &p_path, Ref<GLTFState> state);
Error _parse_glb(const String &p_path, Ref<GLTFState> state);
void _compute_node_heights(Ref<GLTFState> state);
Error _parse_buffers(Ref<GLTFState> state, const String &p_base_path);
Error _parse_buffer_views(Ref<GLTFState> state);
GLTFType _get_type_from_str(const String &p_string);
Error _parse_accessors(Ref<GLTFState> state);
Error _decode_buffer_view(Ref<GLTFState> state, double *dst,
const GLTFBufferViewIndex p_buffer_view,
const int skip_every, const int skip_bytes,
const int element_size, const int count,
const GLTFType type, const int component_count,
const int component_type, const int component_size,
const bool normalized, const int byte_offset,
const bool for_vertex);
Vector<double> _decode_accessor(Ref<GLTFState> state,
const GLTFAccessorIndex p_accessor,
const bool p_for_vertex);
Vector<float> _decode_accessor_as_floats(Ref<GLTFState> state,
const GLTFAccessorIndex p_accessor,
const bool p_for_vertex);
Vector<int> _decode_accessor_as_ints(Ref<GLTFState> state,
const GLTFAccessorIndex p_accessor,
const bool p_for_vertex);
Vector<Vector2> _decode_accessor_as_vec2(Ref<GLTFState> state,
const GLTFAccessorIndex p_accessor,
const bool p_for_vertex);
Vector<Vector3> _decode_accessor_as_vec3(Ref<GLTFState> state,
const GLTFAccessorIndex p_accessor,
const bool p_for_vertex);
Vector<Color> _decode_accessor_as_color(Ref<GLTFState> state,
const GLTFAccessorIndex p_accessor,
const bool p_for_vertex);
Vector<Quat> _decode_accessor_as_quat(Ref<GLTFState> state,
const GLTFAccessorIndex p_accessor,
const bool p_for_vertex);
Vector<Transform2D> _decode_accessor_as_xform2d(Ref<GLTFState> state,
const GLTFAccessorIndex p_accessor,
const bool p_for_vertex);
Vector<Basis> _decode_accessor_as_basis(Ref<GLTFState> state,
const GLTFAccessorIndex p_accessor,
const bool p_for_vertex);
Vector<Transform> _decode_accessor_as_xform(Ref<GLTFState> state,
const GLTFAccessorIndex p_accessor,
const bool p_for_vertex);
Error _parse_meshes(Ref<GLTFState> state);
Error _serialize_textures(Ref<GLTFState> state);
Error _serialize_images(Ref<GLTFState> state, const String &p_path);
Error _serialize_lights(Ref<GLTFState> state);
Error _parse_images(Ref<GLTFState> state, const String &p_base_path);
Error _parse_textures(Ref<GLTFState> state);
Error _parse_materials(Ref<GLTFState> state);
void _set_texture_transform_uv1(const Dictionary &d, Ref<BaseMaterial3D> material);
void spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss,
Ref<BaseMaterial3D> p_material);
static void spec_gloss_to_metal_base_color(const Color &p_specular_factor,
const Color &p_diffuse,
Color &r_base_color,
float &r_metallic);
GLTFNodeIndex _find_highest_node(Ref<GLTFState> state,
const Vector<GLTFNodeIndex> &subset);
bool _capture_nodes_in_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin,
const GLTFNodeIndex node_index);
void _capture_nodes_for_multirooted_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin);
Error _expand_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin);
Error _verify_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin);
Error _parse_skins(Ref<GLTFState> state);
Error _determine_skeletons(Ref<GLTFState> state);
Error _reparent_non_joint_skeleton_subtrees(
Ref<GLTFState> state, Ref<GLTFSkeleton> skeleton,
const Vector<GLTFNodeIndex> &non_joints);
Error _reparent_to_fake_joint(Ref<GLTFState> state, Ref<GLTFSkeleton> skeleton,
const GLTFNodeIndex node_index);
Error _determine_skeleton_roots(Ref<GLTFState> state,
const GLTFSkeletonIndex skel_i);
Error _create_skeletons(Ref<GLTFState> state);
Error _map_skin_joints_indices_to_skeleton_bone_indices(Ref<GLTFState> state);
Error _serialize_skins(Ref<GLTFState> state);
Error _create_skins(Ref<GLTFState> state);
bool _skins_are_same(const Ref<Skin> skin_a, const Ref<Skin> skin_b);
void _remove_duplicate_skins(Ref<GLTFState> state);
Error _serialize_cameras(Ref<GLTFState> state);
Error _parse_cameras(Ref<GLTFState> state);
Error _parse_lights(Ref<GLTFState> state);
Error _parse_animations(Ref<GLTFState> state);
Error _serialize_animations(Ref<GLTFState> state);
BoneAttachment3D *_generate_bone_attachment(Ref<GLTFState> state,
Skeleton3D *skeleton,
const GLTFNodeIndex node_index);
EditorSceneImporterMeshNode3D *_generate_mesh_instance(Ref<GLTFState> state, Node *scene_parent, const GLTFNodeIndex node_index);
Camera3D *_generate_camera(Ref<GLTFState> state, Node *scene_parent,
const GLTFNodeIndex node_index);
Light3D *_generate_light(Ref<GLTFState> state, Node *scene_parent, const GLTFNodeIndex node_index);
Node3D *_generate_spatial(Ref<GLTFState> state, Node *scene_parent,
const GLTFNodeIndex node_index);
void _assign_scene_names(Ref<GLTFState> state);
template <class T>
T _interpolate_track(const Vector<float> &p_times, const Vector<T> &p_values,
const float p_time,
const GLTFAnimation::Interpolation p_interp);
GLTFAccessorIndex _encode_accessor_as_quats(Ref<GLTFState> state,
const Vector<Quat> p_attribs,
const bool p_for_vertex);
GLTFAccessorIndex _encode_accessor_as_weights(Ref<GLTFState> state,
const Vector<Color> p_attribs,
const bool p_for_vertex);
GLTFAccessorIndex _encode_accessor_as_joints(Ref<GLTFState> state,
const Vector<Color> p_attribs,
const bool p_for_vertex);
GLTFAccessorIndex _encode_accessor_as_floats(Ref<GLTFState> state,
const Vector<real_t> p_attribs,
const bool p_for_vertex);
GLTFAccessorIndex _encode_accessor_as_vec2(Ref<GLTFState> state,
const Vector<Vector2> p_attribs,
const bool p_for_vertex);
void _calc_accessor_vec2_min_max(int i, const int element_count, Vector<double> &type_max, Vector2 attribs, Vector<double> &type_min) {
if (i == 0) {
for (int32_t type_i = 0; type_i < element_count; type_i++) {
type_max.write[type_i] = attribs[(i * element_count) + type_i];
type_min.write[type_i] = attribs[(i * element_count) + type_i];
}
}
for (int32_t type_i = 0; type_i < element_count; type_i++) {
type_max.write[type_i] = MAX(attribs[(i * element_count) + type_i], type_max[type_i]);
type_min.write[type_i] = MIN(attribs[(i * element_count) + type_i], type_min[type_i]);
type_max.write[type_i] = _filter_number(type_max.write[type_i]);
type_min.write[type_i] = _filter_number(type_min.write[type_i]);
}
}
GLTFAccessorIndex _encode_accessor_as_vec3(Ref<GLTFState> state,
const Vector<Vector3> p_attribs,
const bool p_for_vertex);
GLTFAccessorIndex _encode_accessor_as_color(Ref<GLTFState> state,
const Vector<Color> p_attribs,
const bool p_for_vertex);
void _calc_accessor_min_max(int p_i, const int p_element_count, Vector<double> &p_type_max, Vector<double> p_attribs, Vector<double> &p_type_min);
GLTFAccessorIndex _encode_accessor_as_ints(Ref<GLTFState> state,
const Vector<int32_t> p_attribs,
const bool p_for_vertex);
GLTFAccessorIndex _encode_accessor_as_xform(Ref<GLTFState> state,
const Vector<Transform> p_attribs,
const bool p_for_vertex);
Error _encode_buffer_view(Ref<GLTFState> state, const double *src,
const int count, const GLTFType type,
const int component_type, const bool normalized,
const int byte_offset, const bool for_vertex,
GLTFBufferViewIndex &r_accessor);
Error _encode_accessors(Ref<GLTFState> state);
Error _encode_buffer_views(Ref<GLTFState> state);
Error _serialize_materials(Ref<GLTFState> state);
Error _serialize_meshes(Ref<GLTFState> state);
Error _serialize_nodes(Ref<GLTFState> state);
Error _serialize_scenes(Ref<GLTFState> state);
String interpolation_to_string(const GLTFAnimation::Interpolation p_interp);
GLTFAnimation::Track _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);
Error _encode_buffer_bins(Ref<GLTFState> state, const String &p_path);
Error _encode_buffer_glb(Ref<GLTFState> state, const String &p_path);
Error _serialize_bone_attachment(Ref<GLTFState> state);
Dictionary _serialize_texture_transform_uv1(Ref<BaseMaterial3D> p_material);
Dictionary _serialize_texture_transform_uv2(Ref<BaseMaterial3D> p_material);
Error _serialize_version(Ref<GLTFState> state);
Error _serialize_file(Ref<GLTFState> state, const String p_path);
Error _serialize_extensions(Ref<GLTFState> state) const;
public:
// http://www.itu.int/rec/R-REC-BT.601
// http://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.601-7-201103-I!!PDF-E.pdf
static constexpr float R_BRIGHTNESS_COEFF = 0.299f;
static constexpr float G_BRIGHTNESS_COEFF = 0.587f;
static constexpr float B_BRIGHTNESS_COEFF = 0.114f;
private:
// https://github.com/microsoft/glTF-SDK/blob/master/GLTFSDK/Source/PBRUtils.cpp#L9
// https://bghgary.github.io/glTF/convert-between-workflows-bjs/js/babylon.pbrUtilities.js
static float solve_metallic(float p_dielectric_specular, float diffuse,
float specular,
float p_one_minus_specular_strength);
static float get_perceived_brightness(const Color p_color);
static float get_max_component(const Color &p_color);
public:
void _process_mesh_instances(Ref<GLTFState> state, Node *scene_root);
void _generate_scene_node(Ref<GLTFState> state, Node *scene_parent,
Node3D *scene_root,
const GLTFNodeIndex node_index);
void _import_animation(Ref<GLTFState> state, AnimationPlayer *ap,
const GLTFAnimationIndex index, const int bake_fps);
GLTFMeshIndex _convert_mesh_instance(Ref<GLTFState> state,
MeshInstance3D *p_mesh_instance);
void _convert_mesh_instances(Ref<GLTFState> state);
GLTFCameraIndex _convert_camera(Ref<GLTFState> state, Camera3D *p_camera);
void _convert_light_to_gltf(Light3D *light, Ref<GLTFState> state, Node3D *spatial, Ref<GLTFNode> gltf_node);
GLTFLightIndex _convert_light(Ref<GLTFState> state, Light3D *p_light);
GLTFSkeletonIndex _convert_skeleton(Ref<GLTFState> state, Skeleton3D *p_skeleton);
void _convert_spatial(Ref<GLTFState> state, Node3D *p_spatial, Ref<GLTFNode> p_node);
void _convert_scene_node(Ref<GLTFState> state, Node *p_current, Node *p_root,
const GLTFNodeIndex p_gltf_current,
const GLTFNodeIndex p_gltf_root);
void _convert_csg_shape_to_gltf(Node *p_current, GLTFNodeIndex p_gltf_parent, Ref<GLTFNode> gltf_node, Ref<GLTFState> state);
void _create_gltf_node(Ref<GLTFState> state,
Node *p_scene_parent,
GLTFNodeIndex current_node_i,
GLTFNodeIndex p_parent_node_index,
GLTFNodeIndex p_root_gltf_node,
Ref<GLTFNode> gltf_node);
void _convert_animation_player_to_gltf(
AnimationPlayer *animation_player, Ref<GLTFState> state,
const GLTFNodeIndex &p_gltf_current,
const GLTFNodeIndex &p_gltf_root_index,
Ref<GLTFNode> p_gltf_node, Node *p_scene_parent,
Node *p_root);
void _check_visibility(Node *p_node, bool &retflag);
void _convert_camera_to_gltf(Camera3D *camera, Ref<GLTFState> state,
Node3D *spatial,
Ref<GLTFNode> gltf_node);
void _convert_grid_map_to_gltf(
Node *p_scene_parent,
const GLTFNodeIndex &p_parent_node_index,
const GLTFNodeIndex &p_root_node_index,
Ref<GLTFNode> gltf_node, Ref<GLTFState> state,
Node *p_root_node);
void _convert_mult_mesh_instance_to_gltf(
Node *p_scene_parent,
const GLTFNodeIndex &p_parent_node_index,
const GLTFNodeIndex &p_root_node_index,
Ref<GLTFNode> gltf_node, Ref<GLTFState> state,
Node *p_root_node);
void _convert_skeleton_to_gltf(
Node *p_scene_parent, Ref<GLTFState> state,
const GLTFNodeIndex &p_parent_node_index,
const GLTFNodeIndex &p_root_node_index,
Ref<GLTFNode> gltf_node, Node *p_root_node);
void _convert_bone_attachment_to_gltf(Node *p_scene_parent,
Ref<GLTFState> state,
Ref<GLTFNode> gltf_node,
bool &retflag);
void _convert_mesh_to_gltf(Node *p_scene_parent,
Ref<GLTFState> state, Node3D *spatial,
Ref<GLTFNode> gltf_node);
void _convert_animation(Ref<GLTFState> state, AnimationPlayer *ap,
String p_animation_track_name);
Error serialize(Ref<GLTFState> state, Node *p_root, const String &p_path);
Error parse(Ref<GLTFState> state, String p_paths, bool p_read_binary = false);
};
#endif // GLTF_DOCUMENT_H

101
modules/gltf/gltf_light.cpp Normal file
View file

@ -0,0 +1,101 @@
/*************************************************************************/
/* gltf_light.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "gltf_light.h"
void GLTFLight::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_color"), &GLTFLight::get_color);
ClassDB::bind_method(D_METHOD("set_color", "color"), &GLTFLight::set_color);
ClassDB::bind_method(D_METHOD("get_intensity"), &GLTFLight::get_intensity);
ClassDB::bind_method(D_METHOD("set_intensity", "intensity"), &GLTFLight::set_intensity);
ClassDB::bind_method(D_METHOD("get_type"), &GLTFLight::get_type);
ClassDB::bind_method(D_METHOD("set_type", "type"), &GLTFLight::set_type);
ClassDB::bind_method(D_METHOD("get_range"), &GLTFLight::get_range);
ClassDB::bind_method(D_METHOD("set_range", "range"), &GLTFLight::set_range);
ClassDB::bind_method(D_METHOD("get_inner_cone_angle"), &GLTFLight::get_inner_cone_angle);
ClassDB::bind_method(D_METHOD("set_inner_cone_angle", "inner_cone_angle"), &GLTFLight::set_inner_cone_angle);
ClassDB::bind_method(D_METHOD("get_outer_cone_angle"), &GLTFLight::get_outer_cone_angle);
ClassDB::bind_method(D_METHOD("set_outer_cone_angle", "outer_cone_angle"), &GLTFLight::set_outer_cone_angle);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color"); // Color
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "intensity"), "set_intensity", "get_intensity"); // float
ADD_PROPERTY(PropertyInfo(Variant::STRING, "type"), "set_type", "get_type"); // String
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "range"), "set_range", "get_range"); // float
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inner_cone_angle"), "set_inner_cone_angle", "get_inner_cone_angle"); // float
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "outer_cone_angle"), "set_outer_cone_angle", "get_outer_cone_angle"); // float
}
Color GLTFLight::get_color() {
return color;
}
void GLTFLight::set_color(Color p_color) {
color = p_color;
}
float GLTFLight::get_intensity() {
return intensity;
}
void GLTFLight::set_intensity(float p_intensity) {
intensity = p_intensity;
}
String GLTFLight::get_type() {
return type;
}
void GLTFLight::set_type(String p_type) {
type = p_type;
}
float GLTFLight::get_range() {
return range;
}
void GLTFLight::set_range(float p_range) {
range = p_range;
}
float GLTFLight::get_inner_cone_angle() {
return inner_cone_angle;
}
void GLTFLight::set_inner_cone_angle(float p_inner_cone_angle) {
inner_cone_angle = p_inner_cone_angle;
}
float GLTFLight::get_outer_cone_angle() {
return outer_cone_angle;
}
void GLTFLight::set_outer_cone_angle(float p_outer_cone_angle) {
outer_cone_angle = p_outer_cone_angle;
}

72
modules/gltf/gltf_light.h Normal file
View file

@ -0,0 +1,72 @@
/*************************************************************************/
/* gltf_light.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 GLTF_LIGHT_H
#define GLTF_LIGHT_H
#include "core/config/engine.h"
#include "core/io/resource.h"
class GLTFLight : public Resource {
GDCLASS(GLTFLight, Resource)
friend class GLTFDocument;
protected:
static void _bind_methods();
private:
Color color;
float intensity = 0.0f;
String type;
float range = 0.0f;
float inner_cone_angle = 0.0f;
float outer_cone_angle = 0.0f;
public:
Color get_color();
void set_color(Color p_color);
float get_intensity();
void set_intensity(float p_intensity);
String get_type();
void set_type(String p_type);
float get_range();
void set_range(float p_range);
float get_inner_cone_angle();
void set_inner_cone_angle(float p_inner_cone_angle);
float get_outer_cone_angle();
void set_outer_cone_angle(float p_outer_cone_angle);
};
#endif // GLTF_LIGHT_H

View file

@ -0,0 +1,58 @@
/*************************************************************************/
/* gltf_mesh.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "gltf_mesh.h"
#include "editor/import/scene_importer_mesh.h"
void GLTFMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_mesh"), &GLTFMesh::get_mesh);
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &GLTFMesh::set_mesh);
ClassDB::bind_method(D_METHOD("get_blend_weights"), &GLTFMesh::get_blend_weights);
ClassDB::bind_method(D_METHOD("set_blend_weights", "blend_weights"), &GLTFMesh::set_blend_weights);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "EditorSceneImporterMesh"), "set_mesh", "get_mesh");
ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT32_ARRAY, "blend_weights"), "set_blend_weights", "get_blend_weights"); // Vector<float>
}
Ref<EditorSceneImporterMesh> GLTFMesh::get_mesh() {
return mesh;
}
void GLTFMesh::set_mesh(Ref<EditorSceneImporterMesh> p_mesh) {
mesh = p_mesh;
}
Vector<float> GLTFMesh::get_blend_weights() {
return blend_weights;
}
void GLTFMesh::set_blend_weights(Vector<float> p_blend_weights) {
blend_weights = p_blend_weights;
}

55
modules/gltf/gltf_mesh.h Normal file
View file

@ -0,0 +1,55 @@
/*************************************************************************/
/* gltf_mesh.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 GLTF_MESH_H
#define GLTF_MESH_H
#include "core/io/resource.h"
#include "editor/import/resource_importer_scene.h"
#include "editor/import/scene_importer_mesh.h"
#include "scene/resources/mesh.h"
class GLTFMesh : public Resource {
GDCLASS(GLTFMesh, Resource);
private:
Ref<EditorSceneImporterMesh> mesh;
Vector<float> blend_weights;
protected:
static void _bind_methods();
public:
Ref<EditorSceneImporterMesh> get_mesh();
void set_mesh(Ref<EditorSceneImporterMesh> p_mesh);
Vector<float> get_blend_weights();
void set_blend_weights(Vector<float> p_blend_weights);
};
#endif // GLTF_MESH_H

189
modules/gltf/gltf_node.cpp Normal file
View file

@ -0,0 +1,189 @@
/*************************************************************************/
/* gltf_node.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "gltf_node.h"
void GLTFNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_parent"), &GLTFNode::get_parent);
ClassDB::bind_method(D_METHOD("set_parent", "parent"), &GLTFNode::set_parent);
ClassDB::bind_method(D_METHOD("get_height"), &GLTFNode::get_height);
ClassDB::bind_method(D_METHOD("set_height", "height"), &GLTFNode::set_height);
ClassDB::bind_method(D_METHOD("get_xform"), &GLTFNode::get_xform);
ClassDB::bind_method(D_METHOD("set_xform", "xform"), &GLTFNode::set_xform);
ClassDB::bind_method(D_METHOD("get_mesh"), &GLTFNode::get_mesh);
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &GLTFNode::set_mesh);
ClassDB::bind_method(D_METHOD("get_camera"), &GLTFNode::get_camera);
ClassDB::bind_method(D_METHOD("set_camera", "camera"), &GLTFNode::set_camera);
ClassDB::bind_method(D_METHOD("get_skin"), &GLTFNode::get_skin);
ClassDB::bind_method(D_METHOD("set_skin", "skin"), &GLTFNode::set_skin);
ClassDB::bind_method(D_METHOD("get_skeleton"), &GLTFNode::get_skeleton);
ClassDB::bind_method(D_METHOD("set_skeleton", "skeleton"), &GLTFNode::set_skeleton);
ClassDB::bind_method(D_METHOD("get_joint"), &GLTFNode::get_joint);
ClassDB::bind_method(D_METHOD("set_joint", "joint"), &GLTFNode::set_joint);
ClassDB::bind_method(D_METHOD("get_translation"), &GLTFNode::get_translation);
ClassDB::bind_method(D_METHOD("set_translation", "translation"), &GLTFNode::set_translation);
ClassDB::bind_method(D_METHOD("get_rotation"), &GLTFNode::get_rotation);
ClassDB::bind_method(D_METHOD("set_rotation", "rotation"), &GLTFNode::set_rotation);
ClassDB::bind_method(D_METHOD("get_scale"), &GLTFNode::get_scale);
ClassDB::bind_method(D_METHOD("set_scale", "scale"), &GLTFNode::set_scale);
ClassDB::bind_method(D_METHOD("get_children"), &GLTFNode::get_children);
ClassDB::bind_method(D_METHOD("set_children", "children"), &GLTFNode::set_children);
ClassDB::bind_method(D_METHOD("get_fake_joint_parent"), &GLTFNode::get_fake_joint_parent);
ClassDB::bind_method(D_METHOD("set_fake_joint_parent", "fake_joint_parent"), &GLTFNode::set_fake_joint_parent);
ClassDB::bind_method(D_METHOD("get_light"), &GLTFNode::get_light);
ClassDB::bind_method(D_METHOD("set_light", "light"), &GLTFNode::set_light);
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::TRANSFORM, "xform"), "set_xform", "get_xform"); // Transform
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, "skin"), "set_skin", "get_skin"); // GLTFSkinIndex
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::VECTOR3, "translation"), "set_translation", "get_translation"); // Vector3
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::PACKED_INT32_ARRAY, "children"), "set_children", "get_children"); // Vector<int>
ADD_PROPERTY(PropertyInfo(Variant::INT, "fake_joint_parent"), "set_fake_joint_parent", "get_fake_joint_parent"); // GLTFNodeIndex
ADD_PROPERTY(PropertyInfo(Variant::INT, "light"), "set_light", "get_light"); // GLTFLightIndex
}
GLTFNodeIndex GLTFNode::get_parent() {
return parent;
}
void GLTFNode::set_parent(GLTFNodeIndex p_parent) {
parent = p_parent;
}
int GLTFNode::get_height() {
return height;
}
void GLTFNode::set_height(int p_height) {
height = p_height;
}
Transform GLTFNode::get_xform() {
return xform;
}
void GLTFNode::set_xform(Transform p_xform) {
xform = p_xform;
}
GLTFMeshIndex GLTFNode::get_mesh() {
return mesh;
}
void GLTFNode::set_mesh(GLTFMeshIndex p_mesh) {
mesh = p_mesh;
}
GLTFCameraIndex GLTFNode::get_camera() {
return camera;
}
void GLTFNode::set_camera(GLTFCameraIndex p_camera) {
camera = p_camera;
}
GLTFSkinIndex GLTFNode::get_skin() {
return skin;
}
void GLTFNode::set_skin(GLTFSkinIndex p_skin) {
skin = p_skin;
}
GLTFSkeletonIndex GLTFNode::get_skeleton() {
return skeleton;
}
void GLTFNode::set_skeleton(GLTFSkeletonIndex p_skeleton) {
skeleton = p_skeleton;
}
bool GLTFNode::get_joint() {
return joint;
}
void GLTFNode::set_joint(bool p_joint) {
joint = p_joint;
}
Vector3 GLTFNode::get_translation() {
return translation;
}
void GLTFNode::set_translation(Vector3 p_translation) {
translation = p_translation;
}
Quat GLTFNode::get_rotation() {
return rotation;
}
void GLTFNode::set_rotation(Quat p_rotation) {
rotation = p_rotation;
}
Vector3 GLTFNode::get_scale() {
return scale;
}
void GLTFNode::set_scale(Vector3 p_scale) {
scale = p_scale;
}
Vector<int> GLTFNode::get_children() {
return children;
}
void GLTFNode::set_children(Vector<int> p_children) {
children = p_children;
}
GLTFNodeIndex GLTFNode::get_fake_joint_parent() {
return fake_joint_parent;
}
void GLTFNode::set_fake_joint_parent(GLTFNodeIndex p_fake_joint_parent) {
fake_joint_parent = p_fake_joint_parent;
}
GLTFLightIndex GLTFNode::get_light() {
return light;
}
void GLTFNode::set_light(GLTFLightIndex p_light) {
light = p_light;
}

105
modules/gltf/gltf_node.h Normal file
View file

@ -0,0 +1,105 @@
/*************************************************************************/
/* gltf_node.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 GLTF_NODE_H
#define GLTF_NODE_H
#include "core/io/resource.h"
#include "gltf_document.h"
class GLTFNode : public Resource {
GDCLASS(GLTFNode, Resource);
friend class GLTFDocument;
friend class PackedSceneGLTF;
private:
// matrices need to be transformed to this
GLTFNodeIndex parent = -1;
int height = -1;
Transform xform;
GLTFMeshIndex mesh = -1;
GLTFCameraIndex camera = -1;
GLTFSkinIndex skin = -1;
GLTFSkeletonIndex skeleton = -1;
bool joint = false;
Vector3 translation;
Quat rotation;
Vector3 scale = Vector3(1, 1, 1);
Vector<int> children;
GLTFNodeIndex fake_joint_parent = -1;
GLTFLightIndex light = -1;
protected:
static void _bind_methods();
public:
GLTFNodeIndex get_parent();
void set_parent(GLTFNodeIndex p_parent);
int get_height();
void set_height(int p_height);
Transform get_xform();
void set_xform(Transform p_xform);
GLTFMeshIndex get_mesh();
void set_mesh(GLTFMeshIndex p_mesh);
GLTFCameraIndex get_camera();
void set_camera(GLTFCameraIndex p_camera);
GLTFSkinIndex get_skin();
void set_skin(GLTFSkinIndex p_skin);
GLTFSkeletonIndex get_skeleton();
void set_skeleton(GLTFSkeletonIndex p_skeleton);
bool get_joint();
void set_joint(bool p_joint);
Vector3 get_translation();
void set_translation(Vector3 p_translation);
Quat get_rotation();
void set_rotation(Quat p_rotation);
Vector3 get_scale();
void set_scale(Vector3 p_scale);
Vector<int> get_children();
void set_children(Vector<int> p_children);
GLTFNodeIndex get_fake_joint_parent();
void set_fake_joint_parent(GLTFNodeIndex p_fake_joint_parent);
GLTFLightIndex get_light();
void set_light(GLTFLightIndex p_light);
};
#endif // GLTF_NODE_H

View file

@ -0,0 +1,95 @@
/*************************************************************************/
/* gltf_skeleton.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "gltf_skeleton.h"
void GLTFSkeleton::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_joints"), &GLTFSkeleton::get_joints);
ClassDB::bind_method(D_METHOD("set_joints", "joints"), &GLTFSkeleton::set_joints);
ClassDB::bind_method(D_METHOD("get_roots"), &GLTFSkeleton::get_roots);
ClassDB::bind_method(D_METHOD("set_roots", "roots"), &GLTFSkeleton::set_roots);
ClassDB::bind_method(D_METHOD("get_godot_skeleton"), &GLTFSkeleton::get_godot_skeleton);
ClassDB::bind_method(D_METHOD("get_unique_names"), &GLTFSkeleton::get_unique_names);
ClassDB::bind_method(D_METHOD("set_unique_names", "unique_names"), &GLTFSkeleton::set_unique_names);
ClassDB::bind_method(D_METHOD("get_godot_bone_node"), &GLTFSkeleton::get_godot_bone_node);
ClassDB::bind_method(D_METHOD("set_godot_bone_node", "godot_bone_node"), &GLTFSkeleton::set_godot_bone_node);
ClassDB::bind_method(D_METHOD("get_bone_attachment_count"), &GLTFSkeleton::get_bone_attachment_count);
ClassDB::bind_method(D_METHOD("get_bone_attachment"), &GLTFSkeleton::get_bone_attachment);
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_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::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"); // Map<int32_t,
}
Vector<GLTFNodeIndex> GLTFSkeleton::get_joints() {
return joints;
}
void GLTFSkeleton::set_joints(Vector<GLTFNodeIndex> p_joints) {
joints = p_joints;
}
Vector<GLTFNodeIndex> GLTFSkeleton::get_roots() {
return roots;
}
void GLTFSkeleton::set_roots(Vector<GLTFNodeIndex> p_roots) {
roots = p_roots;
}
Skeleton3D *GLTFSkeleton::get_godot_skeleton() {
return godot_skeleton;
}
Array GLTFSkeleton::get_unique_names() {
return GLTFDocument::to_array(unique_names);
}
void GLTFSkeleton::set_unique_names(Array p_unique_names) {
GLTFDocument::set_from_array(unique_names, p_unique_names);
}
Dictionary GLTFSkeleton::get_godot_bone_node() {
return GLTFDocument::to_dict(godot_bone_node);
}
void GLTFSkeleton::set_godot_bone_node(Dictionary p_indict) {
GLTFDocument::set_from_dict(godot_bone_node, p_indict);
}
BoneAttachment3D *GLTFSkeleton::get_bone_attachment(int idx) {
ERR_FAIL_INDEX_V(idx, bone_attachments.size(), nullptr);
return bone_attachments[idx];
}
int32_t GLTFSkeleton::get_bone_attachment_count() {
return bone_attachments.size();
}

View file

@ -0,0 +1,101 @@
/*************************************************************************/
/* gltf_skeleton.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 GLTF_SKELETON_H
#define GLTF_SKELETON_H
#include "core/io/resource.h"
#include "gltf_document.h"
class GLTFSkeleton : public Resource {
GDCLASS(GLTFSkeleton, Resource);
friend class GLTFDocument;
private:
// The *synthesized* skeletons joints
Vector<GLTFNodeIndex> joints;
// The roots of the skeleton. If there are multiple, each root must have the
// same parent (ie roots are siblings)
Vector<GLTFNodeIndex> roots;
// The created Skeleton3D for the scene
Skeleton3D *godot_skeleton = nullptr;
// Set of unique bone names for the skeleton
Set<String> unique_names;
Map<int32_t, GLTFNodeIndex> godot_bone_node;
Vector<BoneAttachment3D *> bone_attachments;
protected:
static void _bind_methods();
public:
Vector<GLTFNodeIndex> get_joints();
void set_joints(Vector<GLTFNodeIndex> p_joints);
Vector<GLTFNodeIndex> get_roots();
void set_roots(Vector<GLTFNodeIndex> p_roots);
Skeleton3D *get_godot_skeleton();
// Skeleton *get_godot_skeleton() {
// return this->godot_skeleton;
// }
// void set_godot_skeleton(Skeleton p_*godot_skeleton) {
// this->godot_skeleton = p_godot_skeleton;
// }
Array get_unique_names();
void set_unique_names(Array p_unique_names);
//Map<int32_t, GLTFNodeIndex> get_godot_bone_node() {
// return this->godot_bone_node;
//}
//void set_godot_bone_node(Map<int32_t, GLTFNodeIndex> p_godot_bone_node) {
// this->godot_bone_node = p_godot_bone_node;
//}
Dictionary get_godot_bone_node();
void set_godot_bone_node(Dictionary p_indict);
//Dictionary get_godot_bone_node() {
// return VariantConversion::to_dict(this->godot_bone_node);
//}
//void set_godot_bone_node(Dictionary p_indict) {
// VariantConversion::set_from_dict(this->godot_bone_node, p_indict);
//}
BoneAttachment3D *get_bone_attachment(int idx);
int32_t get_bone_attachment_count();
};
#endif // GLTF_SKELETON_H

155
modules/gltf/gltf_skin.cpp Normal file
View file

@ -0,0 +1,155 @@
/*************************************************************************/
/* gltf_skin.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "gltf_skin.h"
void GLTFSkin::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_skin_root"), &GLTFSkin::get_skin_root);
ClassDB::bind_method(D_METHOD("set_skin_root", "skin_root"), &GLTFSkin::set_skin_root);
ClassDB::bind_method(D_METHOD("get_joints_original"), &GLTFSkin::get_joints_original);
ClassDB::bind_method(D_METHOD("set_joints_original", "joints_original"), &GLTFSkin::set_joints_original);
ClassDB::bind_method(D_METHOD("get_inverse_binds"), &GLTFSkin::get_inverse_binds);
ClassDB::bind_method(D_METHOD("set_inverse_binds", "inverse_binds"), &GLTFSkin::set_inverse_binds);
ClassDB::bind_method(D_METHOD("get_joints"), &GLTFSkin::get_joints);
ClassDB::bind_method(D_METHOD("set_joints", "joints"), &GLTFSkin::set_joints);
ClassDB::bind_method(D_METHOD("get_non_joints"), &GLTFSkin::get_non_joints);
ClassDB::bind_method(D_METHOD("set_non_joints", "non_joints"), &GLTFSkin::set_non_joints);
ClassDB::bind_method(D_METHOD("get_roots"), &GLTFSkin::get_roots);
ClassDB::bind_method(D_METHOD("set_roots", "roots"), &GLTFSkin::set_roots);
ClassDB::bind_method(D_METHOD("get_skeleton"), &GLTFSkin::get_skeleton);
ClassDB::bind_method(D_METHOD("set_skeleton", "skeleton"), &GLTFSkin::set_skeleton);
ClassDB::bind_method(D_METHOD("get_joint_i_to_bone_i"), &GLTFSkin::get_joint_i_to_bone_i);
ClassDB::bind_method(D_METHOD("set_joint_i_to_bone_i", "joint_i_to_bone_i"), &GLTFSkin::set_joint_i_to_bone_i);
ClassDB::bind_method(D_METHOD("get_joint_i_to_name"), &GLTFSkin::get_joint_i_to_name);
ClassDB::bind_method(D_METHOD("set_joint_i_to_name", "joint_i_to_name"), &GLTFSkin::set_joint_i_to_name);
ClassDB::bind_method(D_METHOD("get_godot_skin"), &GLTFSkin::get_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::PACKED_INT32_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<Transform>
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_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::PACKED_INT32_ARRAY, "roots"), "set_roots", "get_roots"); // Vector<GLTFNodeIndex>
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"); // Map<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"); // Map<int,
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "godot_skin"), "set_godot_skin", "get_godot_skin"); // Ref<Skin>
}
GLTFNodeIndex GLTFSkin::get_skin_root() {
return skin_root;
}
void GLTFSkin::set_skin_root(GLTFNodeIndex p_skin_root) {
skin_root = p_skin_root;
}
Vector<GLTFNodeIndex> GLTFSkin::get_joints_original() {
return joints_original;
}
void GLTFSkin::set_joints_original(Vector<GLTFNodeIndex> p_joints_original) {
joints_original = p_joints_original;
}
Array GLTFSkin::get_inverse_binds() {
return GLTFDocument::to_array(inverse_binds);
}
void GLTFSkin::set_inverse_binds(Array p_inverse_binds) {
GLTFDocument::set_from_array(inverse_binds, p_inverse_binds);
}
Vector<GLTFNodeIndex> GLTFSkin::get_joints() {
return joints;
}
void GLTFSkin::set_joints(Vector<GLTFNodeIndex> p_joints) {
joints = p_joints;
}
Vector<GLTFNodeIndex> GLTFSkin::get_non_joints() {
return non_joints;
}
void GLTFSkin::set_non_joints(Vector<GLTFNodeIndex> p_non_joints) {
non_joints = p_non_joints;
}
Vector<GLTFNodeIndex> GLTFSkin::get_roots() {
return roots;
}
void GLTFSkin::set_roots(Vector<GLTFNodeIndex> p_roots) {
roots = p_roots;
}
int GLTFSkin::get_skeleton() {
return skeleton;
}
void GLTFSkin::set_skeleton(int p_skeleton) {
skeleton = p_skeleton;
}
Dictionary GLTFSkin::get_joint_i_to_bone_i() {
return GLTFDocument::to_dict(joint_i_to_bone_i);
}
void GLTFSkin::set_joint_i_to_bone_i(Dictionary p_joint_i_to_bone_i) {
GLTFDocument::set_from_dict(joint_i_to_bone_i, p_joint_i_to_bone_i);
}
Dictionary GLTFSkin::get_joint_i_to_name() {
Dictionary ret;
Map<int, StringName>::Element *elem = joint_i_to_name.front();
while (elem) {
ret[elem->key()] = String(elem->value());
elem = elem->next();
}
return ret;
}
void GLTFSkin::set_joint_i_to_name(Dictionary p_joint_i_to_name) {
joint_i_to_name = Map<int, StringName>();
Array keys = p_joint_i_to_name.keys();
for (int i = 0; i < keys.size(); i++) {
joint_i_to_name[keys[i]] = joint_i_to_name[keys[i]];
}
}
Ref<Skin> GLTFSkin::get_godot_skin() {
return godot_skin;
}
void GLTFSkin::set_godot_skin(Ref<Skin> p_godot_skin) {
godot_skin = p_godot_skin;
}

109
modules/gltf/gltf_skin.h Normal file
View file

@ -0,0 +1,109 @@
/*************************************************************************/
/* gltf_skin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 GLTF_SKIN_H
#define GLTF_SKIN_H
#include "core/io/resource.h"
#include "gltf_document.h"
class GLTFSkin : public Resource {
GDCLASS(GLTFSkin, Resource);
friend class GLTFDocument;
private:
// The "skeleton" property defined in the gltf spec. -1 = Scene Root
GLTFNodeIndex skin_root = -1;
Vector<GLTFNodeIndex> joints_original;
Vector<Transform> inverse_binds;
// Note: joints + non_joints should form a complete subtree, or subtrees
// with a common parent
// All nodes that are skins that are caught in-between the original joints
// (inclusive of joints_original)
Vector<GLTFNodeIndex> joints;
// All Nodes that are caught in-between skin joint nodes, and are not
// defined as joints by any skin
Vector<GLTFNodeIndex> non_joints;
// The roots of the skin. In the case of multiple roots, their parent *must*
// be the same (the roots must be siblings)
Vector<GLTFNodeIndex> roots;
// The GLTF Skeleton this Skin points to (after we determine skeletons)
GLTFSkeletonIndex skeleton = -1;
// A mapping from the joint indices (in the order of joints_original) to the
// Godot Skeleton's bone_indices
Map<int, int> joint_i_to_bone_i;
Map<int, StringName> joint_i_to_name;
// The Actual Skin that will be created as a mapping between the IBM's of
// this skin to the generated skeleton for the mesh instances.
Ref<Skin> godot_skin;
protected:
static void _bind_methods();
public:
GLTFNodeIndex get_skin_root();
void set_skin_root(GLTFNodeIndex p_skin_root);
Vector<GLTFNodeIndex> get_joints_original();
void set_joints_original(Vector<GLTFNodeIndex> p_joints_original);
Array get_inverse_binds();
void set_inverse_binds(Array p_inverse_binds);
Vector<GLTFNodeIndex> get_joints();
void set_joints(Vector<GLTFNodeIndex> p_joints);
Vector<GLTFNodeIndex> get_non_joints();
void set_non_joints(Vector<GLTFNodeIndex> p_non_joints);
Vector<GLTFNodeIndex> get_roots();
void set_roots(Vector<GLTFNodeIndex> p_roots);
int get_skeleton();
void set_skeleton(int p_skeleton);
Dictionary get_joint_i_to_bone_i();
void set_joint_i_to_bone_i(Dictionary p_joint_i_to_bone_i);
Dictionary get_joint_i_to_name();
void set_joint_i_to_name(Dictionary p_joint_i_to_name);
Ref<Skin> get_godot_skin();
void set_godot_skin(Ref<Skin> p_godot_skin);
};
#endif // GLTF_SKIN_H

View file

@ -0,0 +1,90 @@
/*************************************************************************/
/* gltf_spec_gloss.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "gltf_spec_gloss.h"
void GLTFSpecGloss::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_diffuse_img"), &GLTFSpecGloss::get_diffuse_img);
ClassDB::bind_method(D_METHOD("set_diffuse_img", "diffuse_img"), &GLTFSpecGloss::set_diffuse_img);
ClassDB::bind_method(D_METHOD("get_diffuse_factor"), &GLTFSpecGloss::get_diffuse_factor);
ClassDB::bind_method(D_METHOD("set_diffuse_factor", "diffuse_factor"), &GLTFSpecGloss::set_diffuse_factor);
ClassDB::bind_method(D_METHOD("get_gloss_factor"), &GLTFSpecGloss::get_gloss_factor);
ClassDB::bind_method(D_METHOD("set_gloss_factor", "gloss_factor"), &GLTFSpecGloss::set_gloss_factor);
ClassDB::bind_method(D_METHOD("get_specular_factor"), &GLTFSpecGloss::get_specular_factor);
ClassDB::bind_method(D_METHOD("set_specular_factor", "specular_factor"), &GLTFSpecGloss::set_specular_factor);
ClassDB::bind_method(D_METHOD("get_spec_gloss_img"), &GLTFSpecGloss::get_spec_gloss_img);
ClassDB::bind_method(D_METHOD("set_spec_gloss_img", "spec_gloss_img"), &GLTFSpecGloss::set_spec_gloss_img);
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::FLOAT, "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::OBJECT, "spec_gloss_img"), "set_spec_gloss_img", "get_spec_gloss_img"); // Ref<Image>
}
Ref<Image> GLTFSpecGloss::get_diffuse_img() {
return diffuse_img;
}
void GLTFSpecGloss::set_diffuse_img(Ref<Image> p_diffuse_img) {
diffuse_img = p_diffuse_img;
}
Color GLTFSpecGloss::get_diffuse_factor() {
return diffuse_factor;
}
void GLTFSpecGloss::set_diffuse_factor(Color p_diffuse_factor) {
diffuse_factor = p_diffuse_factor;
}
float GLTFSpecGloss::get_gloss_factor() {
return gloss_factor;
}
void GLTFSpecGloss::set_gloss_factor(float p_gloss_factor) {
gloss_factor = p_gloss_factor;
}
Color GLTFSpecGloss::get_specular_factor() {
return specular_factor;
}
void GLTFSpecGloss::set_specular_factor(Color p_specular_factor) {
specular_factor = p_specular_factor;
}
Ref<Image> GLTFSpecGloss::get_spec_gloss_img() {
return spec_gloss_img;
}
void GLTFSpecGloss::set_spec_gloss_img(Ref<Image> p_spec_gloss_img) {
spec_gloss_img = p_spec_gloss_img;
}

View file

@ -0,0 +1,67 @@
/*************************************************************************/
/* gltf_spec_gloss.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 GLTF_SPEC_GLOSS_H
#define GLTF_SPEC_GLOSS_H
#include "core/io/image.h"
#include "core/io/resource.h"
class GLTFSpecGloss : public Resource {
GDCLASS(GLTFSpecGloss, Resource);
friend class GLTFDocument;
private:
Ref<Image> diffuse_img = nullptr;
Color diffuse_factor = Color(1.0f, 1.0f, 1.0f);
float gloss_factor = 1.0f;
Color specular_factor = Color(1.0f, 1.0f, 1.0f);
Ref<Image> spec_gloss_img = nullptr;
protected:
static void _bind_methods();
public:
Ref<Image> get_diffuse_img();
void set_diffuse_img(Ref<Image> p_diffuse_img);
Color get_diffuse_factor();
void set_diffuse_factor(Color p_diffuse_factor);
float get_gloss_factor();
void set_gloss_factor(float p_gloss_factor);
Color get_specular_factor();
void set_specular_factor(Color p_specular_factor);
Ref<Image> get_spec_gloss_img();
void set_spec_gloss_img(Ref<Image> p_spec_gloss_img);
};
#endif // GLTF_SPEC_GLOSS_H

296
modules/gltf/gltf_state.cpp Normal file
View file

@ -0,0 +1,296 @@
/*************************************************************************/
/* gltf_state.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "gltf_state.h"
void GLTFState::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_json"), &GLTFState::get_json);
ClassDB::bind_method(D_METHOD("set_json", "json"), &GLTFState::set_json);
ClassDB::bind_method(D_METHOD("get_major_version"), &GLTFState::get_major_version);
ClassDB::bind_method(D_METHOD("set_major_version", "major_version"), &GLTFState::set_major_version);
ClassDB::bind_method(D_METHOD("get_minor_version"), &GLTFState::get_minor_version);
ClassDB::bind_method(D_METHOD("set_minor_version", "minor_version"), &GLTFState::set_minor_version);
ClassDB::bind_method(D_METHOD("get_glb_data"), &GLTFState::get_glb_data);
ClassDB::bind_method(D_METHOD("set_glb_data", "glb_data"), &GLTFState::set_glb_data);
ClassDB::bind_method(D_METHOD("get_use_named_skin_binds"), &GLTFState::get_use_named_skin_binds);
ClassDB::bind_method(D_METHOD("set_use_named_skin_binds", "use_named_skin_binds"), &GLTFState::set_use_named_skin_binds);
ClassDB::bind_method(D_METHOD("get_nodes"), &GLTFState::get_nodes);
ClassDB::bind_method(D_METHOD("set_nodes", "nodes"), &GLTFState::set_nodes);
ClassDB::bind_method(D_METHOD("get_buffers"), &GLTFState::get_buffers);
ClassDB::bind_method(D_METHOD("set_buffers", "buffers"), &GLTFState::set_buffers);
ClassDB::bind_method(D_METHOD("get_buffer_views"), &GLTFState::get_buffer_views);
ClassDB::bind_method(D_METHOD("set_buffer_views", "buffer_views"), &GLTFState::set_buffer_views);
ClassDB::bind_method(D_METHOD("get_accessors"), &GLTFState::get_accessors);
ClassDB::bind_method(D_METHOD("set_accessors", "accessors"), &GLTFState::set_accessors);
ClassDB::bind_method(D_METHOD("get_meshes"), &GLTFState::get_meshes);
ClassDB::bind_method(D_METHOD("set_meshes", "meshes"), &GLTFState::set_meshes);
ClassDB::bind_method(D_METHOD("get_animation_players_count"), &GLTFState::get_animation_players_count);
ClassDB::bind_method(D_METHOD("get_animation_player"), &GLTFState::get_animation_player);
ClassDB::bind_method(D_METHOD("get_materials"), &GLTFState::get_materials);
ClassDB::bind_method(D_METHOD("set_materials", "materials"), &GLTFState::set_materials);
ClassDB::bind_method(D_METHOD("get_scene_name"), &GLTFState::get_scene_name);
ClassDB::bind_method(D_METHOD("set_scene_name", "scene_name"), &GLTFState::set_scene_name);
ClassDB::bind_method(D_METHOD("get_root_nodes"), &GLTFState::get_root_nodes);
ClassDB::bind_method(D_METHOD("set_root_nodes", "root_nodes"), &GLTFState::set_root_nodes);
ClassDB::bind_method(D_METHOD("get_textures"), &GLTFState::get_textures);
ClassDB::bind_method(D_METHOD("set_textures", "textures"), &GLTFState::set_textures);
ClassDB::bind_method(D_METHOD("get_images"), &GLTFState::get_images);
ClassDB::bind_method(D_METHOD("set_images", "images"), &GLTFState::set_images);
ClassDB::bind_method(D_METHOD("get_skins"), &GLTFState::get_skins);
ClassDB::bind_method(D_METHOD("set_skins", "skins"), &GLTFState::set_skins);
ClassDB::bind_method(D_METHOD("get_cameras"), &GLTFState::get_cameras);
ClassDB::bind_method(D_METHOD("set_cameras", "cameras"), &GLTFState::set_cameras);
ClassDB::bind_method(D_METHOD("get_lights"), &GLTFState::get_lights);
ClassDB::bind_method(D_METHOD("set_lights", "lights"), &GLTFState::set_lights);
ClassDB::bind_method(D_METHOD("get_unique_names"), &GLTFState::get_unique_names);
ClassDB::bind_method(D_METHOD("set_unique_names", "unique_names"), &GLTFState::set_unique_names);
ClassDB::bind_method(D_METHOD("get_skeletons"), &GLTFState::get_skeletons);
ClassDB::bind_method(D_METHOD("set_skeletons", "skeletons"), &GLTFState::set_skeletons);
ClassDB::bind_method(D_METHOD("get_skeleton_to_node"), &GLTFState::get_skeleton_to_node);
ClassDB::bind_method(D_METHOD("set_skeleton_to_node", "skeleton_to_node"), &GLTFState::set_skeleton_to_node);
ClassDB::bind_method(D_METHOD("get_animations"), &GLTFState::get_animations);
ClassDB::bind_method(D_METHOD("set_animations", "animations"), &GLTFState::set_animations);
ClassDB::bind_method(D_METHOD("get_scene_node"), &GLTFState::get_scene_node);
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "json"), "set_json", "get_json"); // Dictionary
ADD_PROPERTY(PropertyInfo(Variant::INT, "major_version"), "set_major_version", "get_major_version"); // int
ADD_PROPERTY(PropertyInfo(Variant::INT, "minor_version"), "set_minor_version", "get_minor_version"); // int
ADD_PROPERTY(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "glb_data"), "set_glb_data", "get_glb_data"); // Vector<uint8_t>
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_named_skin_binds"), "set_use_named_skin_binds", "get_use_named_skin_binds"); // bool
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "nodes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_nodes", "get_nodes"); // Vector<Ref<GLTFNode>>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "buffers"), "set_buffers", "get_buffers"); // Vector<Vector<uint8_t>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "buffer_views", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_buffer_views", "get_buffer_views"); // Vector<Ref<GLTFBufferView>>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "accessors", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_accessors", "get_accessors"); // Vector<Ref<GLTFAccessor>>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "meshes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_meshes", "get_meshes"); // Vector<Ref<GLTFMesh>>
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::PACKED_INT32_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, "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, "cameras", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_cameras", "get_cameras"); // Vector<Ref<GLTFCamera>>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "lights", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_lights", "get_lights"); // Vector<Ref<GLTFLight>>
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, "skeletons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skeletons", "get_skeletons"); // Vector<Ref<GLTFSkeleton>>
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "skeleton_to_node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skeleton_to_node", "get_skeleton_to_node"); // Map<GLTFSkeletonIndex,
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "animations", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_animations", "get_animations"); // Vector<Ref<GLTFAnimation>>
}
Dictionary GLTFState::get_json() {
return json;
}
void GLTFState::set_json(Dictionary p_json) {
json = p_json;
}
int GLTFState::get_major_version() {
return major_version;
}
void GLTFState::set_major_version(int p_major_version) {
major_version = p_major_version;
}
int GLTFState::get_minor_version() {
return minor_version;
}
void GLTFState::set_minor_version(int p_minor_version) {
minor_version = p_minor_version;
}
Vector<uint8_t> GLTFState::get_glb_data() {
return glb_data;
}
void GLTFState::set_glb_data(Vector<uint8_t> p_glb_data) {
glb_data = p_glb_data;
}
bool GLTFState::get_use_named_skin_binds() {
return use_named_skin_binds;
}
void GLTFState::set_use_named_skin_binds(bool p_use_named_skin_binds) {
use_named_skin_binds = p_use_named_skin_binds;
}
Array GLTFState::get_nodes() {
return GLTFDocument::to_array(nodes);
}
void GLTFState::set_nodes(Array p_nodes) {
GLTFDocument::set_from_array(nodes, p_nodes);
}
Array GLTFState::get_buffers() {
return GLTFDocument::to_array(buffers);
}
void GLTFState::set_buffers(Array p_buffers) {
GLTFDocument::set_from_array(buffers, p_buffers);
}
Array GLTFState::get_buffer_views() {
return GLTFDocument::to_array(buffer_views);
}
void GLTFState::set_buffer_views(Array p_buffer_views) {
GLTFDocument::set_from_array(buffer_views, p_buffer_views);
}
Array GLTFState::get_accessors() {
return GLTFDocument::to_array(accessors);
}
void GLTFState::set_accessors(Array p_accessors) {
GLTFDocument::set_from_array(accessors, p_accessors);
}
Array GLTFState::get_meshes() {
return GLTFDocument::to_array(meshes);
}
void GLTFState::set_meshes(Array p_meshes) {
GLTFDocument::set_from_array(meshes, p_meshes);
}
Array GLTFState::get_materials() {
return GLTFDocument::to_array(materials);
}
void GLTFState::set_materials(Array p_materials) {
GLTFDocument::set_from_array(materials, p_materials);
}
String GLTFState::get_scene_name() {
return scene_name;
}
void GLTFState::set_scene_name(String p_scene_name) {
scene_name = p_scene_name;
}
Array GLTFState::get_root_nodes() {
return GLTFDocument::to_array(root_nodes);
}
void GLTFState::set_root_nodes(Array p_root_nodes) {
GLTFDocument::set_from_array(root_nodes, p_root_nodes);
}
Array GLTFState::get_textures() {
return GLTFDocument::to_array(textures);
}
void GLTFState::set_textures(Array p_textures) {
GLTFDocument::set_from_array(textures, p_textures);
}
Array GLTFState::get_images() {
return GLTFDocument::to_array(images);
}
void GLTFState::set_images(Array p_images) {
GLTFDocument::set_from_array(images, p_images);
}
Array GLTFState::get_skins() {
return GLTFDocument::to_array(skins);
}
void GLTFState::set_skins(Array p_skins) {
GLTFDocument::set_from_array(skins, p_skins);
}
Array GLTFState::get_cameras() {
return GLTFDocument::to_array(cameras);
}
void GLTFState::set_cameras(Array p_cameras) {
GLTFDocument::set_from_array(cameras, p_cameras);
}
Array GLTFState::get_lights() {
return GLTFDocument::to_array(lights);
}
void GLTFState::set_lights(Array p_lights) {
GLTFDocument::set_from_array(lights, p_lights);
}
Array GLTFState::get_unique_names() {
return GLTFDocument::to_array(unique_names);
}
void GLTFState::set_unique_names(Array p_unique_names) {
GLTFDocument::set_from_array(unique_names, p_unique_names);
}
Array GLTFState::get_skeletons() {
return GLTFDocument::to_array(skeletons);
}
void GLTFState::set_skeletons(Array p_skeletons) {
GLTFDocument::set_from_array(skeletons, p_skeletons);
}
Dictionary GLTFState::get_skeleton_to_node() {
return GLTFDocument::to_dict(skeleton_to_node);
}
void GLTFState::set_skeleton_to_node(Dictionary p_skeleton_to_node) {
GLTFDocument::set_from_dict(skeleton_to_node, p_skeleton_to_node);
}
Array GLTFState::get_animations() {
return GLTFDocument::to_array(animations);
}
void GLTFState::set_animations(Array p_animations) {
GLTFDocument::set_from_array(animations, p_animations);
}
Node *GLTFState::get_scene_node(GLTFNodeIndex idx) {
if (!scene_nodes.has(idx)) {
return nullptr;
}
return scene_nodes[idx];
}
int GLTFState::get_animation_players_count(int idx) {
return animation_players.size();
}
AnimationPlayer *GLTFState::get_animation_player(int idx) {
ERR_FAIL_INDEX_V(idx, animation_players.size(), nullptr);
return animation_players[idx];
}

180
modules/gltf/gltf_state.h Normal file
View file

@ -0,0 +1,180 @@
/*************************************************************************/
/* gltf_state.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 GLTF_STATE_H
#define GLTF_STATE_H
#include "core/io/resource.h"
#include "core/templates/vector.h"
#include "editor_scene_importer_gltf.h"
#include "gltf_accessor.h"
#include "gltf_animation.h"
#include "gltf_buffer_view.h"
#include "gltf_camera.h"
#include "gltf_document.h"
#include "gltf_light.h"
#include "gltf_mesh.h"
#include "gltf_node.h"
#include "gltf_skeleton.h"
#include "gltf_skin.h"
#include "gltf_texture.h"
#include "scene/animation/animation_player.h"
#include "scene/resources/texture.h"
class GLTFState : public Resource {
GDCLASS(GLTFState, Resource);
friend class GLTFDocument;
friend class PackedSceneGLTF;
Dictionary json;
int major_version = 0;
int minor_version = 0;
Vector<uint8_t> glb_data;
bool use_named_skin_binds = false;
Vector<Ref<GLTFNode>> nodes;
Vector<Vector<uint8_t>> buffers;
Vector<Ref<GLTFBufferView>> buffer_views;
Vector<Ref<GLTFAccessor>> accessors;
Vector<Ref<GLTFMesh>> meshes; // meshes are loaded directly, no reason not to.
Vector<AnimationPlayer *> animation_players;
Map<Ref<BaseMaterial3D>, GLTFMaterialIndex> material_cache;
Vector<Ref<BaseMaterial3D>> materials;
String scene_name;
Vector<int> root_nodes;
Vector<Ref<GLTFTexture>> textures;
Vector<Ref<Texture2D>> images;
Vector<Ref<GLTFSkin>> skins;
Vector<Ref<GLTFCamera>> cameras;
Vector<Ref<GLTFLight>> lights;
Set<String> unique_names;
Vector<Ref<GLTFSkeleton>> skeletons;
Map<GLTFSkeletonIndex, GLTFNodeIndex> skeleton_to_node;
Vector<Ref<GLTFAnimation>> animations;
Map<GLTFNodeIndex, Node *> scene_nodes;
protected:
static void _bind_methods();
public:
Dictionary get_json();
void set_json(Dictionary p_json);
int get_major_version();
void set_major_version(int p_major_version);
int get_minor_version();
void set_minor_version(int p_minor_version);
Vector<uint8_t> get_glb_data();
void set_glb_data(Vector<uint8_t> p_glb_data);
bool get_use_named_skin_binds();
void set_use_named_skin_binds(bool p_use_named_skin_binds);
Array get_nodes();
void set_nodes(Array p_nodes);
Array get_buffers();
void set_buffers(Array p_buffers);
Array get_buffer_views();
void set_buffer_views(Array p_buffer_views);
Array get_accessors();
void set_accessors(Array p_accessors);
Array get_meshes();
void set_meshes(Array p_meshes);
Array get_materials();
void set_materials(Array p_materials);
String get_scene_name();
void set_scene_name(String p_scene_name);
Array get_root_nodes();
void set_root_nodes(Array p_root_nodes);
Array get_textures();
void set_textures(Array p_textures);
Array get_images();
void set_images(Array p_images);
Array get_skins();
void set_skins(Array p_skins);
Array get_cameras();
void set_cameras(Array p_cameras);
Array get_lights();
void set_lights(Array p_lights);
Array get_unique_names();
void set_unique_names(Array p_unique_names);
Array get_skeletons();
void set_skeletons(Array p_skeletons);
Dictionary get_skeleton_to_node();
void set_skeleton_to_node(Dictionary p_skeleton_to_node);
Array get_animations();
void set_animations(Array p_animations);
Node *get_scene_node(GLTFNodeIndex idx);
int get_animation_players_count(int idx);
AnimationPlayer *get_animation_player(int idx);
//void set_scene_nodes(Map<GLTFNodeIndex, Node *> p_scene_nodes) {
// this->scene_nodes = p_scene_nodes;
//}
//void set_animation_players(Vector<AnimationPlayer *> p_animation_players) {
// this->animation_players = p_animation_players;
//}
//Map<Ref<Material>, GLTFMaterialIndex> get_material_cache() {
// return this->material_cache;
//}
//void set_material_cache(Map<Ref<Material>, GLTFMaterialIndex> p_material_cache) {
// this->material_cache = p_material_cache;
//}
};
#endif // GLTF_STATE_H

View file

@ -0,0 +1,46 @@
/*************************************************************************/
/* gltf_texture.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "gltf_texture.h"
void GLTFTexture::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_src_image"), &GLTFTexture::get_src_image);
ClassDB::bind_method(D_METHOD("set_src_image", "src_image"), &GLTFTexture::set_src_image);
ADD_PROPERTY(PropertyInfo(Variant::INT, "src_image"), "set_src_image", "get_src_image"); // int
}
GLTFImageIndex GLTFTexture::get_src_image() const {
return src_image;
}
void GLTFTexture::set_src_image(GLTFImageIndex val) {
src_image = val;
}

View file

@ -0,0 +1,51 @@
/*************************************************************************/
/* gltf_texture.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 GLTF_TEXTURE_H
#define GLTF_TEXTURE_H
#include "core/io/resource.h"
#include "gltf_document.h"
class GLTFTexture : public Resource {
GDCLASS(GLTFTexture, Resource);
private:
GLTFImageIndex src_image;
protected:
static void _bind_methods();
public:
GLTFImageIndex get_src_image() const;
void set_src_image(GLTFImageIndex val);
};
#endif // GLTF_TEXTURE_H

View file

@ -0,0 +1,88 @@
/*************************************************************************/
/* register_types.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#include "register_types.h"
#include "editor/editor_node.h"
#include "editor_scene_exporter_gltf_plugin.h"
#include "editor_scene_importer_gltf.h"
#include "gltf_accessor.h"
#include "gltf_animation.h"
#include "gltf_buffer_view.h"
#include "gltf_camera.h"
#include "gltf_document.h"
#include "gltf_light.h"
#include "gltf_mesh.h"
#include "gltf_node.h"
#include "gltf_skeleton.h"
#include "gltf_skin.h"
#include "gltf_spec_gloss.h"
#include "gltf_state.h"
#include "gltf_texture.h"
#ifndef _3D_DISABLED
#ifdef TOOLS_ENABLED
static void _editor_init() {
Ref<EditorSceneImporterGLTF> import_gltf;
import_gltf.instance();
ResourceImporterScene::get_singleton()->add_importer(import_gltf);
}
#endif
#endif
void register_gltf_types() {
#ifndef _3D_DISABLED
#ifdef TOOLS_ENABLED
ClassDB::register_class<EditorSceneImporterGLTF>();
ClassDB::APIType prev_api = ClassDB::get_current_api();
ClassDB::set_current_api(ClassDB::API_EDITOR);
EditorPlugins::add_by_type<SceneExporterGLTFPlugin>();
ClassDB::set_current_api(prev_api);
EditorNode::add_init_callback(_editor_init);
#endif
ClassDB::register_class<GLTFSpecGloss>();
ClassDB::register_class<GLTFNode>();
ClassDB::register_class<GLTFAnimation>();
ClassDB::register_class<GLTFBufferView>();
ClassDB::register_class<GLTFAccessor>();
ClassDB::register_class<GLTFTexture>();
ClassDB::register_class<GLTFSkeleton>();
ClassDB::register_class<GLTFSkin>();
ClassDB::register_class<GLTFMesh>();
ClassDB::register_class<GLTFCamera>();
ClassDB::register_class<GLTFLight>();
ClassDB::register_class<GLTFState>();
ClassDB::register_class<GLTFDocument>();
ClassDB::register_class<PackedSceneGLTF>();
#endif
}
void unregister_gltf_types() {
}

View file

@ -0,0 +1,32 @@
/*************************************************************************/
/* register_types.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
void register_gltf_types();
void unregister_gltf_types();