Skip to content

Commit

Permalink
Create gltf module.
Browse files Browse the repository at this point in the history
Add initial editor saver plugin and resource saver scene.

Begin EditorSceneSaverGLTF.

Rename to save scene and save animation.

Rename get save flags for saving.

Initial work on save scene and save animation.
Move editor scene saver gltf and its plugin out.

Work on EditorSceneExporter.

Keep the exporter names in sync.
Extract EditorSceneImporterGLTF into a GLTFDocument.


Extract gltf_document.


Work on export from gltf documents.


Work on _generate_gltf_scene.


Work on _convert_mesh_instance.


Convert camera and convert spatial.


Link children and parents of a gltf node.


Improve _convert_mesh_instances.


Can export json.


Export basic gltf2 nodes without meshes.


Initial all elements of the matrix array.


Stub encoding accessor.


Create a stub of _encode_accessor.


Checkpoint.


Scene shows.


Can see triangles now!


Can now duplicate meshes.


Default byte_stride to -1.


Need to cascade change to byte_stride.


Add normals, uv1 and uv2.


Add tangent, weight_0 and bone_0.


Avoid crashing in uvs.


Serialize materials.


Avoid crashes and improve materials.


A mesh instances has meshes, not just array meshes.


Avoid crashes.


Partial material support.


Save to folders.


If the material is transparent, set it as blend.


Support more materials.


Tangents must be reordered.


Size must be greater than zero.


Don't process mesh_instances twice.


Revert "Tangents must be reordered."

This reverts commit 70e0e53a3854973f1e02cac1da88bcb2517cd281.

Remove joints and weights.


Cleanup.


Remove old code from savers and exporters.


Divide the gltf classes that are serializing and converting.


Add copyrights.


Whitespace changes.


Whitespace.


Whitespace.


Code cleanup from cicd.


Cleanup.


Whitespace.


Fixing cicd errors.


Error is not being used.


CICD errors.


CICD fixes.


Restore GDCLASS on resource saver.


Don't double nest the root node.


Avoid material crash.


Don't need to set gltf parent.


Don't lose root node.


Create hierarchy for skeleton.


Better skeleton.


Restore skins.


Add work on skins.

Buggy.
Disable skeletal animation for now.


Revert "Disable skeletal animation for now."

This reverts commit 1dc939c753ec7f249d4a065384386f2e273f414b.

Disable skeletal animation.


Whitespace changes.


Handle materials in mesh instancce and geometry material overrides.

Whitespace changes.

Images array cannot be empty.

Restore animations and bugfix scene conversion.

Disable animations.

Set the skeleton node to have the global transform removed.

Revert "Set the skeleton node to have the global transform removed."

This reverts commit f4a9b5e79af6938ec05d1d9e3b30a06c200f6a7e.

Revert "Disable animations."

This reverts commit 15513b7d2c113d7b4110b8daebebc988a1d8ab45.

Support blend shapes.


Add wip.


Bugfixes.


Restore blend shape support.


Add error message.


Better blend supports.


Whitespace.


Avoid code warnings.


Duplicate and reown removed the top node.


Break apart matrix.


Remove duplication of code in _convert_scene_node.


Change textures to srgb.


Undo correction.


Skins work!


Whitespace.


Skeleton skins meshes.


Use a type that exists on windows.


numerical limit of min is not lowest.


Redo max and min accessor values.


Change accessors for encoding.


Checkin wip.


Fix normalization math and don't normalize.


Disable animations.


Consistently use get_rotation_quat.


Avoid warnings.


Normalizing weights is not needed.


Handle empty materials.


Indices is a boolean value.


Save tangent directly.


Avoid gltf validation errors.


Avoid invalid camera data in the nodes.


Bugfixes

Stepify matrix to avoid min and max float problems. Normalize tangent and normals.
Add some storage for bone to node mappings and node to parent mappings.


Add a material cache.


Make more robust.


Renumber comments.


Support all meshes not just array meshes.


Support gridmaps.


The scene does not have extra nodes now.


Save only visible nodes.


Cleanup skeletons.


Make the code less messy by storing the skeleton to node mapping.


Remove the duplication of the skeleton node.


Cleanup and make bone animations work.


Avoid variable shadowing.


Remove comment.


Cleanup and support blend shape animations.


Cleanup.


Cleanup parenting logic.


Find mesh or skeleton by name.


Use full paths again to get nodes.
  • Loading branch information
fire committed Dec 8, 2019
1 parent 8eb183a commit 2cafc0d
Show file tree
Hide file tree
Showing 27 changed files with 7,814 additions and 3,134 deletions.
426 changes: 426 additions & 0 deletions core/io/resource_exporter.cpp

Large diffs are not rendered by default.

138 changes: 138 additions & 0 deletions core/io/resource_exporter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*************************************************************************/
/* resource_exporter.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 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 RESOURCE_EXPORTER_H
#define RESOURCE_EXPORTER_H

#include "core/io/resource_loader.h"
#include "resource_saver.h"

class ResourceExporter;

class ResourceFormatExporter : public ResourceFormatSaver {

struct PathAndType {
String path;
String type;
String exporter;
String group_file;
Variant metadata;
};

Error _get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid = NULL) const;

static ResourceFormatExporter *singleton;

//need them to stay in order to compute the settings hash
struct SortExporterByName {
bool operator()(const Ref<ResourceExporter> &p_a, const Ref<ResourceExporter> &p_b) const;
};

Vector<Ref<ResourceExporter> > exporters;

public:
static ResourceFormatExporter *get_singleton() { return singleton; }
virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
virtual void get_recognized_exporter_extensions(List<String> *p_extensions) const;
virtual void get_recognized_exporter_extensions_for_type(const String &p_type, List<String> *p_extensions) const;
virtual bool recognize_path(const String &p_path) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
virtual Variant get_resource_metadata(const String &p_path) const;
virtual bool is_export_valid(const String &p_path) const;
virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
virtual bool is_exported(const String &p_path) const { return recognize_path(p_path); }
//TODO
virtual String get_export_group_file(const String &p_path) const;
virtual bool exists(const String &p_path) const;
//TODO
virtual bool can_be_exported(const String &p_path) const;
//TODO
virtual int get_export_order(const String &p_path) const;

String get_internal_resource_path(const String &p_path) const;
void get_internal_resource_path_list(const String &p_path, List<String> *r_paths);

void add_exporter(const Ref<ResourceExporter> &p_exporter) {
exporters.push_back(p_exporter);
}
void remove_exporter(const Ref<ResourceExporter> &p_exporter) { exporters.erase(p_exporter); }
Ref<ResourceExporter> get_exporter_by_name(const String &p_name) const;
Ref<ResourceExporter> get_exporter_by_extension(const String &p_extension) const;
void get_exporters_for_extension(const String &p_extension, List<Ref<ResourceExporter> > *r_exporters);

bool are_export_settings_valid(const String &p_path) const;
//TODO
String get_export_settings_hash() const;
//TODO
String get_export_base_path(const String &p_for_file) const;
ResourceFormatExporter();
~ResourceFormatExporter() {}
};

class ResourceExporter : public Reference {

GDCLASS(ResourceExporter, Reference);

public:
virtual String get_exporter_name() const = 0;
virtual String get_visible_name() const = 0;
virtual void get_recognized_extensions(List<String> *p_extensions) const = 0;
virtual String get_save_extension() const = 0;
virtual String get_resource_type() const = 0;
virtual float get_priority() const { return 1.0; }
virtual int get_export_order() const { return 0; }

struct ExportOption {
PropertyInfo option;
Variant default_value;

ExportOption(const PropertyInfo &p_info, const Variant &p_default) :
option(p_info),
default_value(p_default) {
}
ExportOption() {}
};

virtual int get_preset_count() const { return 0; }
virtual String get_preset_name(int p_idx) const { return String(); }

virtual void get_export_options(List<ExportOption> *r_options, int p_preset = 0) const = 0;
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const = 0;
virtual String get_option_group_file() const { return String(); }

virtual Error export_(Node *p_node, const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL) = 0;

virtual Error export_group_file(const String &p_group_file, const Map<String, Map<StringName, Variant> > &p_source_file_options, const Map<String, String> &p_base_paths) { return ERR_UNAVAILABLE; }
virtual bool are_export_settings_valid(const String &p_path) const { return true; }
virtual String get_export_settings_string() const { return String(); }
};

#endif // RESOURCE_EXPORTER_H
4 changes: 4 additions & 0 deletions core/io/resource_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ int ResourceSaver::saver_count = 0;
bool ResourceSaver::timestamp_on_save = false;
ResourceSavedCallback ResourceSaver::save_callback = 0;

bool ResourceFormatSaver::recognize_path(const String &p_path) const {
return FileAccess::exists(p_path);
}

Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {

if (get_script_instance() && get_script_instance()->has_method("save")) {
Expand Down
7 changes: 5 additions & 2 deletions core/io/resource_saver.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#ifndef RESOURCE_SAVER_H
#define RESOURCE_SAVER_H

#include "core/io/resource_saver.h"
#include "core/os/file_access.h"
#include "core/resource.h"

class ResourceFormatSaver : public Reference {
Expand All @@ -42,15 +44,16 @@ class ResourceFormatSaver : public Reference {
public:
virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
virtual bool recognize(const RES &p_resource) const;
virtual bool recognize_path(const String &p_path) const;
virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const;

virtual ~ResourceFormatSaver() {}
};

typedef void (*ResourceSavedCallback)(Ref<Resource> p_resource, const String &p_path);

class ResourceSaver {

class ResourceSaver : public Reference {
GDCLASS(ResourceSaver, Reference);
enum {
MAX_SAVERS = 64
};
Expand Down
8 changes: 8 additions & 0 deletions core/register_core_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "core/io/packet_peer.h"
#include "core/io/packet_peer_udp.h"
#include "core/io/pck_packer.h"
#include "core/io/resource_exporter.h"
#include "core/io/resource_format_binary.h"
#include "core/io/resource_importer.h"
#include "core/io/stream_peer_ssl.h"
Expand All @@ -70,6 +71,7 @@
static Ref<ResourceFormatSaverBinary> resource_saver_binary;
static Ref<ResourceFormatLoaderBinary> resource_loader_binary;
static Ref<ResourceFormatImporter> resource_format_importer;
static Ref<ResourceFormatExporter> resource_format_exporter;
static Ref<ResourceFormatLoaderImage> resource_format_image;
static Ref<TranslationLoaderPO> resource_format_po;
static Ref<ResourceFormatSaverCrypto> resource_format_saver_crypto;
Expand Down Expand Up @@ -121,6 +123,9 @@ void register_core_types() {
resource_format_importer.instance();
ResourceLoader::add_resource_format_loader(resource_format_importer);

resource_format_exporter.instance();
ResourceSaver::add_resource_format_saver(resource_format_exporter);

resource_format_image.instance();
ResourceLoader::add_resource_format_loader(resource_format_image);

Expand Down Expand Up @@ -288,6 +293,9 @@ void unregister_core_types() {
ResourceLoader::remove_resource_format_loader(resource_format_importer);
resource_format_importer.unref();

ResourceSaver::remove_resource_format_saver(resource_format_exporter);
resource_format_exporter.unref();

ResourceLoader::remove_resource_format_loader(resource_format_po);
resource_format_po.unref();

Expand Down
1 change: 1 addition & 0 deletions editor/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ if env['tools']:
SConscript('fileserver/SCsub')
SConscript('icons/SCsub')
SConscript('import/SCsub')
SConscript('saver/SCsub')
SConscript('plugins/SCsub')

lib = env.add_library("editor", env.editor_sources)
Expand Down
11 changes: 6 additions & 5 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "scene/resources/packed_scene.h"
#include "servers/physics_2d_server.h"

#include "core/io/resource_exporter.h"
#include "editor/editor_audio_buses.h"
#include "editor/editor_file_system.h"
#include "editor/editor_help.h"
Expand All @@ -60,7 +61,6 @@
#include "editor/editor_spin_slider.h"
#include "editor/editor_themes.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"
Expand Down Expand Up @@ -130,6 +130,7 @@
#include "editor/plugins/visual_shader_editor_plugin.h"
#include "editor/pvrtc_compress.h"
#include "editor/register_exporters.h"
#include "editor/saver/resource_saver_scene.h"
#include "editor/script_editor_debugger.h"

#include <stdio.h>
Expand Down Expand Up @@ -5636,15 +5637,15 @@ 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);
}

Ref<ResourceExporterScene> export_scene;
export_scene.instance();
ResourceFormatExporter::get_singleton()->add_exporter(export_scene);

Ref<ResourceImporterBitMap> import_bitmap;
import_bitmap.instance();
ResourceFormatImporter::get_singleton()->add_importer(import_bitmap);
Expand Down
Loading

0 comments on commit 2cafc0d

Please sign in to comment.