mirror of
https://github.com/Relintai/pandemonium_engine_minimal.git
synced 2025-01-26 03:09:18 +01:00
Removed the editor modules.
This commit is contained in:
parent
e8d085a315
commit
e0d729967a
@ -268,7 +268,7 @@ env_base["platform"] = selected_platform # Must always be re-set after calling
|
||||
|
||||
# Detect modules.
|
||||
modules_detected = OrderedDict()
|
||||
module_search_paths = [ "modules", methods.convert_custom_modules_path("editor_modules") ] # Built-in path.
|
||||
module_search_paths = [ "modules" ] # Built-in path.
|
||||
|
||||
# maybe?
|
||||
#if env_base["tools"]:
|
||||
|
@ -1,32 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
Import("env")
|
||||
Import("env_modules")
|
||||
|
||||
env_cvtt = env_modules.Clone()
|
||||
|
||||
# Thirdparty source files
|
||||
|
||||
thirdparty_obj = []
|
||||
|
||||
thirdparty_dir = "#thirdparty/cvtt/"
|
||||
thirdparty_sources = ["ConvectionKernels.cpp"]
|
||||
|
||||
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
|
||||
|
||||
env_cvtt.Prepend(CPPPATH=[thirdparty_dir])
|
||||
|
||||
env_thirdparty = env_cvtt.Clone()
|
||||
env_thirdparty.disable_warnings()
|
||||
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
|
||||
env.modules_sources += thirdparty_obj
|
||||
|
||||
# Pandemonium source files
|
||||
|
||||
module_obj = []
|
||||
|
||||
env_cvtt.add_source_files(module_obj, "*.cpp")
|
||||
env.modules_sources += module_obj
|
||||
|
||||
# Needed to force rebuilding the module files when the thirdparty library is updated.
|
||||
env.Depends(module_obj, thirdparty_obj)
|
@ -1,6 +0,0 @@
|
||||
def can_build(env, platform):
|
||||
return env["tools"]
|
||||
|
||||
|
||||
def configure(env):
|
||||
pass
|
@ -1,396 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* image_compress_cvtt.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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 "image_compress_cvtt.h"
|
||||
|
||||
#include "core/os/os.h"
|
||||
#include "core/os/thread.h"
|
||||
#include "core/string/print_string.h"
|
||||
#include "core/os/safe_refcount.h"
|
||||
|
||||
#include <ConvectionKernels.h>
|
||||
|
||||
struct CVTTCompressionJobParams {
|
||||
bool is_hdr;
|
||||
bool is_signed;
|
||||
int bytes_per_pixel;
|
||||
|
||||
cvtt::Options options;
|
||||
};
|
||||
|
||||
struct CVTTCompressionRowTask {
|
||||
const uint8_t *in_mm_bytes;
|
||||
uint8_t *out_mm_bytes;
|
||||
int y_start;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
struct CVTTCompressionJobQueue {
|
||||
CVTTCompressionJobParams job_params;
|
||||
const CVTTCompressionRowTask *job_tasks;
|
||||
uint32_t num_tasks;
|
||||
SafeNumeric<uint32_t> current_task;
|
||||
};
|
||||
|
||||
static void _digest_row_task(const CVTTCompressionJobParams &p_job_params, const CVTTCompressionRowTask &p_row_task) {
|
||||
const uint8_t *in_bytes = p_row_task.in_mm_bytes;
|
||||
uint8_t *out_bytes = p_row_task.out_mm_bytes;
|
||||
int w = p_row_task.width;
|
||||
int h = p_row_task.height;
|
||||
|
||||
int y_start = p_row_task.y_start;
|
||||
int y_end = y_start + 4;
|
||||
|
||||
int bytes_per_pixel = p_job_params.bytes_per_pixel;
|
||||
bool is_hdr = p_job_params.is_hdr;
|
||||
bool is_signed = p_job_params.is_signed;
|
||||
|
||||
cvtt::PixelBlockU8 input_blocks_ldr[cvtt::NumParallelBlocks];
|
||||
cvtt::PixelBlockF16 input_blocks_hdr[cvtt::NumParallelBlocks];
|
||||
|
||||
for (int x_start = 0; x_start < w; x_start += 4 * cvtt::NumParallelBlocks) {
|
||||
int x_end = x_start + 4 * cvtt::NumParallelBlocks;
|
||||
|
||||
for (int y = y_start; y < y_end; y++) {
|
||||
int first_input_element = (y - y_start) * 4;
|
||||
const uint8_t *row_start;
|
||||
if (y >= h) {
|
||||
row_start = in_bytes + (h - 1) * (w * bytes_per_pixel);
|
||||
} else {
|
||||
row_start = in_bytes + y * (w * bytes_per_pixel);
|
||||
}
|
||||
|
||||
for (int x = x_start; x < x_end; x++) {
|
||||
const uint8_t *pixel_start;
|
||||
if (x >= w) {
|
||||
pixel_start = row_start + (w - 1) * bytes_per_pixel;
|
||||
} else {
|
||||
pixel_start = row_start + x * bytes_per_pixel;
|
||||
}
|
||||
|
||||
int block_index = (x - x_start) / 4;
|
||||
int block_element = (x - x_start) % 4 + first_input_element;
|
||||
if (is_hdr) {
|
||||
memcpy(input_blocks_hdr[block_index].m_pixels[block_element], pixel_start, bytes_per_pixel);
|
||||
input_blocks_hdr[block_index].m_pixels[block_element][3] = 0x3c00; // 1.0 (unused)
|
||||
} else {
|
||||
memcpy(input_blocks_ldr[block_index].m_pixels[block_element], pixel_start, bytes_per_pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t output_blocks[16 * cvtt::NumParallelBlocks];
|
||||
|
||||
if (is_hdr) {
|
||||
if (is_signed) {
|
||||
cvtt::Kernels::EncodeBC6HS(output_blocks, input_blocks_hdr, p_job_params.options);
|
||||
} else {
|
||||
cvtt::Kernels::EncodeBC6HU(output_blocks, input_blocks_hdr, p_job_params.options);
|
||||
}
|
||||
} else {
|
||||
cvtt::Kernels::EncodeBC7(output_blocks, input_blocks_ldr, p_job_params.options);
|
||||
}
|
||||
|
||||
unsigned int num_real_blocks = ((w - x_start) + 3) / 4;
|
||||
if (num_real_blocks > cvtt::NumParallelBlocks) {
|
||||
num_real_blocks = cvtt::NumParallelBlocks;
|
||||
}
|
||||
|
||||
memcpy(out_bytes, output_blocks, 16 * num_real_blocks);
|
||||
out_bytes += 16 * num_real_blocks;
|
||||
}
|
||||
}
|
||||
|
||||
static void _digest_job_queue(void *p_job_queue) {
|
||||
CVTTCompressionJobQueue *job_queue = static_cast<CVTTCompressionJobQueue *>(p_job_queue);
|
||||
|
||||
for (uint32_t next_task = job_queue->current_task.increment(); next_task <= job_queue->num_tasks; next_task = job_queue->current_task.increment()) {
|
||||
_digest_row_task(job_queue->job_params, job_queue->job_tasks[next_task - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
void image_compress_cvtt(Image *p_image, float p_lossy_quality, Image::CompressSource p_source) {
|
||||
if (p_image->get_format() >= Image::FORMAT_BPTC_RGBA) {
|
||||
return; //do not compress, already compressed
|
||||
}
|
||||
|
||||
int w = p_image->get_width();
|
||||
int h = p_image->get_height();
|
||||
|
||||
bool is_ldr = (p_image->get_format() <= Image::FORMAT_RGBA8);
|
||||
bool is_hdr = (p_image->get_format() >= Image::FORMAT_RH) && (p_image->get_format() <= Image::FORMAT_RGBE9995);
|
||||
|
||||
if (!is_ldr && !is_hdr) {
|
||||
return; // Not a usable source format
|
||||
}
|
||||
|
||||
cvtt::Options options;
|
||||
uint32_t flags = cvtt::Flags::Fastest;
|
||||
|
||||
if (p_lossy_quality > 0.85) {
|
||||
flags = cvtt::Flags::Ultra;
|
||||
} else if (p_lossy_quality > 0.75) {
|
||||
flags = cvtt::Flags::Better;
|
||||
} else if (p_lossy_quality > 0.55) {
|
||||
flags = cvtt::Flags::Default;
|
||||
} else if (p_lossy_quality > 0.35) {
|
||||
flags = cvtt::Flags::Fast;
|
||||
} else if (p_lossy_quality > 0.15) {
|
||||
flags = cvtt::Flags::Faster;
|
||||
}
|
||||
|
||||
flags |= cvtt::Flags::BC7_RespectPunchThrough;
|
||||
|
||||
if (p_source == Image::COMPRESS_SOURCE_NORMAL) {
|
||||
flags |= cvtt::Flags::Uniform;
|
||||
}
|
||||
options.flags = flags;
|
||||
|
||||
Image::Format target_format = Image::FORMAT_BPTC_RGBA;
|
||||
|
||||
bool is_signed = false;
|
||||
if (is_hdr) {
|
||||
if (p_image->get_format() != Image::FORMAT_RGBH) {
|
||||
p_image->convert(Image::FORMAT_RGBH);
|
||||
}
|
||||
|
||||
PoolVector<uint8_t>::Read rb = p_image->get_data().read();
|
||||
|
||||
const uint16_t *source_data = reinterpret_cast<const uint16_t *>(&rb[0]);
|
||||
int pixel_element_count = w * h * 3;
|
||||
for (int i = 0; i < pixel_element_count; i++) {
|
||||
if ((source_data[i] & 0x8000) != 0 && (source_data[i] & 0x7fff) != 0) {
|
||||
is_signed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
target_format = is_signed ? Image::FORMAT_BPTC_RGBF : Image::FORMAT_BPTC_RGBFU;
|
||||
} else {
|
||||
p_image->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert
|
||||
}
|
||||
|
||||
PoolVector<uint8_t>::Read rb = p_image->get_data().read();
|
||||
|
||||
PoolVector<uint8_t> data;
|
||||
int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps());
|
||||
int mm_count = p_image->has_mipmaps() ? Image::get_image_required_mipmaps(w, h, target_format) : 0;
|
||||
data.resize(target_size);
|
||||
int shift = Image::get_format_pixel_rshift(target_format);
|
||||
|
||||
PoolVector<uint8_t>::Write wb = data.write();
|
||||
|
||||
int dst_ofs = 0;
|
||||
|
||||
CVTTCompressionJobQueue job_queue;
|
||||
job_queue.job_params.is_hdr = is_hdr;
|
||||
job_queue.job_params.is_signed = is_signed;
|
||||
job_queue.job_params.options = options;
|
||||
job_queue.job_params.bytes_per_pixel = is_hdr ? 6 : 4;
|
||||
|
||||
#ifdef NO_THREADS
|
||||
int num_job_threads = 0;
|
||||
#else
|
||||
int num_job_threads = OS::get_singleton()->can_use_threads() ? (OS::get_singleton()->get_processor_count() - 1) : 0;
|
||||
#endif
|
||||
|
||||
PoolVector<CVTTCompressionRowTask> tasks;
|
||||
|
||||
for (int i = 0; i <= mm_count; i++) {
|
||||
int bw = w % 4 != 0 ? w + (4 - w % 4) : w;
|
||||
int bh = h % 4 != 0 ? h + (4 - h % 4) : h;
|
||||
|
||||
int src_ofs = p_image->get_mipmap_offset(i);
|
||||
|
||||
const uint8_t *in_bytes = &rb[src_ofs];
|
||||
uint8_t *out_bytes = &wb[dst_ofs];
|
||||
|
||||
for (int y_start = 0; y_start < h; y_start += 4) {
|
||||
CVTTCompressionRowTask row_task;
|
||||
row_task.width = w;
|
||||
row_task.height = h;
|
||||
row_task.y_start = y_start;
|
||||
row_task.in_mm_bytes = in_bytes;
|
||||
row_task.out_mm_bytes = out_bytes;
|
||||
|
||||
if (num_job_threads > 0) {
|
||||
tasks.push_back(row_task);
|
||||
} else {
|
||||
_digest_row_task(job_queue.job_params, row_task);
|
||||
}
|
||||
|
||||
out_bytes += 16 * (bw / 4);
|
||||
}
|
||||
|
||||
dst_ofs += (MAX(4, bw) * MAX(4, bh)) >> shift;
|
||||
w = MAX(w / 2, 1);
|
||||
h = MAX(h / 2, 1);
|
||||
}
|
||||
|
||||
if (num_job_threads > 0) {
|
||||
PoolVector<Thread *> threads;
|
||||
threads.resize(num_job_threads);
|
||||
|
||||
PoolVector<Thread *>::Write threads_wb = threads.write();
|
||||
|
||||
PoolVector<CVTTCompressionRowTask>::Read tasks_rb = tasks.read();
|
||||
|
||||
job_queue.job_tasks = &tasks_rb[0];
|
||||
job_queue.current_task.set(0);
|
||||
job_queue.num_tasks = static_cast<uint32_t>(tasks.size());
|
||||
|
||||
for (int i = 0; i < num_job_threads; i++) {
|
||||
threads_wb[i] = memnew(Thread);
|
||||
threads_wb[i]->start(_digest_job_queue, &job_queue);
|
||||
}
|
||||
_digest_job_queue(&job_queue);
|
||||
|
||||
for (int i = 0; i < num_job_threads; i++) {
|
||||
threads_wb[i]->wait_to_finish();
|
||||
memdelete(threads_wb[i]);
|
||||
}
|
||||
}
|
||||
|
||||
p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data);
|
||||
}
|
||||
|
||||
void image_decompress_cvtt(Image *p_image) {
|
||||
Image::Format target_format;
|
||||
bool is_signed = false;
|
||||
bool is_hdr = false;
|
||||
|
||||
Image::Format input_format = p_image->get_format();
|
||||
|
||||
switch (input_format) {
|
||||
case Image::FORMAT_BPTC_RGBA:
|
||||
target_format = Image::FORMAT_RGBA8;
|
||||
break;
|
||||
case Image::FORMAT_BPTC_RGBF:
|
||||
case Image::FORMAT_BPTC_RGBFU:
|
||||
target_format = Image::FORMAT_RGBH;
|
||||
is_signed = (input_format == Image::FORMAT_BPTC_RGBF);
|
||||
is_hdr = true;
|
||||
break;
|
||||
default:
|
||||
return; // Invalid input format
|
||||
};
|
||||
|
||||
int w = p_image->get_width();
|
||||
int h = p_image->get_height();
|
||||
|
||||
PoolVector<uint8_t>::Read rb = p_image->get_data().read();
|
||||
|
||||
PoolVector<uint8_t> data;
|
||||
int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps());
|
||||
int mm_count = p_image->get_mipmap_count();
|
||||
data.resize(target_size);
|
||||
|
||||
PoolVector<uint8_t>::Write wb = data.write();
|
||||
|
||||
int bytes_per_pixel = is_hdr ? 6 : 4;
|
||||
|
||||
int dst_ofs = 0;
|
||||
|
||||
for (int i = 0; i <= mm_count; i++) {
|
||||
int src_ofs = p_image->get_mipmap_offset(i);
|
||||
|
||||
const uint8_t *in_bytes = &rb[src_ofs];
|
||||
uint8_t *out_bytes = &wb[dst_ofs];
|
||||
|
||||
cvtt::PixelBlockU8 output_blocks_ldr[cvtt::NumParallelBlocks];
|
||||
cvtt::PixelBlockF16 output_blocks_hdr[cvtt::NumParallelBlocks];
|
||||
|
||||
for (int y_start = 0; y_start < h; y_start += 4) {
|
||||
int y_end = y_start + 4;
|
||||
|
||||
for (int x_start = 0; x_start < w; x_start += 4 * cvtt::NumParallelBlocks) {
|
||||
int x_end = x_start + 4 * cvtt::NumParallelBlocks;
|
||||
|
||||
uint8_t input_blocks[16 * cvtt::NumParallelBlocks];
|
||||
memset(input_blocks, 0, sizeof(input_blocks));
|
||||
|
||||
unsigned int num_real_blocks = ((w - x_start) + 3) / 4;
|
||||
if (num_real_blocks > cvtt::NumParallelBlocks) {
|
||||
num_real_blocks = cvtt::NumParallelBlocks;
|
||||
}
|
||||
|
||||
memcpy(input_blocks, in_bytes, 16 * num_real_blocks);
|
||||
in_bytes += 16 * num_real_blocks;
|
||||
|
||||
if (is_hdr) {
|
||||
if (is_signed) {
|
||||
cvtt::Kernels::DecodeBC6HS(output_blocks_hdr, input_blocks);
|
||||
} else {
|
||||
cvtt::Kernels::DecodeBC6HU(output_blocks_hdr, input_blocks);
|
||||
}
|
||||
} else {
|
||||
cvtt::Kernels::DecodeBC7(output_blocks_ldr, input_blocks);
|
||||
}
|
||||
|
||||
for (int y = y_start; y < y_end; y++) {
|
||||
int first_input_element = (y - y_start) * 4;
|
||||
uint8_t *row_start;
|
||||
if (y >= h) {
|
||||
row_start = out_bytes + (h - 1) * (w * bytes_per_pixel);
|
||||
} else {
|
||||
row_start = out_bytes + y * (w * bytes_per_pixel);
|
||||
}
|
||||
|
||||
for (int x = x_start; x < x_end; x++) {
|
||||
uint8_t *pixel_start;
|
||||
if (x >= w) {
|
||||
pixel_start = row_start + (w - 1) * bytes_per_pixel;
|
||||
} else {
|
||||
pixel_start = row_start + x * bytes_per_pixel;
|
||||
}
|
||||
|
||||
int block_index = (x - x_start) / 4;
|
||||
int block_element = (x - x_start) % 4 + first_input_element;
|
||||
if (is_hdr) {
|
||||
memcpy(pixel_start, output_blocks_hdr[block_index].m_pixels[block_element], bytes_per_pixel);
|
||||
} else {
|
||||
memcpy(pixel_start, output_blocks_ldr[block_index].m_pixels[block_element], bytes_per_pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dst_ofs += w * h * bytes_per_pixel;
|
||||
w >>= 1;
|
||||
h >>= 1;
|
||||
}
|
||||
|
||||
rb.release();
|
||||
wb.release();
|
||||
|
||||
p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data);
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
#ifndef IMAGE_COMPRESS_CVTT_H
|
||||
#define IMAGE_COMPRESS_CVTT_H
|
||||
/*************************************************************************/
|
||||
/* image_compress_cvtt.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/io/image.h"
|
||||
|
||||
void image_compress_cvtt(Image *p_image, float p_lossy_quality, Image::CompressSource p_source);
|
||||
void image_decompress_cvtt(Image *p_image);
|
||||
|
||||
#endif // IMAGE_COMPRESS_CVTT_H
|
@ -1,46 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* register_types.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "image_compress_cvtt.h"
|
||||
|
||||
void register_cvtt_types(ModuleRegistrationLevel p_level) {
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_CORE) {
|
||||
Image::set_compress_bptc_func(image_compress_cvtt);
|
||||
Image::_image_decompress_bptc = image_decompress_cvtt;
|
||||
}
|
||||
}
|
||||
|
||||
void unregister_cvtt_types(ModuleRegistrationLevel p_level) {}
|
||||
|
||||
#endif
|
@ -1,42 +0,0 @@
|
||||
#ifndef CVTT_REGISTER_TYPES_H
|
||||
#define CVTT_REGISTER_TYPES_H
|
||||
/*************************************************************************/
|
||||
/* register_types.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "modules/register_module_types.h"
|
||||
|
||||
void register_cvtt_types(ModuleRegistrationLevel p_level);
|
||||
void unregister_cvtt_types(ModuleRegistrationLevel p_level);
|
||||
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
#endif // CVTT_REGISTER_TYPES_H
|
@ -1,24 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
Import("env")
|
||||
|
||||
env_mlp = env.Clone()
|
||||
|
||||
sources = [
|
||||
"register_types.cpp",
|
||||
|
||||
"editor_code_text_editor.cpp",
|
||||
"editor_script_text_editor.cpp",
|
||||
"editor_text_editor.cpp",
|
||||
"editor_script_editor_base.cpp",
|
||||
"editor_connection_info_dialog.cpp",
|
||||
"editor_goto_line_dialog.cpp",
|
||||
"editor_find_replace_bar.cpp",
|
||||
"editor_script_editor_quick_open.cpp",
|
||||
"editor_syntax_highlighter.cpp",
|
||||
|
||||
"script_editor_plugin.cpp",
|
||||
"editor_script_editor.cpp",
|
||||
]
|
||||
|
||||
env_mlp.add_source_files(env.modules_sources, sources)
|
@ -1,23 +0,0 @@
|
||||
|
||||
|
||||
def can_build(env, platform):
|
||||
if not env["tools"]:
|
||||
return False
|
||||
|
||||
env.module_add_dependencies("editor_code_editor", ["freetype"], True)
|
||||
|
||||
return True
|
||||
|
||||
def configure(env):
|
||||
pass
|
||||
|
||||
|
||||
def get_doc_classes():
|
||||
return [
|
||||
"EditorScriptEditor",
|
||||
"EditorScriptEditorBase",
|
||||
"EditorSyntaxHighlighter"
|
||||
]
|
||||
|
||||
def get_doc_path():
|
||||
return "doc_classes"
|
@ -1,91 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="EditorScriptEditor" inherits="PanelContainer" version="4.2">
|
||||
<brief_description>
|
||||
Godot editor's script editor.
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class shouldn't be instantiated directly. Instead, access the singleton using [method EditorInterface.get_script_editor].
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="can_drop_data_fw" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<argument index="0" name="point" type="Vector2" />
|
||||
<argument index="1" name="data" type="Variant" />
|
||||
<argument index="2" name="from" type="Control" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="drop_data_fw">
|
||||
<return type="void" />
|
||||
<argument index="0" name="point" type="Vector2" />
|
||||
<argument index="1" name="data" type="Variant" />
|
||||
<argument index="2" name="from" type="Control" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_base_editor" qualifiers="const">
|
||||
<return type="Control" />
|
||||
<description>
|
||||
Returns the underlying [Control] used for editing scripts. For text scripts, this is a [TextEdit].
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_current_script">
|
||||
<return type="Script" />
|
||||
<description>
|
||||
Returns a [Script] that is currently active in editor.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_drag_data_fw">
|
||||
<return type="Variant" />
|
||||
<argument index="0" name="point" type="Vector2" />
|
||||
<argument index="1" name="from" type="Control" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_open_scripts" qualifiers="const">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
Returns an array with all [Script] objects which are currently open in editor.
|
||||
</description>
|
||||
</method>
|
||||
<method name="goto_line">
|
||||
<return type="void" />
|
||||
<argument index="0" name="line_number" type="int" />
|
||||
<description>
|
||||
Goes to the specified line in the current script.
|
||||
</description>
|
||||
</method>
|
||||
<method name="open_script_create_dialog">
|
||||
<return type="void" />
|
||||
<argument index="0" name="base_name" type="String" />
|
||||
<argument index="1" name="base_path" type="String" />
|
||||
<description>
|
||||
Opens the script create dialog. The script will extend [code]base_name[/code]. The file extension can be omitted from [code]base_path[/code]. It will be added based on the selected scripting language.
|
||||
</description>
|
||||
</method>
|
||||
<method name="reload_scripts">
|
||||
<return type="void" />
|
||||
<description>
|
||||
Reload all currently opened scripts from disk in case the file contents are newer.
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<signals>
|
||||
<signal name="editor_script_changed">
|
||||
<argument index="0" name="script" type="Script" />
|
||||
<description>
|
||||
Emitted when user changed active script. Argument is a freshly activated [Script].
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="script_close">
|
||||
<argument index="0" name="script" type="Script" />
|
||||
<description>
|
||||
Emitted when editor is about to close the active script. Argument is a [Script] that is going to be closed.
|
||||
</description>
|
||||
</signal>
|
||||
</signals>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,53 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="EditorScriptEditorBase" inherits="VBoxContainer" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<signals>
|
||||
<signal name="edited_script_changed">
|
||||
<description>
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="go_to_help">
|
||||
<argument index="0" name="what" type="String" />
|
||||
<description>
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="name_changed">
|
||||
<description>
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="replace_in_files_requested">
|
||||
<argument index="0" name="text" type="String" />
|
||||
<description>
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="request_help">
|
||||
<argument index="0" name="topic" type="String" />
|
||||
<description>
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="request_open_script_at_line">
|
||||
<argument index="0" name="script" type="Object" />
|
||||
<argument index="1" name="line" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="request_save_history">
|
||||
<description>
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="search_in_files_requested">
|
||||
<argument index="0" name="text" type="String" />
|
||||
<description>
|
||||
</description>
|
||||
</signal>
|
||||
</signals>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="EditorSyntaxHighlighter" inherits="SyntaxHighlighter" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="_get_name" qualifiers="virtual">
|
||||
<return type="String" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="_get_supported_extentions" qualifiers="virtual">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="_get_supported_languages" qualifiers="virtual">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
File diff suppressed because it is too large
Load Diff
@ -1,185 +0,0 @@
|
||||
#ifndef EDITOR_CODE_EDITOR_H
|
||||
#define EDITOR_CODE_EDITOR_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* code_editor.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/gui/box_container.h"
|
||||
#include "scene/gui/dialogs.h"
|
||||
|
||||
#include "core/containers/list.h"
|
||||
#include "core/math/math_defs.h"
|
||||
#include "core/object/object.h"
|
||||
#include "core/object/reference.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
class Button;
|
||||
class CheckBox;
|
||||
class InputEvent;
|
||||
class Label;
|
||||
class LineEdit;
|
||||
class TextEdit;
|
||||
class Texture;
|
||||
class TextureButton;
|
||||
class Timer;
|
||||
class ToolButton;
|
||||
struct ScriptCodeCompletionOption;
|
||||
class EditorGotoLineDialog;
|
||||
class EditorFindReplaceBar;
|
||||
|
||||
typedef void (*EditorCodeTextEditorCodeCompleteFunc)(void *p_ud, const String &p_code, List<ScriptCodeCompletionOption> *r_options, bool &r_forced);
|
||||
|
||||
class EditorCodeTextEditor : public VBoxContainer {
|
||||
GDCLASS(EditorCodeTextEditor, VBoxContainer);
|
||||
|
||||
TextEdit *text_editor;
|
||||
EditorFindReplaceBar *find_replace_bar;
|
||||
HBoxContainer *status_bar;
|
||||
|
||||
ToolButton *toggle_scripts_button;
|
||||
ToolButton *warning_button;
|
||||
Label *warning_count_label;
|
||||
|
||||
Label *line_and_col_txt;
|
||||
|
||||
Label *info;
|
||||
Timer *idle;
|
||||
Timer *code_complete_timer;
|
||||
|
||||
Timer *font_resize_timer;
|
||||
int font_resize_val;
|
||||
real_t font_size;
|
||||
|
||||
Label *error;
|
||||
int error_line;
|
||||
int error_column;
|
||||
|
||||
void _on_settings_change();
|
||||
|
||||
void _update_font();
|
||||
void _complete_request();
|
||||
Ref<Texture> _get_completion_icon(const ScriptCodeCompletionOption &p_option);
|
||||
void _font_resize_timeout();
|
||||
bool _add_font_size(int p_delta);
|
||||
|
||||
void _text_editor_gui_input(const Ref<InputEvent> &p_event);
|
||||
void _zoom_in();
|
||||
void _zoom_out();
|
||||
void _zoom_changed();
|
||||
void _reset_zoom();
|
||||
|
||||
Color completion_font_color;
|
||||
Color completion_string_color;
|
||||
Color completion_comment_color;
|
||||
EditorCodeTextEditorCodeCompleteFunc code_complete_func;
|
||||
void *code_complete_ud;
|
||||
|
||||
void _warning_label_gui_input(const Ref<InputEvent> &p_event);
|
||||
void _warning_button_pressed();
|
||||
void _set_show_warnings_panel(bool p_show);
|
||||
void _error_pressed(const Ref<InputEvent> &p_event);
|
||||
|
||||
void _delete_line(int p_line);
|
||||
void _toggle_scripts_pressed();
|
||||
|
||||
protected:
|
||||
virtual void _load_theme_settings() {}
|
||||
virtual void _validate_script() {}
|
||||
virtual void _code_complete_script(const String &p_code, List<ScriptCodeCompletionOption> *r_options) {}
|
||||
|
||||
void _text_changed_idle_timeout();
|
||||
void _code_complete_timer_timeout();
|
||||
void _text_changed();
|
||||
void _line_col_changed();
|
||||
void _notification(int);
|
||||
static void _bind_methods();
|
||||
|
||||
bool is_warnings_panel_opened;
|
||||
|
||||
public:
|
||||
void trim_trailing_whitespace();
|
||||
void insert_final_newline();
|
||||
|
||||
void convert_indent_to_spaces();
|
||||
void convert_indent_to_tabs();
|
||||
|
||||
enum CaseStyle {
|
||||
UPPER,
|
||||
LOWER,
|
||||
CAPITALIZE,
|
||||
};
|
||||
void convert_case(CaseStyle p_case);
|
||||
|
||||
void move_lines_up();
|
||||
void move_lines_down();
|
||||
void delete_lines();
|
||||
void duplicate_selection();
|
||||
|
||||
/// Toggle inline comment on currently selected lines, or on current line if nothing is selected,
|
||||
/// by adding or removing comment delimiter
|
||||
void toggle_inline_comment(const String &delimiter);
|
||||
|
||||
void goto_line(int p_line);
|
||||
void goto_line_selection(int p_line, int p_begin, int p_end);
|
||||
void goto_line_centered(int p_line);
|
||||
void set_executing_line(int p_line);
|
||||
void clear_executing_line();
|
||||
|
||||
Variant get_edit_state();
|
||||
void set_edit_state(const Variant &p_state);
|
||||
|
||||
void set_warning_nb(int p_warning_nb);
|
||||
|
||||
void update_editor_settings();
|
||||
void set_error(const String &p_error);
|
||||
void set_error_pos(int p_line, int p_column);
|
||||
void update_line_and_column() { _line_col_changed(); }
|
||||
TextEdit *get_text_edit() { return text_editor; }
|
||||
EditorFindReplaceBar *get_find_replace_bar() { return find_replace_bar; }
|
||||
virtual void apply_code() {}
|
||||
void goto_error();
|
||||
|
||||
void toggle_bookmark();
|
||||
void goto_next_bookmark();
|
||||
void goto_prev_bookmark();
|
||||
void remove_all_bookmarks();
|
||||
|
||||
void set_code_complete_func(EditorCodeTextEditorCodeCompleteFunc p_code_complete_func, void *p_ud);
|
||||
|
||||
void validate_script();
|
||||
|
||||
void show_toggle_scripts_button();
|
||||
void update_toggle_scripts_button();
|
||||
|
||||
EditorCodeTextEditor();
|
||||
};
|
||||
|
||||
#endif // CODE_EDITOR_H
|
@ -1,106 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* script_text_editor.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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_connection_info_dialog.h"
|
||||
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_scale.h"
|
||||
#include "scene/gui/box_container.h"
|
||||
#include "scene/gui/label.h"
|
||||
#include "scene/gui/tree.h"
|
||||
#include "scene/main/node.h"
|
||||
|
||||
void EditorConnectionInfoDialog::ok_pressed() {
|
||||
}
|
||||
|
||||
void EditorConnectionInfoDialog::popup_connections(String p_method, Vector<Node *> p_nodes) {
|
||||
method->set_text(p_method);
|
||||
|
||||
tree->clear();
|
||||
TreeItem *root = tree->create_item();
|
||||
|
||||
for (int i = 0; i < p_nodes.size(); i++) {
|
||||
List<Connection> all_connections;
|
||||
p_nodes[i]->get_signals_connected_to_this(&all_connections);
|
||||
|
||||
for (List<Connection>::Element *E = all_connections.front(); E; E = E->next()) {
|
||||
Connection connection = E->get();
|
||||
|
||||
if (connection.method != p_method) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TreeItem *node_item = tree->create_item(root);
|
||||
|
||||
node_item->set_text(0, Object::cast_to<Node>(connection.source)->get_name());
|
||||
node_item->set_icon(0, EditorNode::get_singleton()->get_object_icon(connection.source, "Node"));
|
||||
node_item->set_selectable(0, false);
|
||||
node_item->set_editable(0, false);
|
||||
|
||||
node_item->set_text(1, connection.signal);
|
||||
node_item->set_icon(1, get_parent_control()->get_theme_icon("Slot", "EditorIcons"));
|
||||
node_item->set_selectable(1, false);
|
||||
node_item->set_editable(1, false);
|
||||
|
||||
node_item->set_text(2, Object::cast_to<Node>(connection.target)->get_name());
|
||||
node_item->set_icon(2, EditorNode::get_singleton()->get_object_icon(connection.target, "Node"));
|
||||
node_item->set_selectable(2, false);
|
||||
node_item->set_editable(2, false);
|
||||
}
|
||||
}
|
||||
|
||||
popup_centered(Size2(600, 300) * EDSCALE);
|
||||
}
|
||||
|
||||
EditorConnectionInfoDialog::EditorConnectionInfoDialog() {
|
||||
set_title(TTR("Connections to method:"));
|
||||
|
||||
VBoxContainer *vbc = memnew(VBoxContainer);
|
||||
vbc->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 8 * EDSCALE);
|
||||
vbc->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 8 * EDSCALE);
|
||||
vbc->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -8 * EDSCALE);
|
||||
vbc->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -8 * EDSCALE);
|
||||
add_child(vbc);
|
||||
|
||||
method = memnew(Label);
|
||||
method->set_align(Label::ALIGN_CENTER);
|
||||
vbc->add_child(method);
|
||||
|
||||
tree = memnew(Tree);
|
||||
tree->set_columns(3);
|
||||
tree->set_hide_root(true);
|
||||
tree->set_column_titles_visible(true);
|
||||
tree->set_column_title(0, TTR("Source"));
|
||||
tree->set_column_title(1, TTR("Signal"));
|
||||
tree->set_column_title(2, TTR("Target"));
|
||||
vbc->add_child(tree);
|
||||
tree->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
tree->set_allow_rmb_select(true);
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
#ifndef EDITOR_CONNECTION_INFO_DIALOG_H
|
||||
#define EDITOR_CONNECTION_INFO_DIALOG_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* script_text_editor.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/gui/dialogs.h"
|
||||
|
||||
class Label;
|
||||
class Node;
|
||||
class Tree;
|
||||
|
||||
class EditorConnectionInfoDialog : public AcceptDialog {
|
||||
GDCLASS(EditorConnectionInfoDialog, AcceptDialog);
|
||||
|
||||
Label *method;
|
||||
Tree *tree;
|
||||
|
||||
virtual void ok_pressed();
|
||||
|
||||
public:
|
||||
void popup_connections(String p_method, Vector<Node *> p_nodes);
|
||||
|
||||
EditorConnectionInfoDialog();
|
||||
};
|
||||
|
||||
#endif // SCRIPT_TEXT_EDITOR_H
|
@ -1,654 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* code_editor.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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_find_replace_bar.h"
|
||||
|
||||
#include "core/input/input.h"
|
||||
#include "core/input/input_event.h"
|
||||
#include "core/input/shortcut.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/os/keyboard.h"
|
||||
#include "editor/editor_scale.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "scene/gui/button.h"
|
||||
#include "scene/gui/check_box.h"
|
||||
#include "scene/main/control.h"
|
||||
#include "scene/gui/label.h"
|
||||
#include "scene/gui/line_edit.h"
|
||||
#include "scene/gui/scroll_container.h"
|
||||
#include "scene/gui/text_edit.h"
|
||||
#include "scene/gui/texture_button.h"
|
||||
#include "scene/gui/tool_button.h"
|
||||
#include "scene/resources/font/font.h"
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
void EditorFindReplaceBar::_notification(int p_what) {
|
||||
if (p_what == NOTIFICATION_READY) {
|
||||
find_prev->set_icon(get_theme_icon("MoveUp", "EditorIcons"));
|
||||
find_next->set_icon(get_theme_icon("MoveDown", "EditorIcons"));
|
||||
hide_button->set_normal_texture(get_theme_icon("Close", "EditorIcons"));
|
||||
hide_button->set_hover_texture(get_theme_icon("Close", "EditorIcons"));
|
||||
hide_button->set_pressed_texture(get_theme_icon("Close", "EditorIcons"));
|
||||
hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size());
|
||||
} else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
|
||||
set_process_unhandled_input(is_visible_in_tree());
|
||||
} else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
|
||||
find_prev->set_icon(get_theme_icon("MoveUp", "EditorIcons"));
|
||||
find_next->set_icon(get_theme_icon("MoveDown", "EditorIcons"));
|
||||
hide_button->set_normal_texture(get_theme_icon("Close", "EditorIcons"));
|
||||
hide_button->set_hover_texture(get_theme_icon("Close", "EditorIcons"));
|
||||
hide_button->set_pressed_texture(get_theme_icon("Close", "EditorIcons"));
|
||||
hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size());
|
||||
} else if (p_what == NOTIFICATION_THEME_CHANGED) {
|
||||
matches_label->add_theme_color_override("font_color", results_count > 0 ? get_theme_color("font_color", "Label") : get_theme_color("error_color", "Editor"));
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::_unhandled_input(const Ref<InputEvent> &p_event) {
|
||||
Ref<InputEventKey> k = p_event;
|
||||
if (!k.is_valid() || !k->is_pressed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Control *focus_owner = get_focus_owner();
|
||||
if (text_edit->has_focus() || (focus_owner && vbc_lineedit->is_a_parent_of(focus_owner))) {
|
||||
bool accepted = true;
|
||||
|
||||
switch (k->get_scancode()) {
|
||||
case KEY_ESCAPE: {
|
||||
_hide_bar();
|
||||
} break;
|
||||
default: {
|
||||
accepted = false;
|
||||
} break;
|
||||
}
|
||||
|
||||
if (accepted) {
|
||||
accept_event();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorFindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col) {
|
||||
int line, col;
|
||||
String text = get_search_text();
|
||||
|
||||
bool found = text_edit->search(text, p_flags, p_from_line, p_from_col, line, col);
|
||||
|
||||
if (found) {
|
||||
if (!preserve_cursor && !is_selection_only()) {
|
||||
text_edit->unfold_line(line);
|
||||
text_edit->cursor_set_line(line, false);
|
||||
text_edit->cursor_set_column(col + text.length(), false);
|
||||
text_edit->center_viewport_to_cursor();
|
||||
text_edit->select(line, col, line, col + text.length());
|
||||
}
|
||||
|
||||
text_edit->set_search_text(text);
|
||||
text_edit->set_search_flags(p_flags);
|
||||
text_edit->set_current_search_result(line, col);
|
||||
|
||||
result_line = line;
|
||||
result_col = col;
|
||||
|
||||
_update_results_count();
|
||||
} else {
|
||||
results_count = 0;
|
||||
result_line = -1;
|
||||
result_col = -1;
|
||||
text_edit->set_search_text("");
|
||||
text_edit->set_search_flags(p_flags);
|
||||
text_edit->set_current_search_result(line, col);
|
||||
}
|
||||
|
||||
_update_matches_label();
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::_replace() {
|
||||
bool selection_enabled = text_edit->is_selection_active();
|
||||
Point2i selection_begin, selection_end;
|
||||
if (selection_enabled) {
|
||||
selection_begin = Point2i(text_edit->get_selection_from_line(), text_edit->get_selection_from_column());
|
||||
selection_end = Point2i(text_edit->get_selection_to_line(), text_edit->get_selection_to_column());
|
||||
}
|
||||
|
||||
String replace_text = get_replace_text();
|
||||
int search_text_len = get_search_text().length();
|
||||
|
||||
text_edit->begin_complex_operation();
|
||||
if (selection_enabled && is_selection_only()) { // To restrict search_current() to selected region
|
||||
text_edit->cursor_set_line(selection_begin.width);
|
||||
text_edit->cursor_set_column(selection_begin.height);
|
||||
}
|
||||
|
||||
if (search_current()) {
|
||||
text_edit->unfold_line(result_line);
|
||||
text_edit->select(result_line, result_col, result_line, result_col + search_text_len);
|
||||
|
||||
if (selection_enabled && is_selection_only()) {
|
||||
Point2i match_from(result_line, result_col);
|
||||
Point2i match_to(result_line, result_col + search_text_len);
|
||||
if (!(match_from < selection_begin || match_to > selection_end)) {
|
||||
text_edit->insert_text_at_cursor(replace_text);
|
||||
if (match_to.x == selection_end.x) { // Adjust selection bounds if necessary
|
||||
selection_end.y += replace_text.length() - search_text_len;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
text_edit->insert_text_at_cursor(replace_text);
|
||||
}
|
||||
}
|
||||
text_edit->end_complex_operation();
|
||||
results_count = -1;
|
||||
|
||||
if (selection_enabled && is_selection_only()) {
|
||||
// Reselect in order to keep 'Replace' restricted to selection
|
||||
text_edit->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y);
|
||||
} else {
|
||||
text_edit->deselect();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::_replace_all() {
|
||||
text_edit->disconnect("text_changed", this, "_editor_text_changed");
|
||||
// Line as x so it gets priority in comparison, column as y.
|
||||
Point2i orig_cursor(text_edit->cursor_get_line(), text_edit->cursor_get_column());
|
||||
Point2i prev_match = Point2(-1, -1);
|
||||
|
||||
bool selection_enabled = text_edit->is_selection_active();
|
||||
Point2i selection_begin, selection_end;
|
||||
if (selection_enabled) {
|
||||
selection_begin = Point2i(text_edit->get_selection_from_line(), text_edit->get_selection_from_column());
|
||||
selection_end = Point2i(text_edit->get_selection_to_line(), text_edit->get_selection_to_column());
|
||||
}
|
||||
|
||||
int vsval = text_edit->get_v_scroll();
|
||||
|
||||
text_edit->cursor_set_line(0);
|
||||
text_edit->cursor_set_column(0);
|
||||
|
||||
String replace_text = get_replace_text();
|
||||
int search_text_len = get_search_text().length();
|
||||
|
||||
int rc = 0;
|
||||
|
||||
replace_all_mode = true;
|
||||
|
||||
text_edit->begin_complex_operation();
|
||||
|
||||
if (selection_enabled && is_selection_only()) {
|
||||
text_edit->cursor_set_line(selection_begin.width);
|
||||
text_edit->cursor_set_column(selection_begin.height);
|
||||
}
|
||||
if (search_current()) {
|
||||
do {
|
||||
// replace area
|
||||
Point2i match_from(result_line, result_col);
|
||||
Point2i match_to(result_line, result_col + search_text_len);
|
||||
|
||||
if (match_from < prev_match) {
|
||||
break; // Done.
|
||||
}
|
||||
|
||||
prev_match = Point2i(result_line, result_col + replace_text.length());
|
||||
|
||||
text_edit->unfold_line(result_line);
|
||||
text_edit->select(result_line, result_col, result_line, match_to.y);
|
||||
|
||||
if (selection_enabled && is_selection_only()) {
|
||||
if (match_from < selection_begin || match_to > selection_end) {
|
||||
break; // Done.
|
||||
}
|
||||
|
||||
// Replace but adjust selection bounds.
|
||||
text_edit->insert_text_at_cursor(replace_text);
|
||||
if (match_to.x == selection_end.x) {
|
||||
selection_end.y += replace_text.length() - search_text_len;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Just replace.
|
||||
text_edit->insert_text_at_cursor(replace_text);
|
||||
}
|
||||
|
||||
rc++;
|
||||
} while (search_next());
|
||||
}
|
||||
|
||||
text_edit->end_complex_operation();
|
||||
|
||||
replace_all_mode = false;
|
||||
|
||||
// Restore editor state (selection, cursor, scroll).
|
||||
text_edit->cursor_set_line(orig_cursor.x);
|
||||
text_edit->cursor_set_column(orig_cursor.y);
|
||||
|
||||
if (selection_enabled && is_selection_only()) {
|
||||
// Reselect.
|
||||
text_edit->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y);
|
||||
} else {
|
||||
text_edit->deselect();
|
||||
}
|
||||
|
||||
text_edit->set_v_scroll(vsval);
|
||||
matches_label->add_theme_color_override("font_color", rc > 0 ? get_theme_color("font_color", "Label") : get_theme_color("error_color", "Editor"));
|
||||
matches_label->set_text(vformat(TTR("%d replaced."), rc));
|
||||
|
||||
text_edit->call_deferred("connect", "text_changed", this, "_editor_text_changed");
|
||||
results_count = -1;
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::_get_search_from(int &r_line, int &r_col) {
|
||||
r_line = text_edit->cursor_get_line();
|
||||
r_col = text_edit->cursor_get_column();
|
||||
|
||||
if (text_edit->is_selection_active() && is_selection_only()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (r_line == result_line && r_col >= result_col && r_col <= result_col + get_search_text().length()) {
|
||||
r_col = result_col;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::_update_results_count() {
|
||||
if (results_count != -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
results_count = 0;
|
||||
|
||||
String searched = get_search_text();
|
||||
if (searched.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String full_text = text_edit->get_text();
|
||||
|
||||
int from_pos = 0;
|
||||
|
||||
while (true) {
|
||||
int pos = is_case_sensitive() ? full_text.find(searched, from_pos) : full_text.findn(searched, from_pos);
|
||||
if (pos == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
int pos_subsequent = pos + searched.length();
|
||||
if (is_whole_words()) {
|
||||
from_pos = pos + 1; // Making sure we won't hit the same match next time, if we get out via a continue.
|
||||
if (pos > 0 && !(is_symbol(full_text[pos - 1]) || full_text[pos - 1] == '\n')) {
|
||||
continue;
|
||||
}
|
||||
if (pos_subsequent < full_text.length() && !(is_symbol(full_text[pos_subsequent]) || full_text[pos_subsequent] == '\n')) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
results_count++;
|
||||
from_pos = pos_subsequent;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::_update_matches_label() {
|
||||
if (search_text->get_text().empty() || results_count == -1) {
|
||||
matches_label->hide();
|
||||
} else {
|
||||
matches_label->show();
|
||||
|
||||
matches_label->add_theme_color_override("font_color", results_count > 0 ? get_theme_color("font_color", "Label") : get_theme_color("error_color", "Editor"));
|
||||
matches_label->set_text(vformat(results_count == 1 ? TTR("%d match.") : TTR("%d matches."), results_count));
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorFindReplaceBar::search_current() {
|
||||
uint32_t flags = 0;
|
||||
|
||||
if (is_whole_words()) {
|
||||
flags |= TextEdit::SEARCH_WHOLE_WORDS;
|
||||
}
|
||||
if (is_case_sensitive()) {
|
||||
flags |= TextEdit::SEARCH_MATCH_CASE;
|
||||
}
|
||||
|
||||
int line, col;
|
||||
_get_search_from(line, col);
|
||||
|
||||
return _search(flags, line, col);
|
||||
}
|
||||
|
||||
bool EditorFindReplaceBar::search_prev() {
|
||||
if (!is_visible()) {
|
||||
popup_search(true);
|
||||
}
|
||||
|
||||
uint32_t flags = 0;
|
||||
String text = get_search_text();
|
||||
|
||||
if (is_whole_words()) {
|
||||
flags |= TextEdit::SEARCH_WHOLE_WORDS;
|
||||
}
|
||||
if (is_case_sensitive()) {
|
||||
flags |= TextEdit::SEARCH_MATCH_CASE;
|
||||
}
|
||||
|
||||
flags |= TextEdit::SEARCH_BACKWARDS;
|
||||
|
||||
int line, col;
|
||||
_get_search_from(line, col);
|
||||
if (text_edit->is_selection_active()) {
|
||||
col--; // Skip currently selected word.
|
||||
}
|
||||
|
||||
col -= text.length();
|
||||
if (col < 0) {
|
||||
line -= 1;
|
||||
if (line < 0) {
|
||||
line = text_edit->get_line_count() - 1;
|
||||
}
|
||||
col = text_edit->get_line(line).length();
|
||||
}
|
||||
|
||||
return _search(flags, line, col);
|
||||
}
|
||||
|
||||
bool EditorFindReplaceBar::search_next() {
|
||||
if (!is_visible()) {
|
||||
popup_search(true);
|
||||
}
|
||||
|
||||
uint32_t flags = 0;
|
||||
String text;
|
||||
if (replace_all_mode) {
|
||||
text = get_replace_text();
|
||||
} else {
|
||||
text = get_search_text();
|
||||
}
|
||||
|
||||
if (is_whole_words()) {
|
||||
flags |= TextEdit::SEARCH_WHOLE_WORDS;
|
||||
}
|
||||
if (is_case_sensitive()) {
|
||||
flags |= TextEdit::SEARCH_MATCH_CASE;
|
||||
}
|
||||
|
||||
int line, col;
|
||||
_get_search_from(line, col);
|
||||
|
||||
if (line == result_line && col == result_col) {
|
||||
col += text.length();
|
||||
if (col > text_edit->get_line(line).length()) {
|
||||
line += 1;
|
||||
if (line >= text_edit->get_line_count()) {
|
||||
line = 0;
|
||||
}
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return _search(flags, line, col);
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::_hide_bar() {
|
||||
if (replace_text->has_focus() || search_text->has_focus()) {
|
||||
text_edit->grab_focus();
|
||||
}
|
||||
|
||||
text_edit->set_search_text("");
|
||||
result_line = -1;
|
||||
result_col = -1;
|
||||
hide();
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::_show_search(bool p_focus_replace, bool p_show_only) {
|
||||
show();
|
||||
if (p_show_only) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_focus_replace) {
|
||||
search_text->deselect();
|
||||
replace_text->call_deferred("grab_focus");
|
||||
} else {
|
||||
replace_text->deselect();
|
||||
search_text->call_deferred("grab_focus");
|
||||
}
|
||||
|
||||
if (text_edit->is_selection_active() && !selection_only->is_pressed()) {
|
||||
search_text->set_text(text_edit->get_selection_text());
|
||||
}
|
||||
|
||||
if (!get_search_text().empty()) {
|
||||
if (p_focus_replace) {
|
||||
replace_text->select_all();
|
||||
replace_text->set_cursor_position(replace_text->get_text().length());
|
||||
} else {
|
||||
search_text->select_all();
|
||||
search_text->set_cursor_position(search_text->get_text().length());
|
||||
}
|
||||
|
||||
results_count = -1;
|
||||
_update_results_count();
|
||||
_update_matches_label();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::popup_search(bool p_show_only) {
|
||||
replace_text->hide();
|
||||
hbc_button_replace->hide();
|
||||
hbc_option_replace->hide();
|
||||
|
||||
_show_search(false, p_show_only);
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::popup_replace() {
|
||||
if (!replace_text->is_visible_in_tree()) {
|
||||
replace_text->show();
|
||||
hbc_button_replace->show();
|
||||
hbc_option_replace->show();
|
||||
}
|
||||
|
||||
selection_only->set_pressed((text_edit->is_selection_active() && text_edit->get_selection_from_line() < text_edit->get_selection_to_line()));
|
||||
|
||||
_show_search(is_visible() || text_edit->is_selection_active());
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::_search_options_changed(bool p_pressed) {
|
||||
results_count = -1;
|
||||
search_current();
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::_editor_text_changed() {
|
||||
results_count = -1;
|
||||
if (is_visible_in_tree()) {
|
||||
preserve_cursor = true;
|
||||
search_current();
|
||||
preserve_cursor = false;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::_search_text_changed(const String &p_text) {
|
||||
results_count = -1;
|
||||
search_current();
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::_search_text_entered(const String &p_text) {
|
||||
if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
|
||||
search_prev();
|
||||
} else {
|
||||
search_next();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::_replace_text_entered(const String &p_text) {
|
||||
if (selection_only->is_pressed() && text_edit->is_selection_active()) {
|
||||
_replace_all();
|
||||
_hide_bar();
|
||||
}
|
||||
}
|
||||
|
||||
String EditorFindReplaceBar::get_search_text() const {
|
||||
return search_text->get_text();
|
||||
}
|
||||
|
||||
String EditorFindReplaceBar::get_replace_text() const {
|
||||
return replace_text->get_text();
|
||||
}
|
||||
|
||||
bool EditorFindReplaceBar::is_case_sensitive() const {
|
||||
return case_sensitive->is_pressed();
|
||||
}
|
||||
|
||||
bool EditorFindReplaceBar::is_whole_words() const {
|
||||
return whole_words->is_pressed();
|
||||
}
|
||||
|
||||
bool EditorFindReplaceBar::is_selection_only() const {
|
||||
return selection_only->is_pressed();
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::set_error(const String &p_label) {
|
||||
emit_signal("error", p_label);
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::set_text_edit(TextEdit *p_text_edit) {
|
||||
results_count = -1;
|
||||
text_edit = p_text_edit;
|
||||
text_edit->connect("text_changed", this, "_editor_text_changed");
|
||||
}
|
||||
|
||||
void EditorFindReplaceBar::_bind_methods() {
|
||||
ClassDB::bind_method("_unhandled_input", &EditorFindReplaceBar::_unhandled_input);
|
||||
|
||||
ClassDB::bind_method("_editor_text_changed", &EditorFindReplaceBar::_editor_text_changed);
|
||||
ClassDB::bind_method("_search_text_changed", &EditorFindReplaceBar::_search_text_changed);
|
||||
ClassDB::bind_method("_search_text_entered", &EditorFindReplaceBar::_search_text_entered);
|
||||
ClassDB::bind_method("_replace_text_entered", &EditorFindReplaceBar::_replace_text_entered);
|
||||
ClassDB::bind_method("_search_current", &EditorFindReplaceBar::search_current);
|
||||
ClassDB::bind_method("_search_next", &EditorFindReplaceBar::search_next);
|
||||
ClassDB::bind_method("_search_prev", &EditorFindReplaceBar::search_prev);
|
||||
ClassDB::bind_method("_replace_pressed", &EditorFindReplaceBar::_replace);
|
||||
ClassDB::bind_method("_replace_all_pressed", &EditorFindReplaceBar::_replace_all);
|
||||
ClassDB::bind_method("_search_options_changed", &EditorFindReplaceBar::_search_options_changed);
|
||||
ClassDB::bind_method("_hide_pressed", &EditorFindReplaceBar::_hide_bar);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("search"));
|
||||
ADD_SIGNAL(MethodInfo("error"));
|
||||
}
|
||||
|
||||
EditorFindReplaceBar::EditorFindReplaceBar() {
|
||||
results_count = -1;
|
||||
replace_all_mode = false;
|
||||
preserve_cursor = false;
|
||||
|
||||
vbc_lineedit = memnew(VBoxContainer);
|
||||
add_child(vbc_lineedit);
|
||||
vbc_lineedit->set_alignment(ALIGN_CENTER);
|
||||
vbc_lineedit->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
VBoxContainer *vbc_button = memnew(VBoxContainer);
|
||||
add_child(vbc_button);
|
||||
VBoxContainer *vbc_option = memnew(VBoxContainer);
|
||||
add_child(vbc_option);
|
||||
|
||||
HBoxContainer *hbc_button_search = memnew(HBoxContainer);
|
||||
vbc_button->add_child(hbc_button_search);
|
||||
hbc_button_search->set_alignment(ALIGN_END);
|
||||
hbc_button_replace = memnew(HBoxContainer);
|
||||
vbc_button->add_child(hbc_button_replace);
|
||||
hbc_button_replace->set_alignment(ALIGN_END);
|
||||
|
||||
HBoxContainer *hbc_option_search = memnew(HBoxContainer);
|
||||
vbc_option->add_child(hbc_option_search);
|
||||
hbc_option_replace = memnew(HBoxContainer);
|
||||
vbc_option->add_child(hbc_option_replace);
|
||||
|
||||
// search toolbar
|
||||
search_text = memnew(LineEdit);
|
||||
vbc_lineedit->add_child(search_text);
|
||||
search_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
|
||||
search_text->connect("text_changed", this, "_search_text_changed");
|
||||
search_text->connect("text_entered", this, "_search_text_entered");
|
||||
|
||||
matches_label = memnew(Label);
|
||||
hbc_button_search->add_child(matches_label);
|
||||
matches_label->hide();
|
||||
|
||||
find_prev = memnew(ToolButton);
|
||||
hbc_button_search->add_child(find_prev);
|
||||
find_prev->set_focus_mode(FOCUS_NONE);
|
||||
find_prev->connect("pressed", this, "_search_prev");
|
||||
|
||||
find_next = memnew(ToolButton);
|
||||
hbc_button_search->add_child(find_next);
|
||||
find_next->set_focus_mode(FOCUS_NONE);
|
||||
find_next->connect("pressed", this, "_search_next");
|
||||
|
||||
case_sensitive = memnew(CheckBox);
|
||||
hbc_option_search->add_child(case_sensitive);
|
||||
case_sensitive->set_text(TTR("Match Case"));
|
||||
case_sensitive->set_focus_mode(FOCUS_NONE);
|
||||
case_sensitive->set_pressed(true);
|
||||
case_sensitive->connect("toggled", this, "_search_options_changed");
|
||||
|
||||
whole_words = memnew(CheckBox);
|
||||
hbc_option_search->add_child(whole_words);
|
||||
whole_words->set_text(TTR("Whole Words"));
|
||||
whole_words->set_focus_mode(FOCUS_NONE);
|
||||
whole_words->connect("toggled", this, "_search_options_changed");
|
||||
|
||||
// replace toolbar
|
||||
replace_text = memnew(LineEdit);
|
||||
vbc_lineedit->add_child(replace_text);
|
||||
replace_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
|
||||
replace_text->connect("text_entered", this, "_replace_text_entered");
|
||||
|
||||
replace = memnew(Button);
|
||||
hbc_button_replace->add_child(replace);
|
||||
replace->set_text(TTR("Replace"));
|
||||
replace->connect("pressed", this, "_replace_pressed");
|
||||
|
||||
replace_all = memnew(Button);
|
||||
hbc_button_replace->add_child(replace_all);
|
||||
replace_all->set_text(TTR("Replace All"));
|
||||
replace_all->connect("pressed", this, "_replace_all_pressed");
|
||||
|
||||
selection_only = memnew(CheckBox);
|
||||
hbc_option_replace->add_child(selection_only);
|
||||
selection_only->set_text(TTR("Selection Only"));
|
||||
selection_only->set_focus_mode(FOCUS_NONE);
|
||||
selection_only->connect("toggled", this, "_search_options_changed");
|
||||
|
||||
hide_button = memnew(TextureButton);
|
||||
add_child(hide_button);
|
||||
hide_button->set_focus_mode(FOCUS_NONE);
|
||||
hide_button->connect("pressed", this, "_hide_pressed");
|
||||
hide_button->set_v_size_flags(SIZE_SHRINK_CENTER);
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
#ifndef EDITOR_FIND_REPLACE_BAR_H
|
||||
#define EDITOR_FIND_REPLACE_BAR_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* code_editor.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/gui/dialogs.h"
|
||||
#include "scene/gui/box_container.h"
|
||||
|
||||
#include "core/containers/list.h"
|
||||
#include "core/math/math_defs.h"
|
||||
#include "core/object/object.h"
|
||||
#include "core/object/reference.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
class Button;
|
||||
class CheckBox;
|
||||
class InputEvent;
|
||||
class Label;
|
||||
class LineEdit;
|
||||
class TextEdit;
|
||||
class Texture;
|
||||
class TextureButton;
|
||||
class ToolButton;
|
||||
|
||||
class EditorFindReplaceBar : public HBoxContainer {
|
||||
GDCLASS(EditorFindReplaceBar, HBoxContainer);
|
||||
|
||||
LineEdit *search_text;
|
||||
Label *matches_label;
|
||||
ToolButton *find_prev;
|
||||
ToolButton *find_next;
|
||||
CheckBox *case_sensitive;
|
||||
CheckBox *whole_words;
|
||||
TextureButton *hide_button;
|
||||
|
||||
LineEdit *replace_text;
|
||||
Button *replace;
|
||||
Button *replace_all;
|
||||
CheckBox *selection_only;
|
||||
|
||||
VBoxContainer *vbc_lineedit;
|
||||
HBoxContainer *hbc_button_replace;
|
||||
HBoxContainer *hbc_option_replace;
|
||||
|
||||
TextEdit *text_edit;
|
||||
|
||||
int result_line;
|
||||
int result_col;
|
||||
int results_count;
|
||||
|
||||
bool replace_all_mode;
|
||||
bool preserve_cursor;
|
||||
|
||||
void _get_search_from(int &r_line, int &r_col);
|
||||
void _update_results_count();
|
||||
void _update_matches_label();
|
||||
|
||||
void _show_search(bool p_focus_replace = false, bool p_show_only = false);
|
||||
void _hide_bar();
|
||||
|
||||
void _editor_text_changed();
|
||||
void _search_options_changed(bool p_pressed);
|
||||
void _search_text_changed(const String &p_text);
|
||||
void _search_text_entered(const String &p_text);
|
||||
void _replace_text_entered(const String &p_text);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
void _unhandled_input(const Ref<InputEvent> &p_event);
|
||||
|
||||
bool _search(uint32_t p_flags, int p_from_line, int p_from_col);
|
||||
|
||||
void _replace();
|
||||
void _replace_all();
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
String get_search_text() const;
|
||||
String get_replace_text() const;
|
||||
|
||||
bool is_case_sensitive() const;
|
||||
bool is_whole_words() const;
|
||||
bool is_selection_only() const;
|
||||
void set_error(const String &p_label);
|
||||
|
||||
void set_text_edit(TextEdit *p_text_edit);
|
||||
|
||||
void popup_search(bool p_show_only = false);
|
||||
void popup_replace();
|
||||
|
||||
bool search_current();
|
||||
bool search_prev();
|
||||
bool search_next();
|
||||
|
||||
EditorFindReplaceBar();
|
||||
};
|
||||
|
||||
#endif // CODE_EDITOR_H
|
@ -1,82 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* code_editor.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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_goto_line_dialog.h"
|
||||
|
||||
#include "scene/gui/line_edit.h"
|
||||
#include "scene/gui/text_edit.h"
|
||||
#include "scene/gui/box_container.h"
|
||||
#include "scene/gui/label.h"
|
||||
|
||||
#include "editor/editor_scale.h"
|
||||
|
||||
void EditorGotoLineDialog::popup_find_line(TextEdit *p_edit) {
|
||||
text_editor = p_edit;
|
||||
|
||||
line->set_text(itos(text_editor->cursor_get_line()));
|
||||
line->select_all();
|
||||
popup_centered(Size2(180, 80) * EDSCALE);
|
||||
line->grab_focus();
|
||||
}
|
||||
|
||||
int EditorGotoLineDialog::get_line() const {
|
||||
return line->get_text().to_int();
|
||||
}
|
||||
|
||||
void EditorGotoLineDialog::ok_pressed() {
|
||||
if (get_line() < 1 || get_line() > text_editor->get_line_count()) {
|
||||
return;
|
||||
}
|
||||
text_editor->unfold_line(get_line() - 1);
|
||||
text_editor->cursor_set_line(get_line() - 1);
|
||||
hide();
|
||||
}
|
||||
|
||||
EditorGotoLineDialog::EditorGotoLineDialog() {
|
||||
set_title(TTR("Go to Line"));
|
||||
|
||||
VBoxContainer *vbc = memnew(VBoxContainer);
|
||||
vbc->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 8 * EDSCALE);
|
||||
vbc->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 8 * EDSCALE);
|
||||
vbc->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -8 * EDSCALE);
|
||||
vbc->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -8 * EDSCALE);
|
||||
add_child(vbc);
|
||||
|
||||
Label *l = memnew(Label);
|
||||
l->set_text(TTR("Line Number:"));
|
||||
vbc->add_child(l);
|
||||
|
||||
line = memnew(LineEdit);
|
||||
vbc->add_child(line);
|
||||
register_text_enter(line);
|
||||
text_editor = nullptr;
|
||||
|
||||
set_hide_on_ok(false);
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
#ifndef EDITOR_GOTO_LINE_DIALOH_H
|
||||
#define EDITOR_GOTO_LINE_DIALOH_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* code_editor.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/gui/dialogs.h"
|
||||
|
||||
class Label;
|
||||
class LineEdit;
|
||||
class TextEdit;
|
||||
|
||||
class EditorGotoLineDialog : public ConfirmationDialog {
|
||||
GDCLASS(EditorGotoLineDialog, ConfirmationDialog);
|
||||
|
||||
Label *line_label;
|
||||
LineEdit *line;
|
||||
|
||||
TextEdit *text_editor;
|
||||
|
||||
virtual void ok_pressed();
|
||||
|
||||
public:
|
||||
void popup_find_line(TextEdit *p_edit);
|
||||
int get_line() const;
|
||||
|
||||
EditorGotoLineDialog();
|
||||
};
|
||||
|
||||
#endif // CODE_EDITOR_H
|
File diff suppressed because it is too large
Load Diff
@ -1,429 +0,0 @@
|
||||
#ifndef EDITOR_SCRIPT_EDITOR_H
|
||||
#define EDITOR_SCRIPT_EDITOR_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* script_editor_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/editor_plugin.h"
|
||||
#include "scene/gui/box_container.h"
|
||||
#include "scene/gui/dialogs.h"
|
||||
#include "scene/gui/panel_container.h"
|
||||
|
||||
#include "scene/resources/text_file.h"
|
||||
|
||||
#include "core/containers/list.h"
|
||||
#include "core/containers/rb_set.h"
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/error/error_list.h"
|
||||
#include "core/math/vector2.h"
|
||||
#include "core/object/object.h"
|
||||
#include "core/object/reference.h"
|
||||
#include "core/object/resource.h"
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/typedefs.h"
|
||||
#include "core/variant/array.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
#include "editor_script_editor_base.h"
|
||||
#include "editor_syntax_highlighter.h"
|
||||
|
||||
class Button;
|
||||
class ConfigFile;
|
||||
class Control;
|
||||
class EditorFileDialog;
|
||||
class EditorHelpSearch;
|
||||
class EditorNode;
|
||||
class HSplitContainer;
|
||||
class InputEvent;
|
||||
class ItemList;
|
||||
class Label;
|
||||
class LineEdit;
|
||||
class MenuButton;
|
||||
class Node;
|
||||
class PopupMenu;
|
||||
class ScriptCreateDialog;
|
||||
class SyntaxHighlighter;
|
||||
class TabContainer;
|
||||
class TextFile;
|
||||
class Texture;
|
||||
class TextureRect;
|
||||
class Timer;
|
||||
class ToolButton;
|
||||
class Tree;
|
||||
class VSplitContainer;
|
||||
class EditorScriptEditorQuickOpen;
|
||||
class EditorScriptEditorDebugger;
|
||||
|
||||
typedef EditorScriptEditorBase *(*CreateEditorScriptEditorFunc)(const RES &p_resource);
|
||||
|
||||
class EditorScriptCodeCompletionCache;
|
||||
class FindInFilesDialog;
|
||||
class FindInFilesPanel;
|
||||
|
||||
class EditorScriptEditor : public PanelContainer {
|
||||
GDCLASS(EditorScriptEditor, PanelContainer);
|
||||
|
||||
EditorNode *editor;
|
||||
enum {
|
||||
FILE_NEW,
|
||||
FILE_NEW_TEXTFILE,
|
||||
FILE_OPEN,
|
||||
FILE_REOPEN_CLOSED,
|
||||
FILE_OPEN_RECENT,
|
||||
FILE_SAVE,
|
||||
FILE_SAVE_AS,
|
||||
FILE_SAVE_ALL,
|
||||
FILE_THEME,
|
||||
FILE_RUN,
|
||||
FILE_CLOSE,
|
||||
CLOSE_DOCS,
|
||||
CLOSE_ALL,
|
||||
CLOSE_OTHER_TABS,
|
||||
TOGGLE_SCRIPTS_PANEL,
|
||||
SHOW_IN_FILE_SYSTEM,
|
||||
FILE_COPY_PATH,
|
||||
FILE_TOOL_RELOAD,
|
||||
FILE_TOOL_RELOAD_SOFT,
|
||||
DEBUG_NEXT,
|
||||
DEBUG_STEP,
|
||||
DEBUG_BREAK,
|
||||
DEBUG_CONTINUE,
|
||||
DEBUG_KEEP_DEBUGGER_OPEN,
|
||||
DEBUG_WITH_EXTERNAL_EDITOR,
|
||||
SEARCH_IN_FILES,
|
||||
REPLACE_IN_FILES,
|
||||
SEARCH_HELP,
|
||||
HELP_SEARCH_FIND,
|
||||
HELP_SEARCH_FIND_NEXT,
|
||||
HELP_SEARCH_FIND_PREVIOUS,
|
||||
WINDOW_MOVE_UP,
|
||||
WINDOW_MOVE_DOWN,
|
||||
WINDOW_NEXT,
|
||||
WINDOW_PREV,
|
||||
WINDOW_SORT,
|
||||
WINDOW_SELECT_BASE = 100
|
||||
};
|
||||
|
||||
enum {
|
||||
THEME_IMPORT,
|
||||
THEME_RELOAD,
|
||||
THEME_SAVE,
|
||||
THEME_SAVE_AS
|
||||
};
|
||||
|
||||
enum ScriptSortBy {
|
||||
SORT_BY_NAME,
|
||||
SORT_BY_PATH,
|
||||
SORT_BY_NONE
|
||||
};
|
||||
|
||||
enum ScriptListName {
|
||||
DISPLAY_NAME,
|
||||
DISPLAY_DIR_AND_NAME,
|
||||
DISPLAY_FULL_PATH,
|
||||
};
|
||||
|
||||
HBoxContainer *menu_hb;
|
||||
MenuButton *file_menu;
|
||||
MenuButton *edit_menu;
|
||||
MenuButton *script_search_menu;
|
||||
MenuButton *debug_menu;
|
||||
PopupMenu *context_menu;
|
||||
Timer *autosave_timer;
|
||||
uint64_t idle;
|
||||
|
||||
PopupMenu *recent_scripts;
|
||||
PopupMenu *theme_submenu;
|
||||
|
||||
Button *help_search;
|
||||
EditorHelpSearch *help_search_dialog;
|
||||
|
||||
ItemList *script_list;
|
||||
HSplitContainer *script_split;
|
||||
ItemList *members_overview;
|
||||
LineEdit *filter_scripts;
|
||||
LineEdit *filter_methods;
|
||||
VBoxContainer *scripts_vbox;
|
||||
VBoxContainer *overview_vbox;
|
||||
HBoxContainer *buttons_hbox;
|
||||
Label *filename;
|
||||
ToolButton *members_overview_alphabeta_sort_button;
|
||||
bool members_overview_enabled;
|
||||
ItemList *help_overview;
|
||||
bool help_overview_enabled;
|
||||
VSplitContainer *list_split;
|
||||
TabContainer *tab_container;
|
||||
EditorFileDialog *file_dialog;
|
||||
AcceptDialog *error_dialog;
|
||||
ConfirmationDialog *erase_tab_confirm;
|
||||
ScriptCreateDialog *script_create_dialog;
|
||||
EditorScriptEditorDebugger *debugger;
|
||||
ToolButton *scripts_visible;
|
||||
|
||||
String current_theme;
|
||||
|
||||
TextureRect *script_icon;
|
||||
Label *script_name_label;
|
||||
|
||||
ToolButton *script_back;
|
||||
ToolButton *script_forward;
|
||||
|
||||
FindInFilesDialog *find_in_files_dialog;
|
||||
FindInFilesPanel *find_in_files;
|
||||
Button *find_in_files_button;
|
||||
|
||||
enum {
|
||||
SCRIPT_EDITOR_FUNC_MAX = 32,
|
||||
SYNTAX_HIGHLIGHTER_FUNC_MAX = 32
|
||||
};
|
||||
|
||||
static int script_editor_func_count;
|
||||
static CreateEditorScriptEditorFunc script_editor_funcs[SCRIPT_EDITOR_FUNC_MAX];
|
||||
|
||||
Vector<Ref<EditorSyntaxHighlighter>> syntax_highlighters;
|
||||
|
||||
struct ScriptHistory {
|
||||
Control *control;
|
||||
Variant state;
|
||||
};
|
||||
|
||||
Vector<ScriptHistory> history;
|
||||
int history_pos;
|
||||
|
||||
List<String> previous_scripts;
|
||||
List<int> script_close_queue;
|
||||
|
||||
void _tab_changed(int p_which);
|
||||
void _menu_option(int p_option);
|
||||
void _update_debug_options();
|
||||
void _theme_option(int p_option);
|
||||
void _show_save_theme_as_dialog();
|
||||
bool _has_docs_tab() const;
|
||||
bool _has_script_tab() const;
|
||||
void _prepare_file_menu();
|
||||
|
||||
Tree *disk_changed_list;
|
||||
ConfirmationDialog *disk_changed;
|
||||
|
||||
bool restoring_layout;
|
||||
|
||||
String _get_debug_tooltip(const String &p_text, Node *_se);
|
||||
|
||||
void _resave_scripts(const String &p_str);
|
||||
|
||||
bool _test_script_times_on_disk(RES p_for_script = Ref<Resource>());
|
||||
|
||||
void _add_recent_script(String p_path);
|
||||
void _update_recent_scripts();
|
||||
void _open_recent_script(int p_idx);
|
||||
|
||||
void _show_error_dialog(String p_path);
|
||||
|
||||
void _close_tab(int p_idx, bool p_save = true, bool p_history_back = true);
|
||||
|
||||
void _close_current_tab(bool p_save = true);
|
||||
void _close_discard_current_tab(const String &p_str);
|
||||
void _close_docs_tab();
|
||||
void _close_other_tabs();
|
||||
void _close_all_tabs();
|
||||
void _queue_close_tabs();
|
||||
|
||||
void _copy_script_path();
|
||||
|
||||
void _ask_close_current_unsaved_tab(EditorScriptEditorBase *current);
|
||||
|
||||
bool grab_focus_block;
|
||||
|
||||
bool pending_auto_reload;
|
||||
bool auto_reload_running_scripts;
|
||||
void _trigger_live_script_reload();
|
||||
void _live_auto_reload_running_scripts();
|
||||
|
||||
void _update_selected_editor_menu();
|
||||
|
||||
EditorScriptCodeCompletionCache *completion_cache;
|
||||
|
||||
void _editor_play();
|
||||
void _editor_pause();
|
||||
void _editor_stop();
|
||||
|
||||
int edit_pass;
|
||||
|
||||
void _add_callback(Object *p_obj, const String &p_function, const PoolStringArray &p_args);
|
||||
void _res_saved_callback(const Ref<Resource> &p_res);
|
||||
void _scene_saved_callback(const String &p_path);
|
||||
|
||||
bool trim_trailing_whitespace_on_save;
|
||||
bool use_space_indentation;
|
||||
bool convert_indent_on_save;
|
||||
|
||||
void _goto_script_line2(int p_line);
|
||||
void _goto_script_line(REF p_script, int p_line);
|
||||
void _set_execution(REF p_script, int p_line);
|
||||
void _clear_execution(REF p_script);
|
||||
void _breaked(bool p_breaked, bool p_can_debug, const String &p_reason, bool p_has_stackdump);
|
||||
void _show_debugger(bool p_show);
|
||||
void _script_created(Ref<Script> p_script);
|
||||
|
||||
EditorScriptEditorBase *_get_current_editor() const;
|
||||
Control *_get_base_editor() const;
|
||||
|
||||
void _save_layout();
|
||||
void _editor_settings_changed();
|
||||
void _autosave_scripts();
|
||||
void _update_autosave_timer();
|
||||
|
||||
void _update_members_overview_visibility();
|
||||
void _update_members_overview();
|
||||
void _toggle_members_overview_alpha_sort(bool p_alphabetic_sort);
|
||||
void _filter_scripts_text_changed(const String &p_newtext);
|
||||
void _filter_methods_text_changed(const String &p_newtext);
|
||||
void _update_script_names();
|
||||
void _update_script_connections();
|
||||
bool _sort_list_on_update;
|
||||
|
||||
void _members_overview_selected(int p_idx);
|
||||
void _script_selected(int p_idx);
|
||||
|
||||
void _update_help_overview_visibility();
|
||||
void _update_help_overview();
|
||||
void _help_overview_selected(int p_idx);
|
||||
|
||||
void _find_scripts(Node *p_base, Node *p_current, RBSet<Ref<Script>> &used);
|
||||
|
||||
void _tree_changed();
|
||||
|
||||
void _script_split_dragged(float);
|
||||
|
||||
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
|
||||
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
|
||||
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
|
||||
|
||||
void _input(const Ref<InputEvent> &p_event);
|
||||
void _shortcut_input(const Ref<InputEvent> &p_event);
|
||||
|
||||
void _script_list_gui_input(const Ref<InputEvent> &ev);
|
||||
void _make_script_list_context_menu();
|
||||
|
||||
void _help_search(String p_text);
|
||||
|
||||
void _history_forward();
|
||||
void _history_back();
|
||||
|
||||
bool waiting_update_names;
|
||||
|
||||
void _help_class_open(const String &p_class);
|
||||
void _help_class_goto(const String &p_desc);
|
||||
void _update_history_arrows();
|
||||
void _save_history();
|
||||
void _go_to_tab(int p_idx);
|
||||
void _update_history_pos(int p_new_pos);
|
||||
void _update_script_colors();
|
||||
void _update_modified_scripts_for_external_editor(Ref<Script> p_for_script = Ref<Script>());
|
||||
|
||||
void _script_changed();
|
||||
int file_dialog_option;
|
||||
void _file_dialog_action(String p_file);
|
||||
|
||||
Ref<Script> _get_current_script();
|
||||
Array _get_open_scripts() const;
|
||||
|
||||
Ref<TextFile> _load_text_file(const String &p_path, Error *r_error);
|
||||
Error _save_text_file(Ref<TextFile> p_text_file, const String &p_path);
|
||||
|
||||
void _on_find_in_files_requested(String text);
|
||||
void _on_replace_in_files_requested(String text);
|
||||
void _on_find_in_files_result_selected(String fpath, int line_number, int begin, int end);
|
||||
void _start_find_in_files(bool with_replace);
|
||||
void _on_find_in_files_modified_files(PoolStringArray paths);
|
||||
|
||||
static void _open_script_request(const String &p_path);
|
||||
|
||||
static EditorScriptEditor *script_editor;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
static EditorScriptEditor *get_singleton() { return script_editor; }
|
||||
|
||||
bool toggle_scripts_panel();
|
||||
bool is_scripts_panel_toggled();
|
||||
void ensure_focus_current();
|
||||
void apply_scripts() const;
|
||||
void open_script_create_dialog(const String &p_base_name, const String &p_base_path);
|
||||
void reload_scripts();
|
||||
|
||||
void ensure_select_current();
|
||||
|
||||
_FORCE_INLINE_ bool edit(const RES &p_resource, bool p_grab_focus = true) { return edit(p_resource, -1, 0, p_grab_focus); }
|
||||
bool edit(const RES &p_resource, int p_line, int p_col, bool p_grab_focus = true);
|
||||
|
||||
void get_breakpoints(List<String> *p_breakpoints);
|
||||
|
||||
void save_current_script();
|
||||
void save_all_scripts();
|
||||
|
||||
void set_window_layout(Ref<ConfigFile> p_layout);
|
||||
void get_window_layout(Ref<ConfigFile> p_layout);
|
||||
|
||||
void set_scene_root_script(Ref<Script> p_script);
|
||||
Vector<Ref<Script>> get_open_scripts() const;
|
||||
|
||||
bool script_goto_method(Ref<Script> p_script, const String &p_method);
|
||||
|
||||
virtual void edited_scene_changed();
|
||||
|
||||
void notify_script_close(const Ref<Script> &p_script);
|
||||
void notify_script_changed(const Ref<Script> &p_script);
|
||||
|
||||
void close_builtin_scripts_from_scene(const String &p_scene);
|
||||
|
||||
void goto_help(const String &p_desc) { _help_class_goto(p_desc); }
|
||||
|
||||
bool can_take_away_focus() const;
|
||||
|
||||
VSplitContainer *get_left_list_split() { return list_split; }
|
||||
|
||||
EditorScriptEditorDebugger *get_debugger() { return debugger; }
|
||||
void set_live_auto_reload_running_scripts(bool p_enabled);
|
||||
|
||||
void register_syntax_highlighter(const Ref<EditorSyntaxHighlighter> &p_syntax_highlighter);
|
||||
void unregister_syntax_highlighter(const Ref<EditorSyntaxHighlighter> &p_syntax_highlighter);
|
||||
|
||||
static void register_create_script_editor_function(CreateEditorScriptEditorFunc p_func);
|
||||
|
||||
EditorScriptEditor(EditorNode *p_editor);
|
||||
~EditorScriptEditor();
|
||||
};
|
||||
|
||||
#endif // SCRIPT_EDITOR_PLUGIN_H
|
@ -1,45 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* script_editor_plugin.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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_script_editor_base.h"
|
||||
|
||||
#include "editor_syntax_highlighter.h"
|
||||
|
||||
void EditorScriptEditorBase::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("name_changed"));
|
||||
ADD_SIGNAL(MethodInfo("edited_script_changed"));
|
||||
ADD_SIGNAL(MethodInfo("request_help", PropertyInfo(Variant::STRING, "topic")));
|
||||
ADD_SIGNAL(MethodInfo("request_open_script_at_line", PropertyInfo(Variant::OBJECT, "script"), PropertyInfo(Variant::INT, "line")));
|
||||
ADD_SIGNAL(MethodInfo("request_save_history"));
|
||||
ADD_SIGNAL(MethodInfo("go_to_help", PropertyInfo(Variant::STRING, "what")));
|
||||
// TODO: This signal is no use for VisualScript.
|
||||
ADD_SIGNAL(MethodInfo("search_in_files_requested", PropertyInfo(Variant::STRING, "text")));
|
||||
ADD_SIGNAL(MethodInfo("replace_in_files_requested", PropertyInfo(Variant::STRING, "text")));
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
#ifndef EDITOR_SCRIPT_EDITOR_BASE_H
|
||||
#define EDITOR_SCRIPT_EDITOR_BASE_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* script_editor_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/gui/box_container.h"
|
||||
|
||||
class EditorSyntaxHighlighter;
|
||||
class Texture;
|
||||
|
||||
class EditorScriptEditorBase : public VBoxContainer {
|
||||
GDCLASS(EditorScriptEditorBase, VBoxContainer);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) = 0;
|
||||
virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) = 0;
|
||||
|
||||
virtual void apply_code() = 0;
|
||||
virtual RES get_edited_resource() const = 0;
|
||||
virtual Vector<String> get_functions() = 0;
|
||||
virtual void set_edited_resource(const RES &p_res) = 0;
|
||||
virtual void enable_editor() = 0;
|
||||
virtual void reload_text() = 0;
|
||||
virtual String get_name() = 0;
|
||||
virtual Ref<Texture> get_icon() = 0;
|
||||
virtual bool is_unsaved() = 0;
|
||||
virtual Variant get_edit_state() = 0;
|
||||
virtual void set_edit_state(const Variant &p_state) = 0;
|
||||
virtual void goto_line(int p_line, bool p_with_error = false) = 0;
|
||||
virtual void set_executing_line(int p_line) = 0;
|
||||
virtual void clear_executing_line() = 0;
|
||||
virtual void trim_trailing_whitespace() = 0;
|
||||
virtual void insert_final_newline() = 0;
|
||||
virtual void convert_indent_to_spaces() = 0;
|
||||
virtual void convert_indent_to_tabs() = 0;
|
||||
virtual void ensure_focus() = 0;
|
||||
virtual void tag_saved_version() = 0;
|
||||
virtual void reload(bool p_soft) {}
|
||||
virtual void get_breakpoints(List<int> *p_breakpoints) = 0;
|
||||
virtual void add_callback(const String &p_function, PoolStringArray p_args) = 0;
|
||||
virtual void update_settings() = 0;
|
||||
virtual void set_debugger_active(bool p_active) = 0;
|
||||
virtual bool can_lose_focus_on_node_selection() { return true; }
|
||||
|
||||
virtual bool show_members_overview() = 0;
|
||||
|
||||
virtual void set_tooltip_request_func(String p_method, Object *p_obj) = 0;
|
||||
virtual Control *get_edit_menu() = 0;
|
||||
virtual void clear_edit_menu() = 0;
|
||||
|
||||
virtual void validate() = 0;
|
||||
|
||||
EditorScriptEditorBase() {}
|
||||
};
|
||||
|
||||
#endif // SCRIPT_EDITOR_PLUGIN_H
|
@ -1,136 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* script_editor_plugin.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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_script_editor_quick_open.h"
|
||||
|
||||
#include "core/os/keyboard.h"
|
||||
|
||||
#include "scene/gui/button.h"
|
||||
#include "scene/gui/line_edit.h"
|
||||
#include "scene/gui/tree.h"
|
||||
#include "scene/gui/box_container.h"
|
||||
|
||||
void EditorScriptEditorQuickOpen::popup_dialog(const Vector<String> &p_functions, bool p_dontclear) {
|
||||
popup_centered_ratio(0.6);
|
||||
if (p_dontclear) {
|
||||
search_box->select_all();
|
||||
} else {
|
||||
search_box->clear();
|
||||
}
|
||||
search_box->grab_focus();
|
||||
functions = p_functions;
|
||||
_update_search();
|
||||
}
|
||||
|
||||
void EditorScriptEditorQuickOpen::_text_changed(const String &p_newtext) {
|
||||
_update_search();
|
||||
}
|
||||
|
||||
void EditorScriptEditorQuickOpen::_sbox_input(const Ref<InputEvent> &p_ie) {
|
||||
Ref<InputEventKey> k = p_ie;
|
||||
|
||||
if (k.is_valid() && (k->get_scancode() == KEY_UP || k->get_scancode() == KEY_DOWN || k->get_scancode() == KEY_PAGEUP || k->get_scancode() == KEY_PAGEDOWN)) {
|
||||
search_options->call("_gui_input", k);
|
||||
search_box->accept_event();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorScriptEditorQuickOpen::_update_search() {
|
||||
search_options->clear();
|
||||
TreeItem *root = search_options->create_item();
|
||||
|
||||
for (int i = 0; i < functions.size(); i++) {
|
||||
String file = functions[i];
|
||||
if ((search_box->get_text() == "" || file.findn(search_box->get_text()) != -1)) {
|
||||
TreeItem *ti = search_options->create_item(root);
|
||||
ti->set_text(0, file);
|
||||
if (root->get_children() == ti) {
|
||||
ti->select(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get_ok()->set_disabled(root->get_children() == nullptr);
|
||||
}
|
||||
|
||||
void EditorScriptEditorQuickOpen::_confirmed() {
|
||||
TreeItem *ti = search_options->get_selected();
|
||||
if (!ti) {
|
||||
return;
|
||||
}
|
||||
int line = ti->get_text(0).get_slice(":", 1).to_int();
|
||||
|
||||
emit_signal("goto_line", line - 1);
|
||||
hide();
|
||||
}
|
||||
|
||||
void EditorScriptEditorQuickOpen::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
connect("confirmed", this, "_confirmed");
|
||||
|
||||
search_box->set_clear_button_enabled(true);
|
||||
FALLTHROUGH;
|
||||
}
|
||||
case NOTIFICATION_THEME_CHANGED: {
|
||||
search_box->set_right_icon(get_theme_icon("Search", "EditorIcons"));
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
disconnect("confirmed", this, "_confirmed");
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorScriptEditorQuickOpen::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("_text_changed"), &EditorScriptEditorQuickOpen::_text_changed);
|
||||
ClassDB::bind_method(D_METHOD("_confirmed"), &EditorScriptEditorQuickOpen::_confirmed);
|
||||
ClassDB::bind_method(D_METHOD("_sbox_input"), &EditorScriptEditorQuickOpen::_sbox_input);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("goto_line", PropertyInfo(Variant::INT, "line")));
|
||||
}
|
||||
|
||||
EditorScriptEditorQuickOpen::EditorScriptEditorQuickOpen() {
|
||||
VBoxContainer *vbc = memnew(VBoxContainer);
|
||||
add_child(vbc);
|
||||
search_box = memnew(LineEdit);
|
||||
vbc->add_margin_child(TTR("Search:"), search_box);
|
||||
search_box->connect("text_changed", this, "_text_changed");
|
||||
search_box->connect("gui_input", this, "_sbox_input");
|
||||
search_options = memnew(Tree);
|
||||
vbc->add_margin_child(TTR("Matches:"), search_options, true);
|
||||
get_ok()->set_text(TTR("Open"));
|
||||
get_ok()->set_disabled(true);
|
||||
register_text_enter(search_box);
|
||||
set_hide_on_ok(false);
|
||||
search_options->connect("item_activated", this, "_confirmed");
|
||||
search_options->set_hide_root(true);
|
||||
search_options->set_hide_folding(true);
|
||||
search_options->add_theme_constant_override("draw_guides", 1);
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
#ifndef EDITOR_SCRIPT_EDITOR_QUICK_OPEN_H
|
||||
#define EDITOR_SCRIPT_EDITOR_QUICK_OPEN_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* script_editor_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/gui/dialogs.h"
|
||||
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
class LineEdit;
|
||||
class Tree;
|
||||
|
||||
class EditorScriptEditorQuickOpen : public ConfirmationDialog {
|
||||
GDCLASS(EditorScriptEditorQuickOpen, ConfirmationDialog);
|
||||
|
||||
LineEdit *search_box;
|
||||
Tree *search_options;
|
||||
String function;
|
||||
|
||||
void _update_search();
|
||||
|
||||
void _sbox_input(const Ref<InputEvent> &p_ie);
|
||||
Vector<String> functions;
|
||||
|
||||
void _confirmed();
|
||||
void _text_changed(const String &p_newtext);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void popup_dialog(const Vector<String> &p_functions, bool p_dontclear = false);
|
||||
EditorScriptEditorQuickOpen();
|
||||
};
|
||||
|
||||
#endif // SCRIPT_EDITOR_PLUGIN_H
|
File diff suppressed because it is too large
Load Diff
@ -1,256 +0,0 @@
|
||||
#ifndef EDITOR_SCRIPT_TEXT_EDITOR_H
|
||||
#define EDITOR_SCRIPT_TEXT_EDITOR_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* script_text_editor.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/gui/dialogs.h"
|
||||
|
||||
#include "editor_script_editor_base.h"
|
||||
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/object/reference.h"
|
||||
|
||||
#include "editor_code_text_editor.h"
|
||||
|
||||
#include "core/containers/list.h"
|
||||
#include "core/containers/rb_map.h"
|
||||
#include "core/math/color.h"
|
||||
#include "core/math/vector2.h"
|
||||
#include "core/object/object.h"
|
||||
#include "core/object/resource.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
class ColorPicker;
|
||||
class Control;
|
||||
class HBoxContainer;
|
||||
class InputEvent;
|
||||
class Label;
|
||||
class MenuButton;
|
||||
class Node;
|
||||
class PopupMenu;
|
||||
class PopupPanel;
|
||||
class RichTextLabel;
|
||||
class Script;
|
||||
class SyntaxHighlighter;
|
||||
class Texture;
|
||||
class Tree;
|
||||
struct ScriptCodeCompletionOption;
|
||||
class EditorScriptEditorQuickOpen;
|
||||
class EditorConnectionInfoDialog;
|
||||
class EditorSyntaxHighlighter;
|
||||
|
||||
class EditorScriptTextEditor : public EditorScriptEditorBase {
|
||||
GDCLASS(EditorScriptTextEditor, EditorScriptEditorBase);
|
||||
|
||||
EditorCodeTextEditor *code_editor;
|
||||
RichTextLabel *warnings_panel;
|
||||
|
||||
Ref<Script> script;
|
||||
bool script_is_valid;
|
||||
bool editor_enabled;
|
||||
|
||||
Vector<String> functions;
|
||||
|
||||
List<Connection> missing_connections;
|
||||
|
||||
Vector<String> member_keywords;
|
||||
|
||||
HBoxContainer *edit_hb;
|
||||
|
||||
MenuButton *edit_menu;
|
||||
MenuButton *search_menu;
|
||||
MenuButton *goto_menu;
|
||||
PopupMenu *bookmarks_menu;
|
||||
PopupMenu *breakpoints_menu;
|
||||
PopupMenu *highlighter_menu;
|
||||
PopupMenu *context_menu;
|
||||
PopupMenu *convert_case;
|
||||
|
||||
EditorGotoLineDialog *goto_line_dialog;
|
||||
EditorScriptEditorQuickOpen *quick_open;
|
||||
EditorConnectionInfoDialog *connection_info_dialog;
|
||||
|
||||
PopupPanel *color_panel;
|
||||
ColorPicker *color_picker;
|
||||
Vector2 color_position;
|
||||
String color_args;
|
||||
|
||||
bool theme_loaded;
|
||||
|
||||
enum {
|
||||
EDIT_UNDO,
|
||||
EDIT_REDO,
|
||||
EDIT_CUT,
|
||||
EDIT_COPY,
|
||||
EDIT_PASTE,
|
||||
EDIT_SELECT_ALL,
|
||||
EDIT_COMPLETE,
|
||||
EDIT_AUTO_INDENT,
|
||||
EDIT_TRIM_TRAILING_WHITESAPCE,
|
||||
EDIT_CONVERT_INDENT_TO_SPACES,
|
||||
EDIT_CONVERT_INDENT_TO_TABS,
|
||||
EDIT_TOGGLE_COMMENT,
|
||||
EDIT_MOVE_LINE_UP,
|
||||
EDIT_MOVE_LINE_DOWN,
|
||||
EDIT_INDENT_RIGHT,
|
||||
EDIT_INDENT_LEFT,
|
||||
EDIT_DELETE_LINE,
|
||||
EDIT_DUPLICATE_SELECTION,
|
||||
EDIT_PICK_COLOR,
|
||||
EDIT_TO_UPPERCASE,
|
||||
EDIT_TO_LOWERCASE,
|
||||
EDIT_CAPITALIZE,
|
||||
EDIT_EVALUATE,
|
||||
EDIT_TOGGLE_FOLD_LINE,
|
||||
EDIT_FOLD_ALL_LINES,
|
||||
EDIT_UNFOLD_ALL_LINES,
|
||||
SEARCH_FIND,
|
||||
SEARCH_FIND_NEXT,
|
||||
SEARCH_FIND_PREV,
|
||||
SEARCH_REPLACE,
|
||||
SEARCH_LOCATE_FUNCTION,
|
||||
SEARCH_GOTO_LINE,
|
||||
SEARCH_IN_FILES,
|
||||
REPLACE_IN_FILES,
|
||||
BOOKMARK_TOGGLE,
|
||||
BOOKMARK_GOTO_NEXT,
|
||||
BOOKMARK_GOTO_PREV,
|
||||
BOOKMARK_REMOVE_ALL,
|
||||
DEBUG_TOGGLE_BREAKPOINT,
|
||||
DEBUG_REMOVE_ALL_BREAKPOINTS,
|
||||
DEBUG_GOTO_NEXT_BREAKPOINT,
|
||||
DEBUG_GOTO_PREV_BREAKPOINT,
|
||||
HELP_CONTEXTUAL,
|
||||
LOOKUP_SYMBOL,
|
||||
};
|
||||
|
||||
static EditorScriptEditorBase *create_editor(const RES &p_resource);
|
||||
|
||||
void _enable_code_editor();
|
||||
|
||||
protected:
|
||||
void _update_breakpoint_list();
|
||||
void _breakpoint_item_pressed(int p_idx);
|
||||
void _breakpoint_toggled(int p_row);
|
||||
|
||||
void _validate_script(); // No longer virtual.
|
||||
void _update_bookmark_list();
|
||||
void _bookmark_item_pressed(int p_idx);
|
||||
|
||||
static void _code_complete_scripts(void *p_ud, const String &p_code, List<ScriptCodeCompletionOption> *r_options, bool &r_force);
|
||||
void _code_complete_script(const String &p_code, List<ScriptCodeCompletionOption> *r_options, bool &r_force);
|
||||
|
||||
void _load_theme_settings();
|
||||
void _set_theme_for_script();
|
||||
void _show_warnings_panel(bool p_show);
|
||||
void _warning_clicked(Variant p_line);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
RBMap<String, Ref<EditorSyntaxHighlighter>> highlighters;
|
||||
void _change_syntax_highlighter(int p_idx);
|
||||
|
||||
void _edit_option(int p_op);
|
||||
void _edit_option_toggle_inline_comment();
|
||||
void _make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, Vector2 p_pos);
|
||||
void _text_edit_gui_input(const Ref<InputEvent> &ev);
|
||||
void _color_changed(const Color &p_color);
|
||||
void _prepare_edit_menu();
|
||||
|
||||
void _goto_line(int p_line) { goto_line(p_line); }
|
||||
void _lookup_symbol(const String &p_symbol, int p_row, int p_column);
|
||||
|
||||
void _lookup_connections(int p_row, String p_method);
|
||||
|
||||
void _convert_case(EditorCodeTextEditor::CaseStyle p_case);
|
||||
|
||||
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
|
||||
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
|
||||
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
|
||||
|
||||
String _get_absolute_path(const String &rel_path);
|
||||
|
||||
public:
|
||||
void _update_connected_methods();
|
||||
|
||||
virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter);
|
||||
virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter);
|
||||
void update_toggle_scripts_button();
|
||||
|
||||
virtual void apply_code();
|
||||
virtual RES get_edited_resource() const;
|
||||
virtual void set_edited_resource(const RES &p_res);
|
||||
virtual void enable_editor();
|
||||
virtual Vector<String> get_functions();
|
||||
virtual void reload_text();
|
||||
virtual String get_name();
|
||||
virtual Ref<Texture> get_icon();
|
||||
virtual bool is_unsaved();
|
||||
virtual Variant get_edit_state();
|
||||
virtual void set_edit_state(const Variant &p_state);
|
||||
virtual void ensure_focus();
|
||||
virtual void trim_trailing_whitespace();
|
||||
virtual void insert_final_newline();
|
||||
virtual void convert_indent_to_spaces();
|
||||
virtual void convert_indent_to_tabs();
|
||||
virtual void tag_saved_version();
|
||||
|
||||
virtual void goto_line(int p_line, bool p_with_error = false);
|
||||
void goto_line_selection(int p_line, int p_begin, int p_end);
|
||||
void goto_line_centered(int p_line);
|
||||
virtual void set_executing_line(int p_line);
|
||||
virtual void clear_executing_line();
|
||||
|
||||
virtual void reload(bool p_soft);
|
||||
virtual void get_breakpoints(List<int> *p_breakpoints);
|
||||
|
||||
virtual void add_callback(const String &p_function, PoolStringArray p_args);
|
||||
virtual void update_settings();
|
||||
|
||||
virtual bool show_members_overview();
|
||||
|
||||
virtual void set_tooltip_request_func(String p_method, Object *p_obj);
|
||||
|
||||
virtual void set_debugger_active(bool p_active);
|
||||
|
||||
Control *get_edit_menu();
|
||||
Control *get_code_editor_text_edit();
|
||||
virtual void clear_edit_menu();
|
||||
static void register_editor();
|
||||
|
||||
virtual void validate();
|
||||
|
||||
EditorScriptTextEditor();
|
||||
~EditorScriptTextEditor();
|
||||
};
|
||||
|
||||
#endif // SCRIPT_TEXT_EDITOR_H
|
@ -1,234 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* script_editor_plugin.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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_syntax_highlighter.h"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "editor/editor_settings.h"
|
||||
|
||||
#include "editor_script_editor.h"
|
||||
/*** SYNTAX HIGHLIGHTER ****/
|
||||
|
||||
String EditorSyntaxHighlighter::_get_name() const {
|
||||
ScriptInstance *si = get_script_instance();
|
||||
if (si && si->has_method("_get_name")) {
|
||||
return si->call("_get_name");
|
||||
}
|
||||
return "Unnamed";
|
||||
}
|
||||
|
||||
Array EditorSyntaxHighlighter::_get_supported_languages() const {
|
||||
ScriptInstance *si = get_script_instance();
|
||||
if (si && si->has_method("_get_supported_languages")) {
|
||||
return si->call("_get_supported_languages");
|
||||
}
|
||||
return Array();
|
||||
}
|
||||
|
||||
Ref<EditorSyntaxHighlighter> EditorSyntaxHighlighter::_create() const {
|
||||
Ref<EditorSyntaxHighlighter> syntax_highlighter;
|
||||
syntax_highlighter.instance();
|
||||
if (get_script_instance()) {
|
||||
syntax_highlighter->set_script(get_script_instance()->get_script().get_ref_ptr());
|
||||
}
|
||||
return syntax_highlighter;
|
||||
}
|
||||
|
||||
EditorSyntaxHighlighter::EditorSyntaxHighlighter() {
|
||||
}
|
||||
EditorSyntaxHighlighter::~EditorSyntaxHighlighter() {
|
||||
}
|
||||
|
||||
void EditorSyntaxHighlighter::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("_get_edited_resource"), &EditorSyntaxHighlighter::_get_edited_resource);
|
||||
|
||||
BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_name"));
|
||||
BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_supported_languages"));
|
||||
BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_supported_extentions"));
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
void EditorStandardSyntaxHighlighter::_update_cache() {
|
||||
highlighter->set_text_edit(text_edit);
|
||||
highlighter->clear_keyword_colors();
|
||||
highlighter->clear_member_keyword_colors();
|
||||
highlighter->clear_color_regions();
|
||||
|
||||
highlighter->set_symbol_color(EDITOR_GET("text_editor/highlighting/symbol_color"));
|
||||
highlighter->set_function_color(EDITOR_GET("text_editor/highlighting/function_color"));
|
||||
highlighter->set_number_color(EDITOR_GET("text_editor/highlighting/number_color"));
|
||||
highlighter->set_member_variable_color(EDITOR_GET("text_editor/highlighting/member_variable_color"));
|
||||
|
||||
/* Engine types. */
|
||||
const Color type_color = EDITOR_GET("text_editor/highlighting/engine_type_color");
|
||||
List<StringName> types;
|
||||
ClassDB::get_class_list(&types);
|
||||
for (List<StringName>::Element *E = types.front(); E; E = E->next()) {
|
||||
String n = E->get();
|
||||
if (n.begins_with("_")) {
|
||||
n = n.substr(1, n.length());
|
||||
}
|
||||
highlighter->add_keyword_color(n, type_color);
|
||||
}
|
||||
|
||||
/* User types. */
|
||||
const Color usertype_color = EDITOR_GET("text_editor/highlighting/user_type_color");
|
||||
List<StringName> global_classes;
|
||||
ScriptServer::get_global_class_list(&global_classes);
|
||||
for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) {
|
||||
highlighter->add_keyword_color(E->get(), usertype_color);
|
||||
}
|
||||
|
||||
/* Autoloads. */
|
||||
List<PropertyInfo> props;
|
||||
ProjectSettings::get_singleton()->get_property_list(&props);
|
||||
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
|
||||
const PropertyInfo &pi = E->get();
|
||||
|
||||
if (!pi.name.begins_with("autoload/")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = pi.name.get_slice("/", 1);
|
||||
String path = ProjectSettings::get_singleton()->get(pi.name);
|
||||
|
||||
if (name.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool is_singleton = path.begins_with("*");
|
||||
|
||||
if (is_singleton) {
|
||||
highlighter->add_keyword_color(name, usertype_color);
|
||||
}
|
||||
}
|
||||
|
||||
const Ref<Script> script = _get_edited_resource();
|
||||
if (script.is_valid()) {
|
||||
/* Core types. */
|
||||
const Color basetype_color = EDITOR_GET("text_editor/highlighting/base_type_color");
|
||||
List<String> core_types;
|
||||
script->get_language()->get_core_type_words(&core_types);
|
||||
for (List<String>::Element *E = core_types.front(); E; E = E->next()) {
|
||||
highlighter->add_keyword_color(E->get(), basetype_color);
|
||||
}
|
||||
|
||||
/* Reserved words. */
|
||||
const Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color");
|
||||
const Color control_flow_keyword_color = EDITOR_GET("text_editor/highlighting/control_flow_keyword_color");
|
||||
List<String> keywords;
|
||||
script->get_language()->get_reserved_words(&keywords);
|
||||
for (List<String>::Element *E = keywords.front(); E; E = E->next()) {
|
||||
if (script->get_language()->is_control_flow_keyword(E->get())) {
|
||||
highlighter->add_keyword_color(E->get(), control_flow_keyword_color);
|
||||
} else {
|
||||
highlighter->add_keyword_color(E->get(), keyword_color);
|
||||
}
|
||||
}
|
||||
|
||||
/* Member types. */
|
||||
const Color member_variable_color = EDITOR_GET("text_editor/highlighting/member_variable_color");
|
||||
StringName instance_base = script->get_instance_base_type();
|
||||
if (instance_base != StringName()) {
|
||||
List<PropertyInfo> plist;
|
||||
ClassDB::get_property_list(instance_base, &plist);
|
||||
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
|
||||
String name = E->get().name;
|
||||
if (E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_GROUP) {
|
||||
continue;
|
||||
}
|
||||
if (name.find("/") != -1) {
|
||||
continue;
|
||||
}
|
||||
highlighter->add_member_keyword_color(name, member_variable_color);
|
||||
}
|
||||
|
||||
List<String> clist;
|
||||
ClassDB::get_integer_constant_list(instance_base, &clist);
|
||||
for (List<String>::Element *E = clist.front(); E; E = E->next()) {
|
||||
highlighter->add_member_keyword_color(E->get(), member_variable_color);
|
||||
}
|
||||
}
|
||||
|
||||
/* Comments */
|
||||
const Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color");
|
||||
List<String> comments;
|
||||
script->get_language()->get_comment_delimiters(&comments);
|
||||
for (List<String>::Element *E = comments.front(); E; E = E->next()) {
|
||||
String comment = E->get();
|
||||
String beg = comment.get_slice(" ", 0);
|
||||
String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String();
|
||||
highlighter->add_color_region(beg, end, comment_color, end == "");
|
||||
}
|
||||
|
||||
/* Strings */
|
||||
const Color string_color = EDITOR_GET("text_editor/highlighting/string_color");
|
||||
List<String> strings;
|
||||
script->get_language()->get_string_delimiters(&strings);
|
||||
for (List<String>::Element *E = strings.front(); E; E = E->next()) {
|
||||
String string = E->get();
|
||||
String beg = string.get_slice(" ", 0);
|
||||
String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String();
|
||||
highlighter->add_color_region(beg, end, string_color, end == "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ref<EditorSyntaxHighlighter> EditorStandardSyntaxHighlighter::_create() const {
|
||||
Ref<EditorStandardSyntaxHighlighter> syntax_highlighter;
|
||||
syntax_highlighter.instance();
|
||||
return syntax_highlighter;
|
||||
}
|
||||
|
||||
EditorStandardSyntaxHighlighter::EditorStandardSyntaxHighlighter() {
|
||||
highlighter.instance();
|
||||
}
|
||||
EditorStandardSyntaxHighlighter::~EditorStandardSyntaxHighlighter() {
|
||||
}
|
||||
|
||||
void EditorStandardSyntaxHighlighter::_bind_methods() {
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
Ref<EditorSyntaxHighlighter> EditorPlainTextSyntaxHighlighter::_create() const {
|
||||
Ref<EditorPlainTextSyntaxHighlighter> syntax_highlighter;
|
||||
syntax_highlighter.instance();
|
||||
return syntax_highlighter;
|
||||
}
|
||||
|
||||
EditorPlainTextSyntaxHighlighter::EditorPlainTextSyntaxHighlighter() {
|
||||
}
|
||||
EditorPlainTextSyntaxHighlighter::~EditorPlainTextSyntaxHighlighter() {
|
||||
}
|
||||
|
||||
void EditorPlainTextSyntaxHighlighter::_bind_methods() {
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
#ifndef EDITOR_SYNTAX_HIGHLIGHTER_H
|
||||
#define EDITOR_SYNTAX_HIGHLIGHTER_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* script_editor_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/editor_plugin.h"
|
||||
|
||||
#include "scene/gui/resources/syntax_highlighter.h"
|
||||
|
||||
class EditorSyntaxHighlighter : public SyntaxHighlighter {
|
||||
GDCLASS(EditorSyntaxHighlighter, SyntaxHighlighter)
|
||||
|
||||
public:
|
||||
virtual String _get_name() const;
|
||||
virtual Array _get_supported_languages() const;
|
||||
|
||||
void _set_edited_resource(const RES &p_res) { edited_resourse = p_res; }
|
||||
REF _get_edited_resource() { return edited_resourse; }
|
||||
|
||||
virtual Ref<EditorSyntaxHighlighter> _create() const;
|
||||
|
||||
EditorSyntaxHighlighter();
|
||||
~EditorSyntaxHighlighter();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
REF edited_resourse;
|
||||
};
|
||||
|
||||
class EditorStandardSyntaxHighlighter : public EditorSyntaxHighlighter {
|
||||
GDCLASS(EditorStandardSyntaxHighlighter, EditorSyntaxHighlighter)
|
||||
|
||||
public:
|
||||
virtual void _update_cache();
|
||||
virtual Dictionary _get_line_syntax_highlighting(int p_line) { return highlighter->get_line_syntax_highlighting(p_line); }
|
||||
|
||||
virtual String _get_name() const { return TTR("Standard"); }
|
||||
|
||||
virtual Ref<EditorSyntaxHighlighter> _create() const;
|
||||
|
||||
EditorStandardSyntaxHighlighter();
|
||||
~EditorStandardSyntaxHighlighter();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Ref<CodeHighlighter> highlighter;
|
||||
};
|
||||
|
||||
class EditorPlainTextSyntaxHighlighter : public EditorSyntaxHighlighter {
|
||||
GDCLASS(EditorPlainTextSyntaxHighlighter, EditorSyntaxHighlighter)
|
||||
|
||||
public:
|
||||
virtual String _get_name() const { return TTR("Plain Text"); }
|
||||
|
||||
virtual Ref<EditorSyntaxHighlighter> _create() const;
|
||||
|
||||
EditorPlainTextSyntaxHighlighter();
|
||||
~EditorPlainTextSyntaxHighlighter();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
};
|
||||
|
||||
#endif // SCRIPT_EDITOR_PLUGIN_H
|
@ -1,701 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* text_editor.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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_text_editor.h"
|
||||
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/input/input_event.h"
|
||||
#include "core/math/transform_2d.h"
|
||||
#include "core/math/vector2.h"
|
||||
#include "core/object/class_db.h"
|
||||
#include "core/os/keyboard.h"
|
||||
#include "core/os/memory.h"
|
||||
#include "core/typedefs.h"
|
||||
#include "core/variant/array.h"
|
||||
#include "core/variant/dictionary.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "scene/gui/box_container.h"
|
||||
#include "scene/main/control.h"
|
||||
#include "scene/gui/menu_button.h"
|
||||
#include "scene/gui/popup_menu.h"
|
||||
#include "scene/gui/text_edit.h"
|
||||
#include "scene/resources/text_file.h"
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
#include "editor_find_replace_bar.h"
|
||||
#include "editor_goto_line_dialog.h"
|
||||
#include "editor_script_editor.h"
|
||||
#include "editor_syntax_highlighter.h"
|
||||
|
||||
void EditorTextEditor::add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) {
|
||||
highlighters[p_highlighter->_get_name()] = p_highlighter;
|
||||
highlighter_menu->add_radio_check_item(p_highlighter->_get_name());
|
||||
}
|
||||
|
||||
void EditorTextEditor::set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) {
|
||||
TextEdit *te = code_editor->get_text_edit();
|
||||
te->set_syntax_highlighter(p_highlighter);
|
||||
highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(p_highlighter->_get_name()), true);
|
||||
}
|
||||
|
||||
void EditorTextEditor::_change_syntax_highlighter(int p_idx) {
|
||||
RBMap<String, Ref<EditorSyntaxHighlighter>>::Element *el = highlighters.front();
|
||||
while (el != nullptr) {
|
||||
highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(el->key()), false);
|
||||
el = el->next();
|
||||
}
|
||||
set_syntax_highlighter(highlighters[highlighter_menu->get_item_text(p_idx)]);
|
||||
}
|
||||
|
||||
void EditorTextEditor::_load_theme_settings() {
|
||||
TextEdit *text_edit = code_editor->get_text_edit();
|
||||
text_edit->get_syntax_highlighter()->update_cache();
|
||||
|
||||
Color background_color = EDITOR_GET("text_editor/highlighting/background_color");
|
||||
Color completion_background_color = EDITOR_GET("text_editor/highlighting/completion_background_color");
|
||||
Color completion_selected_color = EDITOR_GET("text_editor/highlighting/completion_selected_color");
|
||||
Color completion_existing_color = EDITOR_GET("text_editor/highlighting/completion_existing_color");
|
||||
Color completion_scroll_color = EDITOR_GET("text_editor/highlighting/completion_scroll_color");
|
||||
Color completion_font_color = EDITOR_GET("text_editor/highlighting/completion_font_color");
|
||||
Color text_color = EDITOR_GET("text_editor/highlighting/text_color");
|
||||
Color line_number_color = EDITOR_GET("text_editor/highlighting/line_number_color");
|
||||
Color caret_color = EDITOR_GET("text_editor/highlighting/caret_color");
|
||||
Color caret_background_color = EDITOR_GET("text_editor/highlighting/caret_background_color");
|
||||
Color text_selected_color = EDITOR_GET("text_editor/highlighting/text_selected_color");
|
||||
Color selection_color = EDITOR_GET("text_editor/highlighting/selection_color");
|
||||
Color brace_mismatch_color = EDITOR_GET("text_editor/highlighting/brace_mismatch_color");
|
||||
Color current_line_color = EDITOR_GET("text_editor/highlighting/current_line_color");
|
||||
Color line_length_guideline_color = EDITOR_GET("text_editor/highlighting/line_length_guideline_color");
|
||||
Color word_highlighted_color = EDITOR_GET("text_editor/highlighting/word_highlighted_color");
|
||||
Color mark_color = EDITOR_GET("text_editor/highlighting/mark_color");
|
||||
Color bookmark_color = EDITOR_GET("text_editor/highlighting/bookmark_color");
|
||||
Color breakpoint_color = EDITOR_GET("text_editor/highlighting/breakpoint_color");
|
||||
Color executing_line_color = EDITOR_GET("text_editor/highlighting/executing_line_color");
|
||||
Color code_folding_color = EDITOR_GET("text_editor/highlighting/code_folding_color");
|
||||
Color search_result_color = EDITOR_GET("text_editor/highlighting/search_result_color");
|
||||
Color search_result_border_color = EDITOR_GET("text_editor/highlighting/search_result_border_color");
|
||||
|
||||
text_edit->add_theme_color_override("background_color", background_color);
|
||||
text_edit->add_theme_color_override("completion_background_color", completion_background_color);
|
||||
text_edit->add_theme_color_override("completion_selected_color", completion_selected_color);
|
||||
text_edit->add_theme_color_override("completion_existing_color", completion_existing_color);
|
||||
text_edit->add_theme_color_override("completion_scroll_color", completion_scroll_color);
|
||||
text_edit->add_theme_color_override("completion_font_color", completion_font_color);
|
||||
text_edit->add_theme_color_override("font_color", text_color);
|
||||
text_edit->add_theme_color_override("line_number_color", line_number_color);
|
||||
text_edit->add_theme_color_override("caret_color", caret_color);
|
||||
text_edit->add_theme_color_override("caret_background_color", caret_background_color);
|
||||
text_edit->add_theme_color_override("font_color_selected", text_selected_color);
|
||||
text_edit->add_theme_color_override("selection_color", selection_color);
|
||||
text_edit->add_theme_color_override("brace_mismatch_color", brace_mismatch_color);
|
||||
text_edit->add_theme_color_override("current_line_color", current_line_color);
|
||||
text_edit->add_theme_color_override("line_length_guideline_color", line_length_guideline_color);
|
||||
text_edit->add_theme_color_override("word_highlighted_color", word_highlighted_color);
|
||||
text_edit->add_theme_color_override("breakpoint_color", breakpoint_color);
|
||||
text_edit->add_theme_color_override("executing_line_color", executing_line_color);
|
||||
text_edit->add_theme_color_override("mark_color", mark_color);
|
||||
text_edit->add_theme_color_override("bookmark_color", bookmark_color);
|
||||
text_edit->add_theme_color_override("code_folding_color", code_folding_color);
|
||||
text_edit->add_theme_color_override("search_result_color", search_result_color);
|
||||
text_edit->add_theme_color_override("search_result_border_color", search_result_border_color);
|
||||
|
||||
text_edit->add_theme_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 6));
|
||||
}
|
||||
|
||||
String EditorTextEditor::get_name() {
|
||||
String name;
|
||||
|
||||
name = text_file->get_path().get_file();
|
||||
if (name.empty()) {
|
||||
// This appears for newly created built-in text_files before saving the scene.
|
||||
name = TTR("[unsaved]");
|
||||
} else if (text_file->get_path().find("local://") == -1 || text_file->get_path().find("::") == -1) {
|
||||
const String &text_file_name = text_file->get_name();
|
||||
if (text_file_name != "") {
|
||||
// If the built-in text_file has a custom resource name defined,
|
||||
// display the built-in text_file name as follows: `ResourceName (scene_file.tscn)`
|
||||
name = vformat("%s (%s)", text_file_name, name.get_slice("::", 0));
|
||||
}
|
||||
}
|
||||
|
||||
if (is_unsaved()) {
|
||||
name += "(*)";
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
Ref<Texture> EditorTextEditor::get_icon() {
|
||||
return EditorNode::get_singleton()->get_object_icon(text_file.ptr(), "");
|
||||
}
|
||||
|
||||
RES EditorTextEditor::get_edited_resource() const {
|
||||
return text_file;
|
||||
}
|
||||
|
||||
void EditorTextEditor::set_edited_resource(const RES &p_res) {
|
||||
ERR_FAIL_COND(text_file.is_valid());
|
||||
ERR_FAIL_COND(p_res.is_null());
|
||||
|
||||
text_file = p_res;
|
||||
|
||||
code_editor->get_text_edit()->set_text(text_file->get_text());
|
||||
code_editor->get_text_edit()->clear_undo_history();
|
||||
code_editor->get_text_edit()->tag_saved_version();
|
||||
|
||||
emit_signal("name_changed");
|
||||
code_editor->update_line_and_column();
|
||||
}
|
||||
|
||||
void EditorTextEditor::enable_editor() {
|
||||
if (editor_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
editor_enabled = true;
|
||||
|
||||
_load_theme_settings();
|
||||
}
|
||||
|
||||
void EditorTextEditor::add_callback(const String &p_function, PoolStringArray p_args) {
|
||||
}
|
||||
|
||||
void EditorTextEditor::set_debugger_active(bool p_active) {
|
||||
}
|
||||
|
||||
void EditorTextEditor::get_breakpoints(List<int> *p_breakpoints) {
|
||||
}
|
||||
|
||||
void EditorTextEditor::reload_text() {
|
||||
ERR_FAIL_COND(text_file.is_null());
|
||||
|
||||
TextEdit *te = code_editor->get_text_edit();
|
||||
int column = te->cursor_get_column();
|
||||
int row = te->cursor_get_line();
|
||||
int h = te->get_h_scroll();
|
||||
int v = te->get_v_scroll();
|
||||
|
||||
te->set_text(text_file->get_text());
|
||||
te->cursor_set_line(row);
|
||||
te->cursor_set_column(column);
|
||||
te->set_h_scroll(h);
|
||||
te->set_v_scroll(v);
|
||||
|
||||
te->tag_saved_version();
|
||||
|
||||
code_editor->update_line_and_column();
|
||||
}
|
||||
|
||||
void EditorTextEditor::_validate_script() {
|
||||
emit_signal("name_changed");
|
||||
emit_signal("edited_script_changed");
|
||||
}
|
||||
|
||||
void EditorTextEditor::_update_bookmark_list() {
|
||||
bookmarks_menu->clear();
|
||||
|
||||
bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
|
||||
bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL);
|
||||
bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT);
|
||||
bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV);
|
||||
|
||||
Array bookmark_list = code_editor->get_text_edit()->get_bookmarks_array();
|
||||
if (bookmark_list.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
bookmarks_menu->add_separator();
|
||||
|
||||
for (int i = 0; i < bookmark_list.size(); i++) {
|
||||
String line = code_editor->get_text_edit()->get_line(bookmark_list[i]).strip_edges();
|
||||
// Limit the size of the line if too big.
|
||||
if (line.length() > 50) {
|
||||
line = line.substr(0, 50);
|
||||
}
|
||||
|
||||
bookmarks_menu->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\"");
|
||||
bookmarks_menu->set_item_metadata(bookmarks_menu->get_item_count() - 1, bookmark_list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void EditorTextEditor::_bookmark_item_pressed(int p_idx) {
|
||||
if (p_idx < 4) { // Any item before the separator.
|
||||
_edit_option(bookmarks_menu->get_item_id(p_idx));
|
||||
} else {
|
||||
code_editor->goto_line(bookmarks_menu->get_item_metadata(p_idx));
|
||||
}
|
||||
}
|
||||
|
||||
void EditorTextEditor::apply_code() {
|
||||
text_file->set_text(code_editor->get_text_edit()->get_text());
|
||||
}
|
||||
|
||||
bool EditorTextEditor::is_unsaved() {
|
||||
return code_editor->get_text_edit()->get_version() != code_editor->get_text_edit()->get_saved_version();
|
||||
}
|
||||
|
||||
Variant EditorTextEditor::get_edit_state() {
|
||||
return code_editor->get_edit_state();
|
||||
}
|
||||
|
||||
void EditorTextEditor::set_edit_state(const Variant &p_state) {
|
||||
code_editor->set_edit_state(p_state);
|
||||
|
||||
Dictionary state = p_state;
|
||||
if (state.has("syntax_highlighter")) {
|
||||
int idx = highlighter_menu->get_item_idx_from_text(state["syntax_highlighter"]);
|
||||
if (idx >= 0) {
|
||||
_change_syntax_highlighter(idx);
|
||||
}
|
||||
}
|
||||
|
||||
ensure_focus();
|
||||
}
|
||||
|
||||
void EditorTextEditor::trim_trailing_whitespace() {
|
||||
code_editor->trim_trailing_whitespace();
|
||||
}
|
||||
|
||||
void EditorTextEditor::insert_final_newline() {
|
||||
code_editor->insert_final_newline();
|
||||
}
|
||||
|
||||
void EditorTextEditor::convert_indent_to_spaces() {
|
||||
code_editor->convert_indent_to_spaces();
|
||||
}
|
||||
|
||||
void EditorTextEditor::convert_indent_to_tabs() {
|
||||
code_editor->convert_indent_to_tabs();
|
||||
}
|
||||
|
||||
void EditorTextEditor::tag_saved_version() {
|
||||
code_editor->get_text_edit()->tag_saved_version();
|
||||
}
|
||||
|
||||
void EditorTextEditor::goto_line(int p_line, bool p_with_error) {
|
||||
code_editor->goto_line(p_line);
|
||||
}
|
||||
|
||||
void EditorTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) {
|
||||
code_editor->goto_line_selection(p_line, p_begin, p_end);
|
||||
}
|
||||
|
||||
void EditorTextEditor::set_executing_line(int p_line) {
|
||||
code_editor->set_executing_line(p_line);
|
||||
}
|
||||
|
||||
void EditorTextEditor::clear_executing_line() {
|
||||
code_editor->clear_executing_line();
|
||||
}
|
||||
|
||||
void EditorTextEditor::ensure_focus() {
|
||||
code_editor->get_text_edit()->grab_focus();
|
||||
}
|
||||
|
||||
Vector<String> EditorTextEditor::get_functions() {
|
||||
return Vector<String>();
|
||||
}
|
||||
|
||||
bool EditorTextEditor::show_members_overview() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditorTextEditor::update_settings() {
|
||||
code_editor->update_editor_settings();
|
||||
}
|
||||
|
||||
void EditorTextEditor::set_tooltip_request_func(String p_method, Object *p_obj) {
|
||||
code_editor->get_text_edit()->set_tooltip_request_func(p_obj, p_method, this);
|
||||
}
|
||||
|
||||
Control *EditorTextEditor::get_edit_menu() {
|
||||
return edit_hb;
|
||||
}
|
||||
|
||||
void EditorTextEditor::clear_edit_menu() {
|
||||
memdelete(edit_hb);
|
||||
}
|
||||
|
||||
void EditorTextEditor::_edit_option(int p_op) {
|
||||
TextEdit *tx = code_editor->get_text_edit();
|
||||
|
||||
switch (p_op) {
|
||||
case EDIT_UNDO: {
|
||||
tx->undo();
|
||||
tx->call_deferred("grab_focus");
|
||||
} break;
|
||||
case EDIT_REDO: {
|
||||
tx->redo();
|
||||
tx->call_deferred("grab_focus");
|
||||
} break;
|
||||
case EDIT_CUT: {
|
||||
tx->cut();
|
||||
tx->call_deferred("grab_focus");
|
||||
} break;
|
||||
case EDIT_COPY: {
|
||||
tx->copy();
|
||||
tx->call_deferred("grab_focus");
|
||||
} break;
|
||||
case EDIT_PASTE: {
|
||||
tx->paste();
|
||||
tx->call_deferred("grab_focus");
|
||||
} break;
|
||||
case EDIT_SELECT_ALL: {
|
||||
tx->select_all();
|
||||
tx->call_deferred("grab_focus");
|
||||
} break;
|
||||
case EDIT_MOVE_LINE_UP: {
|
||||
code_editor->move_lines_up();
|
||||
} break;
|
||||
case EDIT_MOVE_LINE_DOWN: {
|
||||
code_editor->move_lines_down();
|
||||
} break;
|
||||
case EDIT_INDENT_LEFT: {
|
||||
tx->indent_left();
|
||||
} break;
|
||||
case EDIT_INDENT_RIGHT: {
|
||||
tx->indent_right();
|
||||
} break;
|
||||
case EDIT_DELETE_LINE: {
|
||||
code_editor->delete_lines();
|
||||
} break;
|
||||
case EDIT_DUPLICATE_SELECTION: {
|
||||
code_editor->duplicate_selection();
|
||||
} break;
|
||||
case EDIT_TOGGLE_FOLD_LINE: {
|
||||
tx->toggle_fold_line(tx->cursor_get_line());
|
||||
tx->update();
|
||||
} break;
|
||||
case EDIT_FOLD_ALL_LINES: {
|
||||
tx->fold_all_lines();
|
||||
tx->update();
|
||||
} break;
|
||||
case EDIT_UNFOLD_ALL_LINES: {
|
||||
tx->unhide_all_lines();
|
||||
tx->update();
|
||||
} break;
|
||||
case EDIT_TRIM_TRAILING_WHITESAPCE: {
|
||||
trim_trailing_whitespace();
|
||||
} break;
|
||||
case EDIT_CONVERT_INDENT_TO_SPACES: {
|
||||
convert_indent_to_spaces();
|
||||
} break;
|
||||
case EDIT_CONVERT_INDENT_TO_TABS: {
|
||||
convert_indent_to_tabs();
|
||||
} break;
|
||||
case EDIT_TO_UPPERCASE: {
|
||||
_convert_case(EditorCodeTextEditor::UPPER);
|
||||
} break;
|
||||
case EDIT_TO_LOWERCASE: {
|
||||
_convert_case(EditorCodeTextEditor::LOWER);
|
||||
} break;
|
||||
case EDIT_CAPITALIZE: {
|
||||
_convert_case(EditorCodeTextEditor::CAPITALIZE);
|
||||
} break;
|
||||
case SEARCH_FIND: {
|
||||
code_editor->get_find_replace_bar()->popup_search();
|
||||
} break;
|
||||
case SEARCH_FIND_NEXT: {
|
||||
code_editor->get_find_replace_bar()->search_next();
|
||||
} break;
|
||||
case SEARCH_FIND_PREV: {
|
||||
code_editor->get_find_replace_bar()->search_prev();
|
||||
} break;
|
||||
case SEARCH_REPLACE: {
|
||||
code_editor->get_find_replace_bar()->popup_replace();
|
||||
} break;
|
||||
case SEARCH_IN_FILES: {
|
||||
String selected_text = code_editor->get_text_edit()->get_selection_text();
|
||||
|
||||
// Yep, because it doesn't make sense to instance this dialog for every single script open...
|
||||
// So this will be delegated to the EditorScriptEditor.
|
||||
emit_signal("search_in_files_requested", selected_text);
|
||||
} break;
|
||||
case REPLACE_IN_FILES: {
|
||||
String selected_text = code_editor->get_text_edit()->get_selection_text();
|
||||
|
||||
emit_signal("replace_in_files_requested", selected_text);
|
||||
} break;
|
||||
case SEARCH_GOTO_LINE: {
|
||||
goto_line_dialog->popup_find_line(tx);
|
||||
} break;
|
||||
case BOOKMARK_TOGGLE: {
|
||||
code_editor->toggle_bookmark();
|
||||
} break;
|
||||
case BOOKMARK_GOTO_NEXT: {
|
||||
code_editor->goto_next_bookmark();
|
||||
} break;
|
||||
case BOOKMARK_GOTO_PREV: {
|
||||
code_editor->goto_prev_bookmark();
|
||||
} break;
|
||||
case BOOKMARK_REMOVE_ALL: {
|
||||
code_editor->remove_all_bookmarks();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorTextEditor::_convert_case(EditorCodeTextEditor::CaseStyle p_case) {
|
||||
code_editor->convert_case(p_case);
|
||||
}
|
||||
|
||||
void EditorTextEditor::_bind_methods() {
|
||||
ClassDB::bind_method("_validate_script", &EditorTextEditor::_validate_script);
|
||||
ClassDB::bind_method("_update_bookmark_list", &EditorTextEditor::_update_bookmark_list);
|
||||
ClassDB::bind_method("_bookmark_item_pressed", &EditorTextEditor::_bookmark_item_pressed);
|
||||
ClassDB::bind_method("_load_theme_settings", &EditorTextEditor::_load_theme_settings);
|
||||
ClassDB::bind_method("_edit_option", &EditorTextEditor::_edit_option);
|
||||
ClassDB::bind_method("_change_syntax_highlighter", &EditorTextEditor::_change_syntax_highlighter);
|
||||
ClassDB::bind_method("_text_edit_gui_input", &EditorTextEditor::_text_edit_gui_input);
|
||||
ClassDB::bind_method("_prepare_edit_menu", &EditorTextEditor::_prepare_edit_menu);
|
||||
}
|
||||
|
||||
EditorScriptEditorBase *EditorTextEditor::create_editor(const RES &p_resource) {
|
||||
if (Object::cast_to<TextFile>(*p_resource)) {
|
||||
return memnew(EditorTextEditor);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void EditorTextEditor::register_editor() {
|
||||
EditorScriptEditor::register_create_script_editor_function(create_editor);
|
||||
}
|
||||
|
||||
void EditorTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
|
||||
Ref<InputEventMouseButton> mb = ev;
|
||||
|
||||
if (mb.is_valid()) {
|
||||
if (mb->get_button_index() == BUTTON_RIGHT) {
|
||||
int col, row;
|
||||
TextEdit *tx = code_editor->get_text_edit();
|
||||
tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col);
|
||||
|
||||
tx->set_right_click_moves_caret(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret"));
|
||||
bool can_fold = tx->can_fold(row);
|
||||
bool is_folded = tx->is_folded(row);
|
||||
|
||||
if (tx->is_right_click_moving_caret()) {
|
||||
if (tx->is_selection_active()) {
|
||||
int from_line = tx->get_selection_from_line();
|
||||
int to_line = tx->get_selection_to_line();
|
||||
int from_column = tx->get_selection_from_column();
|
||||
int to_column = tx->get_selection_to_column();
|
||||
|
||||
if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) {
|
||||
// Right click is outside the selected text.
|
||||
tx->deselect();
|
||||
}
|
||||
}
|
||||
if (!tx->is_selection_active()) {
|
||||
tx->cursor_set_line(row, true, false);
|
||||
tx->cursor_set_column(col);
|
||||
}
|
||||
}
|
||||
|
||||
if (!mb->is_pressed()) {
|
||||
_make_context_menu(tx->is_selection_active(), can_fold, is_folded, get_local_mouse_position());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ref<InputEventKey> k = ev;
|
||||
if (k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_MENU) {
|
||||
TextEdit *tx = code_editor->get_text_edit();
|
||||
int line = tx->cursor_get_line();
|
||||
_make_context_menu(tx->is_selection_active(), tx->can_fold(line), tx->is_folded(line), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->_get_cursor_pixel_pos()));
|
||||
context_menu->grab_focus();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorTextEditor::_prepare_edit_menu() {
|
||||
const TextEdit *tx = code_editor->get_text_edit();
|
||||
PopupMenu *popup = edit_menu->get_popup();
|
||||
popup->set_item_disabled(popup->get_item_index(EDIT_UNDO), !tx->has_undo());
|
||||
popup->set_item_disabled(popup->get_item_index(EDIT_REDO), !tx->has_redo());
|
||||
}
|
||||
|
||||
void EditorTextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position) {
|
||||
context_menu->clear();
|
||||
if (p_selection) {
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
|
||||
}
|
||||
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
|
||||
context_menu->add_separator();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
|
||||
context_menu->add_separator();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
|
||||
|
||||
if (p_selection) {
|
||||
context_menu->add_separator();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_uppercase"), EDIT_TO_UPPERCASE);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_lowercase"), EDIT_TO_LOWERCASE);
|
||||
}
|
||||
if (p_can_fold || p_is_folded) {
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
|
||||
}
|
||||
|
||||
const TextEdit *tx = code_editor->get_text_edit();
|
||||
context_menu->set_item_disabled(context_menu->get_item_index(EDIT_UNDO), !tx->has_undo());
|
||||
context_menu->set_item_disabled(context_menu->get_item_index(EDIT_REDO), !tx->has_redo());
|
||||
|
||||
context_menu->set_position(get_global_transform().xform(p_position));
|
||||
context_menu->set_size(Vector2(1, 1));
|
||||
context_menu->popup();
|
||||
}
|
||||
|
||||
EditorTextEditor::EditorTextEditor() {
|
||||
editor_enabled = false;
|
||||
|
||||
code_editor = memnew(EditorCodeTextEditor);
|
||||
add_child(code_editor);
|
||||
code_editor->add_theme_constant_override("separation", 0);
|
||||
code_editor->connect("load_theme_settings", this, "_load_theme_settings");
|
||||
code_editor->connect("validate_script", this, "_validate_script");
|
||||
code_editor->set_anchors_and_margins_preset(Control::PRESET_WIDE);
|
||||
code_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
|
||||
update_settings();
|
||||
|
||||
code_editor->get_text_edit()->set_context_menu_enabled(false);
|
||||
code_editor->get_text_edit()->connect("gui_input", this, "_text_edit_gui_input");
|
||||
|
||||
context_menu = memnew(PopupMenu);
|
||||
add_child(context_menu);
|
||||
context_menu->connect("id_pressed", this, "_edit_option");
|
||||
|
||||
edit_hb = memnew(HBoxContainer);
|
||||
|
||||
search_menu = memnew(MenuButton);
|
||||
search_menu->set_shortcut_context(this);
|
||||
edit_hb->add_child(search_menu);
|
||||
search_menu->set_text(TTR("Search"));
|
||||
search_menu->set_switch_on_hover(true);
|
||||
search_menu->get_popup()->connect("id_pressed", this, "_edit_option");
|
||||
|
||||
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find"), SEARCH_FIND);
|
||||
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT);
|
||||
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV);
|
||||
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE);
|
||||
search_menu->get_popup()->add_separator();
|
||||
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_in_files"), SEARCH_IN_FILES);
|
||||
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace_in_files"), REPLACE_IN_FILES);
|
||||
|
||||
edit_menu = memnew(MenuButton);
|
||||
edit_menu->set_shortcut_context(this);
|
||||
edit_hb->add_child(edit_menu);
|
||||
edit_menu->set_text(TTR("Edit"));
|
||||
edit_menu->set_switch_on_hover(true);
|
||||
edit_menu->connect("about_to_show", this, "_prepare_edit_menu");
|
||||
edit_menu->get_popup()->connect("id_pressed", this, "_edit_option");
|
||||
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_all_lines"), EDIT_FOLD_ALL_LINES);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_all_lines"), EDIT_UNFOLD_ALL_LINES);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/duplicate_selection"), EDIT_DUPLICATE_SELECTION);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_spaces"), EDIT_CONVERT_INDENT_TO_SPACES);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_tabs"), EDIT_CONVERT_INDENT_TO_TABS);
|
||||
|
||||
edit_menu->get_popup()->add_separator();
|
||||
PopupMenu *convert_case = memnew(PopupMenu);
|
||||
convert_case->set_name("convert_case");
|
||||
edit_menu->get_popup()->add_child(convert_case);
|
||||
edit_menu->get_popup()->add_submenu_item(TTR("Convert Case"), "convert_case");
|
||||
convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/convert_to_uppercase", TTR("Uppercase")), EDIT_TO_UPPERCASE);
|
||||
convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/convert_to_lowercase", TTR("Lowercase")), EDIT_TO_LOWERCASE);
|
||||
convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/capitalize", TTR("Capitalize")), EDIT_CAPITALIZE);
|
||||
convert_case->connect("id_pressed", this, "_edit_option");
|
||||
|
||||
highlighter_menu = memnew(PopupMenu);
|
||||
highlighter_menu->set_name("highlighter_menu");
|
||||
edit_menu->get_popup()->add_child(highlighter_menu);
|
||||
edit_menu->get_popup()->add_submenu_item(TTR("Syntax Highlighter"), "highlighter_menu");
|
||||
highlighter_menu->connect("id_pressed", this, "_change_syntax_highlighter");
|
||||
|
||||
Ref<EditorPlainTextSyntaxHighlighter> plain_highlighter;
|
||||
plain_highlighter.instance();
|
||||
add_syntax_highlighter(plain_highlighter);
|
||||
|
||||
Ref<EditorStandardSyntaxHighlighter> highlighter;
|
||||
highlighter.instance();
|
||||
add_syntax_highlighter(highlighter);
|
||||
set_syntax_highlighter(plain_highlighter);
|
||||
|
||||
MenuButton *goto_menu = memnew(MenuButton);
|
||||
goto_menu->set_shortcut_context(this);
|
||||
edit_hb->add_child(goto_menu);
|
||||
goto_menu->set_text(TTR("Go To"));
|
||||
goto_menu->set_switch_on_hover(true);
|
||||
goto_menu->get_popup()->connect("id_pressed", this, "_edit_option");
|
||||
|
||||
goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE);
|
||||
goto_menu->get_popup()->add_separator();
|
||||
|
||||
bookmarks_menu = memnew(PopupMenu);
|
||||
bookmarks_menu->set_name("Bookmarks");
|
||||
goto_menu->get_popup()->add_child(bookmarks_menu);
|
||||
goto_menu->get_popup()->add_submenu_item(TTR("Bookmarks"), "Bookmarks");
|
||||
_update_bookmark_list();
|
||||
bookmarks_menu->connect("about_to_show", this, "_update_bookmark_list");
|
||||
bookmarks_menu->connect("index_pressed", this, "_bookmark_item_pressed");
|
||||
|
||||
goto_line_dialog = memnew(EditorGotoLineDialog);
|
||||
add_child(goto_line_dialog);
|
||||
|
||||
code_editor->get_text_edit()->set_drag_forwarding(this);
|
||||
}
|
||||
|
||||
EditorTextEditor::~EditorTextEditor() {
|
||||
highlighters.clear();
|
||||
}
|
||||
|
||||
void EditorTextEditor::validate() {
|
||||
}
|
@ -1,187 +0,0 @@
|
||||
#ifndef EDITOR_TEXT_EDITOR_H
|
||||
#define EDITOR_TEXT_EDITOR_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* text_editor.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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_script_editor_base.h"
|
||||
|
||||
#include "editor_code_text_editor.h"
|
||||
|
||||
#include "core/containers/list.h"
|
||||
#include "core/containers/rb_map.h"
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/math/color.h"
|
||||
#include "core/object/object.h"
|
||||
#include "core/object/reference.h"
|
||||
#include "core/object/resource.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
class Control;
|
||||
class HBoxContainer;
|
||||
class InputEvent;
|
||||
class MenuButton;
|
||||
class PopupMenu;
|
||||
class SyntaxHighlighter;
|
||||
class TextFile;
|
||||
class Texture;
|
||||
struct Vector2;
|
||||
class EditorSyntaxHighlighter;
|
||||
class EditorTextEditor : public EditorScriptEditorBase {
|
||||
GDCLASS(EditorTextEditor, EditorScriptEditorBase);
|
||||
|
||||
private:
|
||||
EditorCodeTextEditor *code_editor;
|
||||
|
||||
Ref<TextFile> text_file;
|
||||
bool editor_enabled;
|
||||
|
||||
HBoxContainer *edit_hb;
|
||||
MenuButton *edit_menu;
|
||||
PopupMenu *highlighter_menu;
|
||||
MenuButton *search_menu;
|
||||
PopupMenu *bookmarks_menu;
|
||||
PopupMenu *context_menu;
|
||||
|
||||
EditorGotoLineDialog *goto_line_dialog;
|
||||
|
||||
struct ColorsCache {
|
||||
Color font_color;
|
||||
Color symbol_color;
|
||||
Color keyword_color;
|
||||
Color control_flow_keyword_color;
|
||||
Color basetype_color;
|
||||
Color type_color;
|
||||
Color comment_color;
|
||||
Color string_color;
|
||||
} colors_cache;
|
||||
|
||||
enum {
|
||||
EDIT_UNDO,
|
||||
EDIT_REDO,
|
||||
EDIT_CUT,
|
||||
EDIT_COPY,
|
||||
EDIT_PASTE,
|
||||
EDIT_SELECT_ALL,
|
||||
EDIT_TRIM_TRAILING_WHITESAPCE,
|
||||
EDIT_CONVERT_INDENT_TO_SPACES,
|
||||
EDIT_CONVERT_INDENT_TO_TABS,
|
||||
EDIT_MOVE_LINE_UP,
|
||||
EDIT_MOVE_LINE_DOWN,
|
||||
EDIT_INDENT_RIGHT,
|
||||
EDIT_INDENT_LEFT,
|
||||
EDIT_DELETE_LINE,
|
||||
EDIT_DUPLICATE_SELECTION,
|
||||
EDIT_TO_UPPERCASE,
|
||||
EDIT_TO_LOWERCASE,
|
||||
EDIT_CAPITALIZE,
|
||||
EDIT_TOGGLE_FOLD_LINE,
|
||||
EDIT_FOLD_ALL_LINES,
|
||||
EDIT_UNFOLD_ALL_LINES,
|
||||
SEARCH_FIND,
|
||||
SEARCH_FIND_NEXT,
|
||||
SEARCH_FIND_PREV,
|
||||
SEARCH_REPLACE,
|
||||
SEARCH_IN_FILES,
|
||||
REPLACE_IN_FILES,
|
||||
SEARCH_GOTO_LINE,
|
||||
BOOKMARK_TOGGLE,
|
||||
BOOKMARK_GOTO_NEXT,
|
||||
BOOKMARK_GOTO_PREV,
|
||||
BOOKMARK_REMOVE_ALL,
|
||||
};
|
||||
|
||||
static EditorScriptEditorBase *create_editor(const RES &p_resource);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
void _edit_option(int p_op);
|
||||
void _make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position);
|
||||
void _text_edit_gui_input(const Ref<InputEvent> &ev);
|
||||
void _prepare_edit_menu();
|
||||
|
||||
RBMap<String, Ref<EditorSyntaxHighlighter> > highlighters;
|
||||
void _change_syntax_highlighter(int p_idx);
|
||||
void _load_theme_settings();
|
||||
|
||||
void _convert_case(EditorCodeTextEditor::CaseStyle p_case);
|
||||
|
||||
void _validate_script();
|
||||
|
||||
void _update_bookmark_list();
|
||||
void _bookmark_item_pressed(int p_idx);
|
||||
|
||||
public:
|
||||
virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter);
|
||||
virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter);
|
||||
|
||||
virtual String get_name();
|
||||
virtual Ref<Texture> get_icon();
|
||||
virtual RES get_edited_resource() const;
|
||||
virtual void set_edited_resource(const RES &p_res);
|
||||
virtual void enable_editor();
|
||||
virtual void reload_text();
|
||||
virtual void apply_code();
|
||||
virtual bool is_unsaved();
|
||||
virtual Variant get_edit_state();
|
||||
virtual void set_edit_state(const Variant &p_state);
|
||||
virtual Vector<String> get_functions();
|
||||
virtual void get_breakpoints(List<int> *p_breakpoints);
|
||||
virtual void goto_line(int p_line, bool p_with_error = false);
|
||||
void goto_line_selection(int p_line, int p_begin, int p_end);
|
||||
virtual void set_executing_line(int p_line);
|
||||
virtual void clear_executing_line();
|
||||
virtual void trim_trailing_whitespace();
|
||||
virtual void insert_final_newline();
|
||||
virtual void convert_indent_to_spaces();
|
||||
virtual void convert_indent_to_tabs();
|
||||
virtual void ensure_focus();
|
||||
virtual void tag_saved_version();
|
||||
virtual void update_settings();
|
||||
virtual bool show_members_overview();
|
||||
virtual bool can_lose_focus_on_node_selection() { return true; }
|
||||
virtual void set_debugger_active(bool p_active);
|
||||
virtual void set_tooltip_request_func(String p_method, Object *p_obj);
|
||||
virtual void add_callback(const String &p_function, PoolStringArray p_args);
|
||||
|
||||
virtual Control *get_edit_menu();
|
||||
virtual void clear_edit_menu();
|
||||
|
||||
virtual void validate();
|
||||
|
||||
static void register_editor();
|
||||
|
||||
EditorTextEditor();
|
||||
~EditorTextEditor();
|
||||
};
|
||||
|
||||
#endif // TEXT_EDITOR_H
|
@ -1,34 +0,0 @@
|
||||
|
||||
#include "register_types.h"
|
||||
|
||||
#include "editor_script_editor.h"
|
||||
#include "script_editor_plugin.h"
|
||||
|
||||
#include "editor_script_editor_base.h"
|
||||
//#include "script_text_editor.h"
|
||||
//#include "text_editor.h"
|
||||
//#include "code_text_editor.h"
|
||||
|
||||
void register_editor_code_editor_types(ModuleRegistrationLevel p_level) {
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) {
|
||||
//ClassDB::register_class<>();
|
||||
ClassDB::register_virtual_class<EditorScriptEditor>();
|
||||
|
||||
ClassDB::register_virtual_class<EditorScriptEditorBase>();
|
||||
|
||||
ClassDB::register_class<EditorSyntaxHighlighter>();
|
||||
|
||||
//ClassDB::register_class<TextEditor>();
|
||||
//ClassDB::register_class<EditorScriptTextEditor>();
|
||||
//ClassDB::register_class<EditorCodeTextEditor>();
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_EDITOR) {
|
||||
EditorPlugins::add_by_type_front<EditorScriptEditorPlugin>();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void unregister_editor_code_editor_types(ModuleRegistrationLevel p_level) {
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
#ifndef EDITOR_CODE_EDITOR_REGISTER_TYPES_H
|
||||
#define EDITOR_CODE_EDITOR_REGISTER_TYPES_H
|
||||
|
||||
#include "modules/register_module_types.h"
|
||||
|
||||
void register_editor_code_editor_types(ModuleRegistrationLevel p_level);
|
||||
void unregister_editor_code_editor_types(ModuleRegistrationLevel p_level);
|
||||
|
||||
#endif
|
@ -1,217 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* script_editor_plugin.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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 "script_editor_plugin.h"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/containers/pair.h"
|
||||
#include "core/containers/rb_map.h"
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/input/input.h"
|
||||
#include "core/input/input_event.h"
|
||||
#include "core/io/config_file.h"
|
||||
#include "core/io/resource_loader.h"
|
||||
#include "core/io/resource_saver.h"
|
||||
#include "core/math/color.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/math/transform_2d.h"
|
||||
#include "core/object/class_db.h"
|
||||
#include "core/object/undo_redo.h"
|
||||
#include "core/os/file_access.h"
|
||||
#include "core/os/keyboard.h"
|
||||
#include "core/os/main_loop.h"
|
||||
#include "core/os/memory.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/string/string_name.h"
|
||||
#include "core/variant/dictionary.h"
|
||||
#include "core/version_generated.gen.h"
|
||||
#include "editor/editor_data.h"
|
||||
#include "editor/editor_file_dialog.h"
|
||||
#include "editor/editor_file_system.h"
|
||||
#include "editor/editor_help.h"
|
||||
#include "editor/editor_help_search.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_run_script.h"
|
||||
#include "editor/editor_scale.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "editor/filesystem_dock.h"
|
||||
#include "editor/find_in_files.h"
|
||||
#include "editor/inspector_dock.h"
|
||||
#include "editor/node_dock.h"
|
||||
#include "editor/script_create_dialog.h"
|
||||
#include "editor/script_editor_debugger.h"
|
||||
#include "scene/main/canvas_item.h"
|
||||
#include "scene/gui/button.h"
|
||||
#include "scene/main/control.h"
|
||||
#include "scene/gui/item_list.h"
|
||||
#include "scene/gui/label.h"
|
||||
#include "scene/gui/line_edit.h"
|
||||
#include "scene/gui/menu_button.h"
|
||||
#include "scene/gui/popup_menu.h"
|
||||
#include "scene/gui/separator.h"
|
||||
#include "scene/gui/split_container.h"
|
||||
#include "scene/gui/tab_container.h"
|
||||
#include "scene/gui/text_edit.h"
|
||||
#include "scene/gui/texture_rect.h"
|
||||
#include "scene/gui/tool_button.h"
|
||||
#include "scene/gui/tree.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/main/scene_tree.h"
|
||||
#include "scene/main/timer.h"
|
||||
#include "scene/main/viewport.h"
|
||||
#include "scene/resources/text_file.h"
|
||||
#include "scene/resources/texture.h"
|
||||
#include "scene/main/scene_string_names.h"
|
||||
|
||||
#include "editor_script_editor_quick_open.h"
|
||||
#include "editor_script_text_editor.h"
|
||||
#include "editor_text_editor.h"
|
||||
|
||||
#include "editor_script_editor.h"
|
||||
|
||||
static bool _is_built_in_script(Script *p_script) {
|
||||
String path = p_script->get_path();
|
||||
|
||||
return path.find("::") != -1;
|
||||
}
|
||||
|
||||
void EditorScriptEditorPlugin::edit(Object *p_object) {
|
||||
if (Object::cast_to<Script>(p_object)) {
|
||||
Script *p_script = Object::cast_to<Script>(p_object);
|
||||
String res_path = p_script->get_path().get_slice("::", 0);
|
||||
|
||||
if (_is_built_in_script(p_script)) {
|
||||
if (ResourceLoader::get_resource_type(res_path) == "PackedScene") {
|
||||
if (!EditorNode::get_singleton()->is_scene_open(res_path)) {
|
||||
EditorNode::get_singleton()->load_scene(res_path);
|
||||
}
|
||||
} else {
|
||||
EditorNode::get_singleton()->load_resource(res_path);
|
||||
}
|
||||
}
|
||||
script_editor->edit(p_script);
|
||||
} else if (Object::cast_to<TextFile>(p_object)) {
|
||||
script_editor->edit(Object::cast_to<TextFile>(p_object));
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorScriptEditorPlugin::handles(Object *p_object) const {
|
||||
if (Object::cast_to<TextFile>(p_object)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Script *script = Object::cast_to<Script>(p_object);
|
||||
if (script) {
|
||||
return script->get_language() != nullptr; // Could be a PluginScript with no language attached.
|
||||
}
|
||||
|
||||
return p_object->is_class("Script");
|
||||
}
|
||||
|
||||
void EditorScriptEditorPlugin::make_visible(bool p_visible) {
|
||||
if (p_visible) {
|
||||
script_editor->show();
|
||||
script_editor->set_process(true);
|
||||
script_editor->ensure_select_current();
|
||||
} else {
|
||||
script_editor->hide();
|
||||
script_editor->set_process(false);
|
||||
}
|
||||
}
|
||||
|
||||
void EditorScriptEditorPlugin::selected_notify() {
|
||||
script_editor->ensure_select_current();
|
||||
}
|
||||
|
||||
void EditorScriptEditorPlugin::save_external_data() {
|
||||
script_editor->save_all_scripts();
|
||||
}
|
||||
|
||||
void EditorScriptEditorPlugin::apply_changes() {
|
||||
script_editor->apply_scripts();
|
||||
}
|
||||
|
||||
void EditorScriptEditorPlugin::restore_global_state() {
|
||||
}
|
||||
|
||||
void EditorScriptEditorPlugin::save_global_state() {
|
||||
}
|
||||
|
||||
void EditorScriptEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
|
||||
script_editor->set_window_layout(p_layout);
|
||||
}
|
||||
|
||||
void EditorScriptEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) {
|
||||
script_editor->get_window_layout(p_layout);
|
||||
}
|
||||
|
||||
void EditorScriptEditorPlugin::get_breakpoints(List<String> *p_breakpoints) {
|
||||
script_editor->get_breakpoints(p_breakpoints);
|
||||
}
|
||||
|
||||
void EditorScriptEditorPlugin::edited_scene_changed() {
|
||||
script_editor->edited_scene_changed();
|
||||
}
|
||||
|
||||
EditorScriptEditorPlugin::EditorScriptEditorPlugin(EditorNode *p_node) {
|
||||
EditorScriptTextEditor::register_editor(); //register one for text scripts
|
||||
EditorTextEditor::register_editor();
|
||||
|
||||
editor = p_node;
|
||||
script_editor = memnew(EditorScriptEditor(p_node));
|
||||
editor->get_viewport()->add_child(script_editor);
|
||||
script_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
|
||||
script_editor->hide();
|
||||
|
||||
EDITOR_DEF("text_editor/files/auto_reload_scripts_on_external_change", true);
|
||||
ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/files/auto_reload_and_parse_scripts_on_save", true));
|
||||
EDITOR_DEF("text_editor/files/open_dominant_script_on_scene_change", true);
|
||||
EDITOR_DEF("text_editor/external/use_external_editor", false);
|
||||
EDITOR_DEF("text_editor/external/exec_path", "");
|
||||
EDITOR_DEF("text_editor/script_list/script_temperature_enabled", true);
|
||||
EDITOR_DEF("text_editor/script_list/highlight_current_script", true);
|
||||
EDITOR_DEF("text_editor/script_list/script_temperature_history_size", 15);
|
||||
EDITOR_DEF("text_editor/script_list/current_script_background_color", Color(1, 1, 1, 0.3));
|
||||
EDITOR_DEF("text_editor/script_list/group_help_pages", true);
|
||||
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "text_editor/script_list/sort_scripts_by", PROPERTY_HINT_ENUM, "Name,Path,None"));
|
||||
EDITOR_DEF("text_editor/script_list/sort_scripts_by", 0);
|
||||
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "text_editor/script_list/list_script_names_as", PROPERTY_HINT_ENUM, "Name,Parent Directory And Name,Full Path"));
|
||||
EDITOR_DEF("text_editor/script_list/list_script_names_as", 0);
|
||||
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "text_editor/external/exec_path", PROPERTY_HINT_GLOBAL_FILE));
|
||||
EDITOR_DEF("text_editor/external/exec_flags", "{file}");
|
||||
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "text_editor/external/exec_flags", PROPERTY_HINT_PLACEHOLDER_TEXT, "Call flags with placeholders: {project}, {file}, {col}, {line}."));
|
||||
|
||||
ED_SHORTCUT("script_editor/reopen_closed_script", TTR("Reopen Closed Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_T);
|
||||
ED_SHORTCUT("script_editor/clear_recent", TTR("Clear Recent Scripts"));
|
||||
}
|
||||
|
||||
EditorScriptEditorPlugin::~EditorScriptEditorPlugin() {
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
#ifndef SCRIPT_EDITOR_PLUGIN_H
|
||||
#define SCRIPT_EDITOR_PLUGIN_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* script_editor_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/editor_plugin.h"
|
||||
|
||||
class EditorScriptEditor;
|
||||
|
||||
class EditorScriptEditorPlugin : public EditorPlugin {
|
||||
GDCLASS(EditorScriptEditorPlugin, EditorPlugin);
|
||||
|
||||
EditorScriptEditor *script_editor;
|
||||
EditorNode *editor;
|
||||
|
||||
public:
|
||||
virtual String get_name() const { return "Script"; }
|
||||
bool has_main_screen() const { return true; }
|
||||
virtual void edit(Object *p_object);
|
||||
virtual bool handles(Object *p_object) const;
|
||||
virtual void make_visible(bool p_visible);
|
||||
virtual void selected_notify();
|
||||
|
||||
virtual void save_external_data();
|
||||
virtual void apply_changes();
|
||||
|
||||
virtual void restore_global_state();
|
||||
virtual void save_global_state();
|
||||
|
||||
virtual void set_window_layout(Ref<ConfigFile> p_layout);
|
||||
virtual void get_window_layout(Ref<ConfigFile> p_layout);
|
||||
|
||||
virtual void get_breakpoints(List<String> *p_breakpoints);
|
||||
|
||||
virtual void edited_scene_changed();
|
||||
|
||||
EditorScriptEditorPlugin(EditorNode *p_node);
|
||||
~EditorScriptEditorPlugin();
|
||||
};
|
||||
|
||||
#endif // SCRIPT_EDITOR_PLUGIN_H
|
@ -1,48 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
Import("env")
|
||||
Import("env_modules")
|
||||
|
||||
env_etc = env_modules.Clone()
|
||||
|
||||
# Thirdparty source files
|
||||
|
||||
thirdparty_obj = []
|
||||
|
||||
# Not unbundled so far since not widespread as shared library
|
||||
thirdparty_dir = "#thirdparty/etc2comp/"
|
||||
thirdparty_sources = [
|
||||
"EtcBlock4x4.cpp",
|
||||
"EtcBlock4x4Encoding.cpp",
|
||||
"EtcBlock4x4Encoding_ETC1.cpp",
|
||||
"EtcBlock4x4Encoding_R11.cpp",
|
||||
"EtcBlock4x4Encoding_RG11.cpp",
|
||||
"EtcBlock4x4Encoding_RGB8A1.cpp",
|
||||
"EtcBlock4x4Encoding_RGB8.cpp",
|
||||
"EtcBlock4x4Encoding_RGBA8.cpp",
|
||||
"Etc.cpp",
|
||||
"EtcDifferentialTrys.cpp",
|
||||
"EtcFilter.cpp",
|
||||
"EtcImage.cpp",
|
||||
"EtcIndividualTrys.cpp",
|
||||
"EtcMath.cpp",
|
||||
"EtcSortedBlockList.cpp",
|
||||
]
|
||||
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
|
||||
|
||||
env_etc.Prepend(CPPPATH=[thirdparty_dir])
|
||||
|
||||
env_thirdparty = env_etc.Clone()
|
||||
env_thirdparty.disable_warnings()
|
||||
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
|
||||
env.modules_sources += thirdparty_obj
|
||||
|
||||
# Pandemonium source files
|
||||
|
||||
module_obj = []
|
||||
|
||||
env_etc.add_source_files(module_obj, "*.cpp")
|
||||
env.modules_sources += module_obj
|
||||
|
||||
# Needed to force rebuilding the module files when the thirdparty library is updated.
|
||||
env.Depends(module_obj, thirdparty_obj)
|
@ -1,6 +0,0 @@
|
||||
def can_build(env, platform):
|
||||
return env["tools"]
|
||||
|
||||
|
||||
def configure(env):
|
||||
pass
|
@ -1,262 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* image_compress_etc.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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 "image_compress_etc.h"
|
||||
|
||||
#include "core/io/image.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/string/print_string.h"
|
||||
|
||||
#include <Etc.h>
|
||||
#include <EtcFilter.h>
|
||||
|
||||
static Image::Format _get_etc2_mode(Image::DetectChannels format) {
|
||||
switch (format) {
|
||||
case Image::DETECTED_R:
|
||||
return Image::FORMAT_ETC2_R11;
|
||||
|
||||
case Image::DETECTED_RG:
|
||||
return Image::FORMAT_ETC2_RG11;
|
||||
|
||||
case Image::DETECTED_RGB:
|
||||
return Image::FORMAT_ETC2_RGB8;
|
||||
|
||||
case Image::DETECTED_RGBA:
|
||||
return Image::FORMAT_ETC2_RGBA8;
|
||||
|
||||
// TODO: would be nice if we could use FORMAT_ETC2_RGB8A1 for FORMAT_RGBA5551
|
||||
default:
|
||||
// TODO: Kept for compatibility, but should be investigated whether it's correct or if it should error out
|
||||
return Image::FORMAT_ETC2_RGBA8;
|
||||
}
|
||||
}
|
||||
|
||||
static Etc::Image::Format _image_format_to_etc2comp_format(Image::Format format) {
|
||||
switch (format) {
|
||||
case Image::FORMAT_ETC:
|
||||
return Etc::Image::Format::ETC1;
|
||||
|
||||
case Image::FORMAT_ETC2_R11:
|
||||
return Etc::Image::Format::R11;
|
||||
|
||||
case Image::FORMAT_ETC2_R11S:
|
||||
return Etc::Image::Format::SIGNED_R11;
|
||||
|
||||
case Image::FORMAT_ETC2_RG11:
|
||||
return Etc::Image::Format::RG11;
|
||||
|
||||
case Image::FORMAT_ETC2_RG11S:
|
||||
return Etc::Image::Format::SIGNED_RG11;
|
||||
|
||||
case Image::FORMAT_ETC2_RGB8:
|
||||
return Etc::Image::Format::RGB8;
|
||||
|
||||
case Image::FORMAT_ETC2_RGBA8:
|
||||
return Etc::Image::Format::RGBA8;
|
||||
|
||||
case Image::FORMAT_ETC2_RGB8A1:
|
||||
return Etc::Image::Format::RGB8A1;
|
||||
|
||||
default:
|
||||
ERR_FAIL_V(Etc::Image::Format::UNKNOWN);
|
||||
}
|
||||
}
|
||||
|
||||
static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_format, Image::CompressSource p_source) {
|
||||
Image::Format img_format = p_img->get_format();
|
||||
Image::DetectChannels detected_channels = p_img->get_detected_channels();
|
||||
|
||||
if (p_source == Image::COMPRESS_SOURCE_LAYERED) {
|
||||
//keep what comes in
|
||||
switch (p_img->get_format()) {
|
||||
case Image::FORMAT_L8: {
|
||||
detected_channels = Image::DETECTED_L;
|
||||
} break;
|
||||
case Image::FORMAT_LA8: {
|
||||
detected_channels = Image::DETECTED_LA;
|
||||
} break;
|
||||
case Image::FORMAT_R8: {
|
||||
detected_channels = Image::DETECTED_R;
|
||||
} break;
|
||||
case Image::FORMAT_RG8: {
|
||||
detected_channels = Image::DETECTED_RG;
|
||||
} break;
|
||||
case Image::FORMAT_RGB8: {
|
||||
detected_channels = Image::DETECTED_RGB;
|
||||
} break;
|
||||
case Image::FORMAT_RGBA8:
|
||||
case Image::FORMAT_RGBA4444:
|
||||
case Image::FORMAT_RGBA5551: {
|
||||
detected_channels = Image::DETECTED_RGBA;
|
||||
} break;
|
||||
default: {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (p_source == Image::COMPRESS_SOURCE_SRGB && (detected_channels == Image::DETECTED_R || detected_channels == Image::DETECTED_RG)) {
|
||||
//R and RG do not support SRGB
|
||||
detected_channels = Image::DETECTED_RGB;
|
||||
}
|
||||
|
||||
if (p_source == Image::COMPRESS_SOURCE_NORMAL) {
|
||||
//use RG channels only for normal
|
||||
detected_channels = Image::DETECTED_RG;
|
||||
}
|
||||
|
||||
if (img_format >= Image::FORMAT_DXT1) {
|
||||
return; //do not compress, already compressed
|
||||
}
|
||||
|
||||
if (img_format > Image::FORMAT_RGBA8) {
|
||||
// TODO: we should be able to handle FORMAT_RGBA4444 and FORMAT_RGBA5551 eventually
|
||||
return;
|
||||
}
|
||||
|
||||
if (force_etc1_format) {
|
||||
// If VRAM compression is using ETC, but image has alpha, convert to RGBA4444 or LA8
|
||||
// This saves space while maintaining the alpha channel
|
||||
if (detected_channels == Image::DETECTED_RGBA) {
|
||||
if (p_img->has_mipmaps()) {
|
||||
// Image doesn't support mipmaps with RGBA4444 textures
|
||||
p_img->clear_mipmaps();
|
||||
}
|
||||
p_img->convert(Image::FORMAT_RGBA4444);
|
||||
return;
|
||||
} else if (detected_channels == Image::DETECTED_LA) {
|
||||
p_img->convert(Image::FORMAT_LA8);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t imgw = p_img->get_width(), imgh = p_img->get_height();
|
||||
|
||||
Image::Format etc_format = force_etc1_format ? Image::FORMAT_ETC : _get_etc2_mode(detected_channels);
|
||||
|
||||
Ref<Image> img = p_img->duplicate();
|
||||
|
||||
if (img->get_format() != Image::FORMAT_RGBA8) {
|
||||
img->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert
|
||||
}
|
||||
|
||||
if (img->has_mipmaps()) {
|
||||
if (next_power_of_2(imgw) != imgw || next_power_of_2(imgh) != imgh) {
|
||||
img->resize_to_po2();
|
||||
imgw = img->get_width();
|
||||
imgh = img->get_height();
|
||||
}
|
||||
} else {
|
||||
if (imgw % 4 != 0 || imgh % 4 != 0) {
|
||||
if (imgw % 4) {
|
||||
imgw += 4 - imgw % 4;
|
||||
}
|
||||
if (imgh % 4) {
|
||||
imgh += 4 - imgh % 4;
|
||||
}
|
||||
|
||||
img->resize(imgw, imgh);
|
||||
}
|
||||
}
|
||||
|
||||
PoolVector<uint8_t>::Read r = img->get_data().read();
|
||||
ERR_FAIL_COND(!r.ptr());
|
||||
|
||||
unsigned int target_size = Image::get_image_data_size(imgw, imgh, etc_format, p_img->has_mipmaps());
|
||||
int mmc = 1 + (p_img->has_mipmaps() ? Image::get_image_required_mipmaps(imgw, imgh, etc_format) : 0);
|
||||
|
||||
PoolVector<uint8_t> dst_data;
|
||||
dst_data.resize(target_size);
|
||||
|
||||
PoolVector<uint8_t>::Write w = dst_data.write();
|
||||
|
||||
// prepare parameters to be passed to etc2comp
|
||||
int num_cpus = OS::get_singleton()->get_processor_count();
|
||||
int encoding_time = 0;
|
||||
|
||||
float effort = 0.0; //default, reasonable time
|
||||
|
||||
if (p_lossy_quality > 0.95) {
|
||||
effort = 80;
|
||||
} else if (p_lossy_quality > 0.85) {
|
||||
effort = 60;
|
||||
} else if (p_lossy_quality > 0.75) {
|
||||
effort = 40;
|
||||
}
|
||||
|
||||
Etc::ErrorMetric error_metric = Etc::ErrorMetric::RGBX; // NOTE: we can experiment with other error metrics
|
||||
Etc::Image::Format etc2comp_etc_format = _image_format_to_etc2comp_format(etc_format);
|
||||
|
||||
int wofs = 0;
|
||||
|
||||
print_verbose("ETC: Begin encoding, format: " + Image::get_format_name(etc_format));
|
||||
uint64_t t = OS::get_singleton()->get_ticks_msec();
|
||||
for (int i = 0; i < mmc; i++) {
|
||||
// convert source image to internal etc2comp format (which is equivalent to Image::FORMAT_RGBAF)
|
||||
// NOTE: We can alternatively add a case to Image::convert to handle Image::FORMAT_RGBAF conversion.
|
||||
int mipmap_ofs = 0, mipmap_size = 0, mipmap_w = 0, mipmap_h = 0;
|
||||
img->get_mipmap_offset_size_and_dimensions(i, mipmap_ofs, mipmap_size, mipmap_w, mipmap_h);
|
||||
const uint8_t *src = &r[mipmap_ofs];
|
||||
|
||||
Etc::ColorFloatRGBA *src_rgba_f = new Etc::ColorFloatRGBA[mipmap_w * mipmap_h];
|
||||
for (int j = 0; j < mipmap_w * mipmap_h; j++) {
|
||||
int si = j * 4; // RGBA8
|
||||
src_rgba_f[j] = Etc::ColorFloatRGBA::ConvertFromRGBA8(src[si], src[si + 1], src[si + 2], src[si + 3]);
|
||||
}
|
||||
|
||||
unsigned char *etc_data = nullptr;
|
||||
unsigned int etc_data_len = 0;
|
||||
unsigned int extended_width = 0, extended_height = 0;
|
||||
Etc::Encode((float *)src_rgba_f, mipmap_w, mipmap_h, etc2comp_etc_format, error_metric, effort, num_cpus, num_cpus, &etc_data, &etc_data_len, &extended_width, &extended_height, &encoding_time);
|
||||
|
||||
CRASH_COND(wofs + etc_data_len > target_size);
|
||||
memcpy(&w[wofs], etc_data, etc_data_len);
|
||||
wofs += etc_data_len;
|
||||
|
||||
delete[] etc_data;
|
||||
delete[] src_rgba_f;
|
||||
}
|
||||
|
||||
print_verbose("ETC: Time encoding: " + rtos(OS::get_singleton()->get_ticks_msec() - t));
|
||||
|
||||
p_img->create(imgw, imgh, p_img->has_mipmaps(), etc_format, dst_data);
|
||||
}
|
||||
|
||||
static void _compress_etc1(Image *p_img, float p_lossy_quality) {
|
||||
_compress_etc(p_img, p_lossy_quality, true, Image::COMPRESS_SOURCE_GENERIC);
|
||||
}
|
||||
|
||||
static void _compress_etc2(Image *p_img, float p_lossy_quality, Image::CompressSource p_source) {
|
||||
_compress_etc(p_img, p_lossy_quality, false, p_source);
|
||||
}
|
||||
|
||||
void _register_etc_compress_func() {
|
||||
Image::_image_compress_etc1_func = _compress_etc1;
|
||||
Image::_image_compress_etc2_func = _compress_etc2;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#ifndef IMAGE_COMPRESS_ETC_H
|
||||
#define IMAGE_COMPRESS_ETC_H
|
||||
/*************************************************************************/
|
||||
/* image_compress_etc.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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_etc_compress_func();
|
||||
|
||||
#endif // IMAGE_COMPRESS_ETC_H
|
@ -1,52 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* register_types.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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 "image_compress_etc.h"
|
||||
#include "texture_loader_pkm.h"
|
||||
|
||||
static Ref<ResourceFormatPKM> resource_loader_pkm;
|
||||
|
||||
void register_etc_types(ModuleRegistrationLevel p_level) {
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_CORE) {
|
||||
resource_loader_pkm.instance();
|
||||
ResourceLoader::add_resource_format_loader(resource_loader_pkm);
|
||||
|
||||
_register_etc_compress_func();
|
||||
}
|
||||
}
|
||||
|
||||
void unregister_etc_types(ModuleRegistrationLevel p_level) {
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_CORE) {
|
||||
ResourceLoader::remove_resource_format_loader(resource_loader_pkm);
|
||||
resource_loader_pkm.unref();
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
#ifndef ETC_REGISTER_TYPES_H
|
||||
#define ETC_REGISTER_TYPES_H
|
||||
/*************************************************************************/
|
||||
/* register_types.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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 "modules/register_module_types.h"
|
||||
|
||||
void register_etc_types(ModuleRegistrationLevel p_level);
|
||||
void unregister_etc_types(ModuleRegistrationLevel p_level);
|
||||
|
||||
#endif // ETC_REGISTER_TYPES_H
|
@ -1,115 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* texture_loader_pkm.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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 "texture_loader_pkm.h"
|
||||
|
||||
#include "core/os/file_access.h"
|
||||
#include <string.h>
|
||||
|
||||
struct ETC1Header {
|
||||
char tag[6]; // "PKM 10"
|
||||
uint16_t format; // Format == number of mips (== zero)
|
||||
uint16_t texWidth; // Texture dimensions, multiple of 4 (big-endian)
|
||||
uint16_t texHeight;
|
||||
uint16_t origWidth; // Original dimensions (big-endian)
|
||||
uint16_t origHeight;
|
||||
};
|
||||
|
||||
RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_no_subresource_cache) {
|
||||
if (r_error) {
|
||||
*r_error = ERR_CANT_OPEN;
|
||||
}
|
||||
|
||||
Error err;
|
||||
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
if (!f) {
|
||||
return RES();
|
||||
}
|
||||
|
||||
FileAccessRef fref(f);
|
||||
if (r_error) {
|
||||
*r_error = ERR_FILE_CORRUPT;
|
||||
}
|
||||
|
||||
ERR_FAIL_COND_V_MSG(err != OK, RES(), "Unable to open PKM texture file '" + p_path + "'.");
|
||||
|
||||
// big endian
|
||||
f->set_endian_swap(true);
|
||||
|
||||
ETC1Header h;
|
||||
f->get_buffer((uint8_t *)&h.tag, sizeof(h.tag));
|
||||
ERR_FAIL_COND_V_MSG(strncmp(h.tag, "PKM 10", sizeof(h.tag)), RES(), "Invalid or unsupported PKM texture file '" + p_path + "'.");
|
||||
|
||||
h.format = f->get_16();
|
||||
h.texWidth = f->get_16();
|
||||
h.texHeight = f->get_16();
|
||||
h.origWidth = f->get_16();
|
||||
h.origHeight = f->get_16();
|
||||
|
||||
PoolVector<uint8_t> src_data;
|
||||
|
||||
uint32_t size = h.texWidth * h.texHeight / 2;
|
||||
src_data.resize(size);
|
||||
PoolVector<uint8_t>::Write wb = src_data.write();
|
||||
f->get_buffer(wb.ptr(), size);
|
||||
wb.release();
|
||||
|
||||
int mipmaps = h.format;
|
||||
int width = h.origWidth;
|
||||
int height = h.origHeight;
|
||||
|
||||
Ref<Image> img = memnew(Image(width, height, mipmaps, Image::FORMAT_ETC, src_data));
|
||||
|
||||
Ref<ImageTexture> texture = memnew(ImageTexture);
|
||||
texture->create_from_image(img);
|
||||
|
||||
if (r_error) {
|
||||
*r_error = OK;
|
||||
}
|
||||
|
||||
f->close();
|
||||
memdelete(f);
|
||||
return texture;
|
||||
}
|
||||
|
||||
void ResourceFormatPKM::get_recognized_extensions(List<String> *p_extensions) const {
|
||||
p_extensions->push_back("pkm");
|
||||
}
|
||||
|
||||
bool ResourceFormatPKM::handles_type(const String &p_type) const {
|
||||
return ClassDB::is_parent_class(p_type, "Texture");
|
||||
}
|
||||
|
||||
String ResourceFormatPKM::get_resource_type(const String &p_path) const {
|
||||
if (p_path.get_extension().to_lower() == "pkm") {
|
||||
return "ImageTexture";
|
||||
}
|
||||
return "";
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
#ifndef TEXTURE_LOADER_PKM_H
|
||||
#define TEXTURE_LOADER_PKM_H
|
||||
/*************************************************************************/
|
||||
/* texture_loader_pkm.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/io/resource_loader.h"
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
class ResourceFormatPKM : public ResourceFormatLoader {
|
||||
public:
|
||||
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_no_subresource_cache = false);
|
||||
virtual void get_recognized_extensions(List<String> *p_extensions) const;
|
||||
virtual bool handles_type(const String &p_type) const;
|
||||
virtual String get_resource_type(const String &p_path) const;
|
||||
|
||||
virtual ~ResourceFormatPKM() {}
|
||||
};
|
||||
|
||||
#endif // TEXTURE_LOADER_PKM_H
|
@ -1,10 +0,0 @@
|
||||
# GLTF import and export module
|
||||
|
||||
In a nutshell, the GLTF module works like this:
|
||||
|
||||
* The [`structures/`](structures/) folder contains GLTF structures, the
|
||||
small pieces that make up a GLTF file, represented as C++ classes.
|
||||
* The [`extensions/`](extensions/) folder contains GLTF extensions, which
|
||||
are optional features that build on top of the base GLTF spec.
|
||||
* [`GLTFState`](gltf_state.h) holds collections of structures and extensions.
|
||||
* [`GLTFDocument`](gltf_document.h) operates on GLTFState and its elements.
|
@ -1,12 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
Import("env")
|
||||
Import("env_modules")
|
||||
|
||||
env_gltf = env_modules.Clone()
|
||||
|
||||
# Pandemonium's own source files
|
||||
env_gltf.add_source_files(env.modules_sources, "*.cpp")
|
||||
|
||||
env_gltf.add_source_files(env.modules_sources, "structures/*.cpp")
|
||||
SConscript("extensions/SCsub")
|
@ -1,34 +0,0 @@
|
||||
def can_build(env, platform):
|
||||
return env["tools"] and not env["disable_3d"]
|
||||
|
||||
|
||||
def configure(env):
|
||||
pass
|
||||
|
||||
|
||||
def get_doc_classes():
|
||||
return [
|
||||
"EditorSceneImporterGLTF",
|
||||
"GLTFAccessor",
|
||||
"GLTFAnimation",
|
||||
"GLTFBufferView",
|
||||
"GLTFCamera",
|
||||
"GLTFCollider",
|
||||
"GLTFDocument",
|
||||
"GLTFDocumentExtension",
|
||||
"GLTFLight",
|
||||
"GLTFMesh",
|
||||
"GLTFNode",
|
||||
"GLTFPhysicsBody",
|
||||
"GLTFSkeleton",
|
||||
"GLTFSkin",
|
||||
"GLTFSpecGloss",
|
||||
"GLTFState",
|
||||
"GLTFTexture",
|
||||
"GLTFTextureSampler",
|
||||
"PackedSceneGLTF",
|
||||
]
|
||||
|
||||
|
||||
def get_doc_path():
|
||||
return "doc_classes"
|
@ -1,44 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFAccessor" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFAccessor] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="buffer_view" type="int" setter="set_buffer_view" getter="get_buffer_view" default="0">
|
||||
</member>
|
||||
<member name="byte_offset" type="int" setter="set_byte_offset" getter="get_byte_offset" default="0">
|
||||
</member>
|
||||
<member name="component_type" type="int" setter="set_component_type" getter="get_component_type" default="0">
|
||||
</member>
|
||||
<member name="count" type="int" setter="set_count" getter="get_count" default="0">
|
||||
</member>
|
||||
<member name="max" type="PoolRealArray" setter="set_max" getter="get_max" default="PoolRealArray( )">
|
||||
</member>
|
||||
<member name="min" type="PoolRealArray" setter="set_min" getter="get_min" default="PoolRealArray( )">
|
||||
</member>
|
||||
<member name="normalized" type="bool" setter="set_normalized" getter="get_normalized" default="false">
|
||||
</member>
|
||||
<member name="sparse_count" type="int" setter="set_sparse_count" getter="get_sparse_count" default="0">
|
||||
</member>
|
||||
<member name="sparse_indices_buffer_view" type="int" setter="set_sparse_indices_buffer_view" getter="get_sparse_indices_buffer_view" default="0">
|
||||
</member>
|
||||
<member name="sparse_indices_byte_offset" type="int" setter="set_sparse_indices_byte_offset" getter="get_sparse_indices_byte_offset" default="0">
|
||||
</member>
|
||||
<member name="sparse_indices_component_type" type="int" setter="set_sparse_indices_component_type" getter="get_sparse_indices_component_type" default="0">
|
||||
</member>
|
||||
<member name="sparse_values_buffer_view" type="int" setter="set_sparse_values_buffer_view" getter="get_sparse_values_buffer_view" default="0">
|
||||
</member>
|
||||
<member name="sparse_values_byte_offset" type="int" setter="set_sparse_values_byte_offset" getter="get_sparse_values_byte_offset" default="0">
|
||||
</member>
|
||||
<member name="type" type="int" setter="set_type" getter="get_type" default="0">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFAnimation" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFAnimation] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="loop" type="bool" setter="set_loop" getter="get_loop" default="false">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFBufferView" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFBufferView] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="buffer" type="int" setter="set_buffer" getter="get_buffer" default="-1">
|
||||
</member>
|
||||
<member name="byte_length" type="int" setter="set_byte_length" getter="get_byte_length" default="0">
|
||||
</member>
|
||||
<member name="byte_offset" type="int" setter="set_byte_offset" getter="get_byte_offset" default="0">
|
||||
</member>
|
||||
<member name="byte_stride" type="int" setter="set_byte_stride" getter="get_byte_stride" default="-1">
|
||||
</member>
|
||||
<member name="indices" type="bool" setter="set_indices" getter="get_indices" default="false">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,47 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFCamera" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
Represents a GLTF camera.
|
||||
</brief_description>
|
||||
<description>
|
||||
Represents a camera as defined by the base GLTF spec.
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFCamera] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="GLTF camera detailed specification">https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-camera</link>
|
||||
<link title="GLTF camera spec and example file">https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_015_SimpleCameras.md</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="to_dictionary" qualifiers="const">
|
||||
<return type="Dictionary" />
|
||||
<description>
|
||||
Serializes this GLTFCamera instance into a [Dictionary].
|
||||
</description>
|
||||
</method>
|
||||
<method name="to_node" qualifiers="const">
|
||||
<return type="Camera" />
|
||||
<description>
|
||||
Converts this GLTFCamera instance into a Godot [Camera] node.
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="fov_size" type="float" setter="set_fov_size" getter="get_fov_size" default="1.309">
|
||||
The FOV of the camera. This class and GLTF define the camera FOV in radians, while Godot uses degrees. This maps to GLTF's [code]yfov[/code] property. This value is only used for perspective cameras, when [member perspective] is true.
|
||||
</member>
|
||||
<member name="perspective" type="bool" setter="set_perspective" getter="get_perspective" default="true">
|
||||
Whether or not the camera is in perspective mode. If false, the camera is in orthographic/orthogonal mode. This maps to GLTF's camera [code]type[/code] property. See [member Camera.projection] and the GLTF spec for more information.
|
||||
</member>
|
||||
<member name="size_mag" type="float" setter="set_size_mag" getter="get_size_mag" default="0.5">
|
||||
The size of the camera. This class and GLTF define the camera size magnitude as a radius in meters, while Godot defines it as a diameter in meters. This maps to GLTF's [code]ymag[/code] property. This value is only used for orthographic/orthogonal cameras, when [member perspective] is false.
|
||||
</member>
|
||||
<member name="zfar" type="float" setter="set_zfar" getter="get_zfar" default="4000.0">
|
||||
The distance to the far culling boundary for this camera relative to its local Z axis, in meters. This maps to GLTF's [code]zfar[/code] property.
|
||||
</member>
|
||||
<member name="znear" type="float" setter="set_znear" getter="get_znear" default="0.05">
|
||||
The distance to the near culling boundary for this camera relative to its local Z axis, in meters. This maps to GLTF's [code]znear[/code] property.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,53 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFCollider" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
Represents a GLTF collider.
|
||||
</brief_description>
|
||||
<description>
|
||||
Represents a collider as defined by the [code]OMI_collider[/code] GLTF extension. This class is an intermediary between the GLTF data and Godot's nodes, and it's abstracted in a way that allows adding support for different GLTF physics extensions in the future.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="OMI_collider GLTF extension">https://github.com/omigroup/gltf-extensions/tree/main/extensions/2.0/OMI_collider</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="to_dictionary" qualifiers="const">
|
||||
<return type="Dictionary" />
|
||||
<description>
|
||||
Serializes this GLTFCollider instance into a [Dictionary].
|
||||
</description>
|
||||
</method>
|
||||
<method name="to_node">
|
||||
<return type="CollisionShape" />
|
||||
<argument index="0" name="cache_shapes" type="bool" default="false" />
|
||||
<description>
|
||||
Converts this GLTFCollider instance into a Godot [CollisionShape] node.
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="array_mesh" type="ArrayMesh" setter="set_array_mesh" getter="get_array_mesh">
|
||||
The [ArrayMesh] resource of the collider. This is only used when the collider type is "hull" (convex hull) or "trimesh" (concave trimesh).
|
||||
</member>
|
||||
<member name="height" type="float" setter="set_height" getter="get_height" default="2.0">
|
||||
The height of the collider, in meters. This is only used when the collider type is "capsule" or "cylinder". This value should not be negative, and for "capsule" it should be at least twice the radius.
|
||||
</member>
|
||||
<member name="is_trigger" type="bool" setter="set_is_trigger" getter="get_is_trigger" default="false">
|
||||
If [code]true[/code], indicates that this collider is a trigger. For Godot, this means that the collider should be a child of an Area3D node.
|
||||
This is the only variable not used in the [method to_node] method, it's intended to be used alongside when deciding where to add the generated node as a child.
|
||||
</member>
|
||||
<member name="mesh_index" type="int" setter="set_mesh_index" getter="get_mesh_index" default="-1">
|
||||
The index of the collider's mesh in the GLTF file. This is only used when the collider type is "hull" (convex hull) or "trimesh" (concave trimesh).
|
||||
</member>
|
||||
<member name="radius" type="float" setter="set_radius" getter="get_radius" default="0.5">
|
||||
The radius of the collider, in meters. This is only used when the collider type is "capsule", "cylinder", or "sphere". This value should not be negative.
|
||||
</member>
|
||||
<member name="shape_type" type="String" setter="set_shape_type" getter="get_shape_type" default="""">
|
||||
The type of shape this collider represents. Valid values are "box", "capsule", "cylinder", "sphere", "hull", and "trimesh".
|
||||
</member>
|
||||
<member name="size" type="Vector3" setter="set_size" getter="get_size" default="Vector3( 1, 1, 1 )">
|
||||
The size of the collider, in meters. This is only used when the collider type is "box", and it represents the "diameter" of the box. This value should not be negative.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,36 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFDocument" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFDocument] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="register_gltf_document_extension">
|
||||
<return type="void" />
|
||||
<argument index="0" name="extension" type="GLTFDocumentExtension" />
|
||||
<argument index="1" name="first_priority" type="bool" default="false" />
|
||||
<description>
|
||||
Registers the given [GLTFDocumentExtension] instance with GLTFDocument. If [code]first_priority[/code] is true, this extension will be run first. Otherwise, it will be run last.
|
||||
[b]Note:[/b] Like GLTFDocument itself, all GLTFDocumentExtension classes must be stateless in order to function properly. If you need to store data, use the [code]set_additional_data[/code] and [code]get_additional_data[/code] methods in [GLTFState] or [GLTFNode].
|
||||
</description>
|
||||
</method>
|
||||
<method name="unregister_all_gltf_document_extensions">
|
||||
<return type="void" />
|
||||
<description>
|
||||
Unregisters all [GLTFDocumentExtension] instances.
|
||||
</description>
|
||||
</method>
|
||||
<method name="unregister_gltf_document_extension">
|
||||
<return type="void" />
|
||||
<argument index="0" name="extension" type="GLTFDocumentExtension" />
|
||||
<description>
|
||||
Unregisters the given [GLTFDocumentExtension] instance.
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,118 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFDocumentExtension" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
[GLTFDocument] extension class.
|
||||
</brief_description>
|
||||
<description>
|
||||
Extends the functionality of the [GLTFDocument] class by allowing you to run arbitrary code at various stages of GLTF import or export.
|
||||
[b]Note:[/b] Like GLTFDocument itself, all GLTFDocumentExtension classes must be stateless in order to function properly. If you need to store data, use the [code]set_additional_data[/code] and [code]get_additional_data[/code] methods in [GLTFState] or [GLTFNode].
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="_convert_scene_node" qualifiers="virtual">
|
||||
<return type="void" />
|
||||
<argument index="0" name="state" type="Object" />
|
||||
<argument index="1" name="gltf_node" type="Object" />
|
||||
<argument index="2" name="scene_node" type="Object" />
|
||||
<description>
|
||||
Part of the export process. This method is run after [method _export_preflight] and before [method _export_node].
|
||||
Runs when converting the data from a Godot scene node. This method can be used to process the Godot scene node data into a format that can be used by [method _export_node].
|
||||
</description>
|
||||
</method>
|
||||
<method name="_export_node" qualifiers="virtual">
|
||||
<return type="int" />
|
||||
<argument index="0" name="state" type="Object" />
|
||||
<argument index="1" name="gltf_node" type="Object" />
|
||||
<argument index="2" name="json" type="Dictionary" />
|
||||
<argument index="3" name="node" type="Object" />
|
||||
<description>
|
||||
Part of the export process. This method is run after [method _convert_scene_node] and before [method _export_post].
|
||||
This method can be used to modify the final JSON of each node.
|
||||
</description>
|
||||
</method>
|
||||
<method name="_export_post" qualifiers="virtual">
|
||||
<return type="int" />
|
||||
<argument index="0" name="state" type="Object" />
|
||||
<description>
|
||||
Part of the export process. This method is run last, after all other parts of the export process.
|
||||
This method can be used to modify the final JSON of the generated GLTF file.
|
||||
</description>
|
||||
</method>
|
||||
<method name="_export_preflight" qualifiers="virtual">
|
||||
<return type="int" />
|
||||
<argument index="0" name="state" type="Object" />
|
||||
<argument index="1" name="root" type="Object" />
|
||||
<description>
|
||||
Part of the export process. This method is run first, before all other parts of the export process.
|
||||
The return value is used to determine if this [GLTFDocumentExtension] instance should be used for exporting a given GLTF file. If [constant OK], the export will use this [GLTFDocumentExtension] instance. If not overridden, [constant OK] is returned.
|
||||
</description>
|
||||
</method>
|
||||
<method name="_generate_scene_node" qualifiers="virtual">
|
||||
<return type="Object" />
|
||||
<argument index="0" name="state" type="Object" />
|
||||
<argument index="1" name="gltf_node" type="Object" />
|
||||
<argument index="2" name="scene_parent" type="Object" />
|
||||
<description>
|
||||
Part of the import process. This method is run after [method _parse_node_extensions] and before [method _import_post_parse].
|
||||
Runs when generating a Godot scene node from a GLTFNode. The returned node will be added to the scene tree. Multiple nodes can be generated in this step if they are added as a child of the returned node.
|
||||
</description>
|
||||
</method>
|
||||
<method name="_get_supported_extensions" qualifiers="virtual">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
Part of the import process. This method is run after [method _import_preflight] and before [method _parse_node_extensions].
|
||||
Returns an array of the GLTF extensions supported by this GLTFDocumentExtension class. This is used to validate if a GLTF file with required extensions can be loaded.
|
||||
</description>
|
||||
</method>
|
||||
<method name="_import_node" qualifiers="virtual">
|
||||
<return type="int" />
|
||||
<argument index="0" name="state" type="Object" />
|
||||
<argument index="1" name="gltf_node" type="Object" />
|
||||
<argument index="2" name="json" type="Dictionary" />
|
||||
<argument index="3" name="node" type="Object" />
|
||||
<description>
|
||||
Part of the import process. This method is run after [method _import_post_parse] and before [method _import_post].
|
||||
This method can be used to make modifications to each of the generated Godot scene nodes.
|
||||
</description>
|
||||
</method>
|
||||
<method name="_import_post" qualifiers="virtual">
|
||||
<return type="int" />
|
||||
<argument index="0" name="state" type="Object" />
|
||||
<argument index="1" name="root" type="Object" />
|
||||
<description>
|
||||
Part of the import process. This method is run last, after all other parts of the import process.
|
||||
This method can be used to modify the final Godot scene generated by the import process.
|
||||
</description>
|
||||
</method>
|
||||
<method name="_import_post_parse" qualifiers="virtual">
|
||||
<return type="int" />
|
||||
<argument index="0" name="state" type="Object" />
|
||||
<description>
|
||||
Part of the import process. This method is run after [method _generate_scene_node] and before [method _import_node].
|
||||
This method can be used to modify any of the data imported so far, including any scene nodes, before running the final per-node import step.
|
||||
</description>
|
||||
</method>
|
||||
<method name="_import_preflight" qualifiers="virtual">
|
||||
<return type="int" />
|
||||
<argument index="0" name="state" type="Object" />
|
||||
<argument index="1" name="extensions" type="PoolStringArray" />
|
||||
<description>
|
||||
Part of the import process. This method is run first, before all other parts of the import process.
|
||||
The return value is used to determine if this [GLTFDocumentExtension] instance should be used for importing a given GLTF file. If [constant OK], the import will use this [GLTFDocumentExtension] instance. If not overridden, [constant OK] is returned.
|
||||
</description>
|
||||
</method>
|
||||
<method name="_parse_node_extensions" qualifiers="virtual">
|
||||
<return type="int" />
|
||||
<argument index="0" name="state" type="Object" />
|
||||
<argument index="1" name="gltf_node" type="Object" />
|
||||
<argument index="2" name="extensions" type="Dictionary" />
|
||||
<description>
|
||||
Part of the import process. This method is run after [method _get_supported_extensions] and before [method _generate_scene_node].
|
||||
Runs when parsing the node extensions of a GLTFNode. This method can be used to process the extension JSON data into a format that can be used by [method _generate_scene_node]. The return value should be a member of the [enum Error] enum.
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,51 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFLight" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
Represents a GLTF light.
|
||||
</brief_description>
|
||||
<description>
|
||||
Represents a light as defined by the [code]KHR_lights_punctual[/code] GLTF extension.
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFLight] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="KHR_lights_punctual GLTF extension spec">https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="to_dictionary" qualifiers="const">
|
||||
<return type="Dictionary" />
|
||||
<description>
|
||||
Serializes this GLTFLight instance into a [Dictionary].
|
||||
</description>
|
||||
</method>
|
||||
<method name="to_node" qualifiers="const">
|
||||
<return type="Light" />
|
||||
<description>
|
||||
Converts this GLTFLight instance into a Godot [Light] node.
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="color" type="Color" setter="set_color" getter="get_color" default="Color( 1, 1, 1, 1 )">
|
||||
The [Color] of the light. Defaults to white. A black color causes the light to have no effect.
|
||||
</member>
|
||||
<member name="inner_cone_angle" type="float" setter="set_inner_cone_angle" getter="get_inner_cone_angle" default="0.0">
|
||||
The inner angle of the cone in a spotlight. Must be less than or equal to the outer cone angle.
|
||||
Within this angle, the light is at full brightness. Between the inner and outer cone angles, there is a transition from full brightness to zero brightness. When creating a Pandemonium [SpotLight], the ratio between the inner and outer cone angles is used to calculate the attenuation of the light.
|
||||
</member>
|
||||
<member name="intensity" type="float" setter="set_intensity" getter="get_intensity" default="1.0">
|
||||
The intensity of the light. This is expressed in candelas (lumens per steradian) for point and spot lights, and lux (lumens per m²) for directional lights. When creating a Pandemonium light, this value is converted to a unitless multiplier.
|
||||
</member>
|
||||
<member name="outer_cone_angle" type="float" setter="set_outer_cone_angle" getter="get_outer_cone_angle" default="0.785398">
|
||||
The outer angle of the cone in a spotlight. Must be greater than or equal to the inner angle.
|
||||
At this angle, the light drops off to zero brightness. Between the inner and outer cone angles, there is a transition from full brightness to zero brightness. If this angle is a half turn, then the spotlight emits in all directions. When creating a Pandemonium [SpotLight], the outer cone angle is used as the angle of the spotlight.
|
||||
</member>
|
||||
<member name="range" type="float" setter="set_range" getter="get_range" default="inf">
|
||||
The range of the light, beyond which the light has no effect. GLTF lights with no range defined behave like physical lights (which have infinite range). When creating a Pandemonium light, the range is clamped to 4096.
|
||||
</member>
|
||||
<member name="type" type="String" setter="set_type" getter="get_type" default="""">
|
||||
The type of the light. The values accepted by Pandemonium are "point", "spot", and "directional", which correspond to Pandemonium's [OmniLight], [SpotLight], and [DirectionalLight] respectively.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFMesh" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFMesh] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="blend_weights" type="PoolRealArray" setter="set_blend_weights" getter="get_blend_weights" default="PoolRealArray( )">
|
||||
</member>
|
||||
<member name="instance_materials" type="Array" setter="set_instance_materials" getter="get_instance_materials" default="[ ]">
|
||||
</member>
|
||||
<member name="mesh" type="ArrayMesh" setter="set_mesh" getter="get_mesh">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,75 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFNode" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
GLTF node class.
|
||||
</brief_description>
|
||||
<description>
|
||||
Represents a GLTF node. GLTF nodes may have names, transforms, children (other GLTF nodes), and more specialized properties (represented by their own classes).
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFNode] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="GLTF scene and node spec">https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_004_ScenesNodes.md"</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="get_additional_data">
|
||||
<return type="Variant" />
|
||||
<argument index="0" name="extension_name" type="String" />
|
||||
<description>
|
||||
Gets additional arbitrary data in this [GLTFNode] instance. This can be used to keep per-node state data in [GLTFDocumentExtension] classes, which is important because they are stateless.
|
||||
The argument should be the [GLTFDocumentExtension] name (does not have to match the extension name in the GLTF file), and the return value can be anything you set. If nothing was set, the return value is null.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_additional_data">
|
||||
<return type="void" />
|
||||
<argument index="0" name="extension_name" type="String" />
|
||||
<argument index="1" name="additional_data" type="Variant" />
|
||||
<description>
|
||||
Sets additional arbitrary data in this [GLTFNode] instance. This can be used to keep per-node state data in [GLTFDocumentExtension] classes, which is important because they are stateless.
|
||||
The first argument should be the [GLTFDocumentExtension] name (does not have to match the extension name in the GLTF file), and the second argument can be anything you want.
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="camera" type="int" setter="set_camera" getter="get_camera" default="-1">
|
||||
If this GLTF node is a camera, the index of the [GLTFCamera] in the [GLTFState] that describes the camera's properties. If -1, this node is not a camera.
|
||||
</member>
|
||||
<member name="children" type="PoolIntArray" setter="set_children" getter="get_children" default="PoolIntArray( )">
|
||||
The indices of the children nodes in the [GLTFState]. If this GLTF node has no children, this will be an empty array.
|
||||
</member>
|
||||
<member name="height" type="int" setter="set_height" getter="get_height" default="-1">
|
||||
How deep into the node hierarchy this node is. A root node will have a height of 0, its children will have a height of 1, and so on. If -1, the height has not been calculated.
|
||||
</member>
|
||||
<member name="joint" type="bool" setter="set_joint" getter="get_joint" default="false">
|
||||
This property is unused and does nothing.
|
||||
</member>
|
||||
<member name="light" type="int" setter="set_light" getter="get_light" default="-1">
|
||||
If this GLTF node is a light, the index of the [GLTFLight] in the [GLTFState] that describes the light's properties. If -1, this node is not a light.
|
||||
</member>
|
||||
<member name="mesh" type="int" setter="set_mesh" getter="get_mesh" default="-1">
|
||||
If this GLTF node is a mesh, the index of the [GLTFMesh] in the [GLTFState] that describes the mesh's properties. If -1, this node is not a mesh.
|
||||
</member>
|
||||
<member name="parent" type="int" setter="set_parent" getter="get_parent" default="-1">
|
||||
The index of the parent node in the [GLTFState]. If -1, this node is a root node.
|
||||
</member>
|
||||
<member name="rotation" type="Quaternion" setter="set_rotation" getter="get_rotation" default="Quaternion( 0, 0, 0, 1 )">
|
||||
The rotation of the GLTF node relative to its parent.
|
||||
</member>
|
||||
<member name="scale" type="Vector3" setter="set_scale" getter="get_scale" default="Vector3( 1, 1, 1 )">
|
||||
The scale of the GLTF node relative to its parent.
|
||||
</member>
|
||||
<member name="skeleton" type="int" setter="set_skeleton" getter="get_skeleton" default="-1">
|
||||
If this GLTF node has a skeleton, the index of the [GLTFSkeleton] in the [GLTFState] that describes the skeleton's properties. If -1, this node does not have a skeleton.
|
||||
</member>
|
||||
<member name="skin" type="int" setter="set_skin" getter="get_skin" default="-1">
|
||||
If this GLTF node has a skin, the index of the [GLTFSkin] in the [GLTFState] that describes the skin's properties. If -1, this node does not have a skin.
|
||||
</member>
|
||||
<member name="translation" type="Vector3" setter="set_translation" getter="get_translation" default="Vector3( 0, 0, 0 )">
|
||||
The position of the GLTF node relative to its parent.
|
||||
</member>
|
||||
<member name="xform" type="Transform" setter="set_xform" getter="get_xform" default="Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )">
|
||||
The transform of the GLTF node relative to its parent. This property is usually unused since the position, rotation, and scale properties are preferred.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,42 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFPhysicsBody" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
Represents a GLTF physics body.
|
||||
</brief_description>
|
||||
<description>
|
||||
Represents a physics body as defined by the [code]OMI_physics_body[/code] GLTF extension. This class is an intermediary between the GLTF data and Godot's nodes, and it's abstracted in a way that allows adding support for different GLTF physics extensions in the future.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="OMI_physics_body GLTF extension">https://github.com/omigroup/gltf-extensions/tree/main/extensions/2.0/OMI_physics_body</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="to_dictionary" qualifiers="const">
|
||||
<return type="Dictionary" />
|
||||
<description>
|
||||
Serializes this GLTFPhysicsBody instance into a [Dictionary].
|
||||
</description>
|
||||
</method>
|
||||
<method name="to_node" qualifiers="const">
|
||||
<return type="CollisionObject" />
|
||||
<description>
|
||||
Converts this GLTFPhysicsBody instance into a Godot [CollisionObject] node.
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="angular_velocity" type="Vector3" setter="set_angular_velocity" getter="get_angular_velocity" default="Vector3( 0, 0, 0 )">
|
||||
The angular velocity of the physics body, in radians per second. This is only used when the body type is "rigid" or "vehicle".
|
||||
</member>
|
||||
<member name="body_type" type="String" setter="set_body_type" getter="get_body_type" default=""static"">
|
||||
The type of the body. Valid values are "static", "kinematic", "character", "rigid", "vehicle", and "trigger".
|
||||
</member>
|
||||
<member name="linear_velocity" type="Vector3" setter="set_linear_velocity" getter="get_linear_velocity" default="Vector3( 0, 0, 0 )">
|
||||
The linear velocity of the physics body, in meters per second. This is only used when the body type is "rigid" or "vehicle".
|
||||
</member>
|
||||
<member name="mass" type="float" setter="set_mass" getter="get_mass" default="1.0">
|
||||
The mass of the physics body, in kilograms. This is only used when the body type is "rigid" or "vehicle".
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,58 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFSkeleton" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFSkeleton] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="get_bone_attachment">
|
||||
<return type="BoneAttachment" />
|
||||
<argument index="0" name="idx" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_bone_attachment_count">
|
||||
<return type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_pandemonium_bone_node">
|
||||
<return type="Dictionary" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_pandemonium_skeleton">
|
||||
<return type="Skeleton" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_unique_names">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_pandemonium_bone_node">
|
||||
<return type="void" />
|
||||
<argument index="0" name="pandemonium_bone_node" type="Dictionary" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_unique_names">
|
||||
<return type="void" />
|
||||
<argument index="0" name="unique_names" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="joints" type="PoolIntArray" setter="set_joints" getter="get_joints" default="PoolIntArray( )">
|
||||
</member>
|
||||
<member name="roots" type="PoolIntArray" setter="set_roots" getter="get_roots" default="PoolIntArray( )">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,62 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFSkin" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="get_inverse_binds">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_joint_i_to_bone_i">
|
||||
<return type="Dictionary" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_joint_i_to_name">
|
||||
<return type="Dictionary" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_inverse_binds">
|
||||
<return type="void" />
|
||||
<argument index="0" name="inverse_binds" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_joint_i_to_bone_i">
|
||||
<return type="void" />
|
||||
<argument index="0" name="joint_i_to_bone_i" type="Dictionary" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_joint_i_to_name">
|
||||
<return type="void" />
|
||||
<argument index="0" name="joint_i_to_name" type="Dictionary" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="joints" type="PoolIntArray" setter="set_joints" getter="get_joints" default="PoolIntArray( )">
|
||||
</member>
|
||||
<member name="joints_original" type="PoolIntArray" setter="set_joints_original" getter="get_joints_original" default="PoolIntArray( )">
|
||||
</member>
|
||||
<member name="non_joints" type="PoolIntArray" setter="set_non_joints" getter="get_non_joints" default="PoolIntArray( )">
|
||||
</member>
|
||||
<member name="pandemonium_skin" type="Skin" setter="set_pandemonium_skin" getter="get_pandemonium_skin">
|
||||
</member>
|
||||
<member name="roots" type="PoolIntArray" setter="set_roots" getter="get_roots" default="PoolIntArray( )">
|
||||
</member>
|
||||
<member name="skeleton" type="int" setter="set_skeleton" getter="get_skeleton" default="-1">
|
||||
</member>
|
||||
<member name="skin_root" type="int" setter="set_skin_root" getter="get_skin_root" default="-1">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFSpecGloss" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFSpecGloss] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="KHR_materials_pbrSpecularGlossiness GLTF extension spec">https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="diffuse_factor" type="Color" setter="set_diffuse_factor" getter="get_diffuse_factor" default="Color( 1, 1, 1, 1 )">
|
||||
The reflected diffuse factor of the material.
|
||||
</member>
|
||||
<member name="diffuse_img" type="Image" setter="set_diffuse_img" getter="get_diffuse_img">
|
||||
The diffuse texture.
|
||||
</member>
|
||||
<member name="gloss_factor" type="float" setter="set_gloss_factor" getter="get_gloss_factor" default="1.0">
|
||||
The glossiness or smoothness of the material.
|
||||
</member>
|
||||
<member name="spec_gloss_img" type="Image" setter="set_spec_gloss_img" getter="get_spec_gloss_img">
|
||||
The specular-glossiness texture.
|
||||
</member>
|
||||
<member name="specular_factor" type="Color" setter="set_specular_factor" getter="get_specular_factor" default="Color( 1, 1, 1, 1 )">
|
||||
The specular RGB color of the material. The alpha channel is unused.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,267 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFState" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
Represents all data of a GLTF file.
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFState] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="add_used_extension">
|
||||
<return type="void" />
|
||||
<argument index="0" name="extension_name" type="String" />
|
||||
<argument index="1" name="required" type="bool" />
|
||||
<description>
|
||||
Appends an extension to the list of extensions used by this GLTF file during serialization. If [code]required[/code] is true, the extension will also be added to the list of required extensions. Do not run this in [method GLTFDocumentExtension._export_post], as that stage is too late to add extensions. The final list is sorted alphabetically.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_accessors">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_additional_data">
|
||||
<return type="Variant" />
|
||||
<argument index="0" name="extension_name" type="String" />
|
||||
<description>
|
||||
Gets additional arbitrary data in this [GLTFState] instance. This can be used to keep per-file state data in [GLTFDocumentExtension] classes, which is important because they are stateless.
|
||||
The argument should be the [GLTFDocumentExtension] name (does not have to match the extension name in the GLTF file), and the return value can be anything you set. If nothing was set, the return value is null.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_animation_player">
|
||||
<return type="AnimationPlayer" />
|
||||
<argument index="0" name="idx" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_animation_players_count">
|
||||
<return type="int" />
|
||||
<argument index="0" name="idx" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_animations">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
Returns an array of all [GLTFAnimation]s in the GLTF file. When importing, these will be generated as animations in an [AnimationPlayer] node. When exporting, these will be generated from Godot [AnimationPlayer] nodes.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_buffer_views">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_cameras">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
Returns an array of all [GLTFCamera]s in the GLTF file. These are the cameras that the [member GLTFNode.camera] index refers to.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_images">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_lights">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
Returns an array of all [GLTFLight]s in the GLTF file. These are the lights that the [member GLTFNode.light] index refers to.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_materials">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_meshes">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
Returns an array of all [GLTFMesh]es in the GLTF file. These are the meshes that the [member GLTFNode.mesh] index refers to.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_nodes">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
Returns an array of all [GLTFNode]s in the GLTF file. These are the nodes that [member GLTFNode.children] and [member root_nodes] refer to. This includes nodes that may not be generated in the Godot scene, or nodes that may generate multiple Godot scene nodes.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_scene_node">
|
||||
<return type="Node" />
|
||||
<argument index="0" name="idx" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_skeleton_to_node">
|
||||
<return type="Dictionary" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_skeletons">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
Returns an array of all [GLTFSkeleton]s in the GLTF file. These are the skeletons that the [member GLTFNode.skeleton] index refers to.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_skins">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
Returns an array of all [GLTFSkin]s in the GLTF file. These are the skins that the [member GLTFNode.skin] index refers to.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_texture_samplers">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
Retrieves the array of texture samplers that are used by the textures contained in the GLTF.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_textures">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_unique_animation_names">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
Returns an array of unique animation names. This is only used during the import process.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_unique_names">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
Returns an array of unique node names. This is used in both the import process and export process.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_accessors">
|
||||
<return type="void" />
|
||||
<argument index="0" name="accessors" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_additional_data">
|
||||
<return type="void" />
|
||||
<argument index="0" name="extension_name" type="String" />
|
||||
<argument index="1" name="additional_data" type="Variant" />
|
||||
<description>
|
||||
Sets additional arbitrary data in this [GLTFState] instance. This can be used to keep per-file state data in [GLTFDocumentExtension] classes, which is important because they are stateless.
|
||||
The first argument should be the [GLTFDocumentExtension] name (does not have to match the extension name in the GLTF file), and the second argument can be anything you want.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_animations">
|
||||
<return type="void" />
|
||||
<argument index="0" name="animations" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_buffer_views">
|
||||
<return type="void" />
|
||||
<argument index="0" name="buffer_views" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_cameras">
|
||||
<return type="void" />
|
||||
<argument index="0" name="cameras" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_images">
|
||||
<return type="void" />
|
||||
<argument index="0" name="images" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_lights">
|
||||
<return type="void" />
|
||||
<argument index="0" name="lights" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_materials">
|
||||
<return type="void" />
|
||||
<argument index="0" name="materials" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_meshes">
|
||||
<return type="void" />
|
||||
<argument index="0" name="meshes" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_nodes">
|
||||
<return type="void" />
|
||||
<argument index="0" name="nodes" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_skeleton_to_node">
|
||||
<return type="void" />
|
||||
<argument index="0" name="skeleton_to_node" type="Dictionary" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_skeletons">
|
||||
<return type="void" />
|
||||
<argument index="0" name="skeletons" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_skins">
|
||||
<return type="void" />
|
||||
<argument index="0" name="skins" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_texture_samplers">
|
||||
<return type="void" />
|
||||
<argument index="0" name="texture_samplers" type="Array" />
|
||||
<description>
|
||||
Sets the array of texture samplers that are used by the textures contained in the GLTF.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_textures">
|
||||
<return type="void" />
|
||||
<argument index="0" name="textures" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_unique_animation_names">
|
||||
<return type="void" />
|
||||
<argument index="0" name="unique_animation_names" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_unique_names">
|
||||
<return type="void" />
|
||||
<argument index="0" name="unique_names" type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="buffers" type="Array" setter="set_buffers" getter="get_buffers" default="[ ]">
|
||||
</member>
|
||||
<member name="create_animations" type="bool" setter="set_create_animations" getter="get_create_animations" default="true">
|
||||
</member>
|
||||
<member name="glb_data" type="PoolByteArray" setter="set_glb_data" getter="get_glb_data" default="PoolByteArray( )">
|
||||
</member>
|
||||
<member name="json" type="Dictionary" setter="set_json" getter="get_json" default="{}">
|
||||
</member>
|
||||
<member name="major_version" type="int" setter="set_major_version" getter="get_major_version" default="0">
|
||||
</member>
|
||||
<member name="minor_version" type="int" setter="set_minor_version" getter="get_minor_version" default="0">
|
||||
</member>
|
||||
<member name="root_nodes" type="Array" setter="set_root_nodes" getter="get_root_nodes" default="[ ]">
|
||||
The root nodes of the GLTF file. Typically, a GLTF file will only have one scene, and therefore one root node. However, a GLTF file may have multiple scenes and therefore multiple root nodes, which will be generated as siblings of each other and as children of the root node of the generated Godot scene.
|
||||
</member>
|
||||
<member name="scene_name" type="String" setter="set_scene_name" getter="get_scene_name" default="""">
|
||||
The name of the scene. When importing, if not specified, this will be the file name. When exporting, if specified, the scene name will be saved to the GLTF file.
|
||||
</member>
|
||||
<member name="use_named_skin_binds" type="bool" setter="set_use_named_skin_binds" getter="get_use_named_skin_binds" default="false">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFTexture" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [GLTFTexture] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="sampler" type="int" setter="set_sampler" getter="get_sampler" default="-1">
|
||||
ID of the texture sampler to use when sampling the image. If -1, then the default texture sampler is used (linear filtering, and repeat wrapping in both axes).
|
||||
</member>
|
||||
<member name="src_image" type="int" setter="set_src_image" getter="get_src_image" default="0">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GLTFTextureSampler" inherits="Resource" version="4.2">
|
||||
<brief_description>
|
||||
Represents a GLTF texture sampler
|
||||
</brief_description>
|
||||
<description>
|
||||
Represents a texture sampler as defined by the base GLTF spec. Texture samplers in GLTF specify how to sample data from the texture's base image, when rendering the texture on an object.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="mag_filter" type="int" setter="set_mag_filter" getter="get_mag_filter" default="9729">
|
||||
Texture's magnification filter, used when the texture appears larger on screen than the source image.
|
||||
</member>
|
||||
<member name="min_filter" type="int" setter="set_min_filter" getter="get_min_filter" default="9987">
|
||||
Texture's minification filter, used when the texture appears smaller on screen than the source image.
|
||||
</member>
|
||||
<member name="wrap_s" type="int" setter="set_wrap_s" getter="get_wrap_s" default="10497">
|
||||
Wrapping mode to use for S-axis (horizontal) texture coordinates.
|
||||
</member>
|
||||
<member name="wrap_t" type="int" setter="set_wrap_t" getter="get_wrap_t" default="10497">
|
||||
Wrapping mode to use for T-axis (vertical) texture coordinates.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,46 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="PackedSceneGLTF" inherits="PackedScene" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
[b]Note:[/b] This class is only compiled in editor builds. Run-time glTF loading and saving is [i]not[/i] available in exported projects. References to [PackedSceneGLTF] within a script will cause an error in an exported project.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="export_gltf">
|
||||
<return type="int" enum="Error" />
|
||||
<argument index="0" name="node" type="Node" />
|
||||
<argument index="1" name="path" type="String" />
|
||||
<argument index="2" name="flags" type="int" default="0" />
|
||||
<argument index="3" name="bake_fps" type="float" default="1000.0" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="import_gltf_scene">
|
||||
<return type="Node" />
|
||||
<argument index="0" name="path" type="String" />
|
||||
<argument index="1" name="flags" type="int" default="0" />
|
||||
<argument index="2" name="bake_fps" type="float" default="1000.0" />
|
||||
<argument index="3" name="compress_flags" type="int" default="2194432" />
|
||||
<argument index="4" name="state" type="GLTFState" default="null" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="pack_gltf">
|
||||
<return type="void" />
|
||||
<argument index="0" name="path" type="String" />
|
||||
<argument index="1" name="flags" type="int" default="0" />
|
||||
<argument index="2" name="bake_fps" type="float" default="1000.0" />
|
||||
<argument index="3" name="compress_flags" type="int" default="2194432" />
|
||||
<argument index="4" name="state" type="GLTFState" default="null" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="_bundled" type="Dictionary" setter="_set_bundled_scene" getter="_get_bundled_scene" overrides="PackedScene" default="{"conn_count": 0,"conns": PoolIntArray( ),"editable_instances": [ ],"names": PoolStringArray( ),"node_count": 0,"node_paths": [ ],"nodes": PoolIntArray( ),"variants": [ ],"version": 2}" />
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,95 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* editor_scene_exporter_gltf_plugin.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "editor_scene_exporter_gltf_plugin.h"
|
||||
|
||||
#include "editor/editor_file_dialog.h"
|
||||
#include "editor/editor_file_system.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "scene/main/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", this, "_gltf2_dialog_action");
|
||||
file_export_lib->set_title(TTR("Export Library"));
|
||||
file_export_lib->set_mode(EditorFileDialog::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_convert_menu_item(gltf_scene_name, this, "convert_scene_to_gltf2", DEFVAL(Variant()));
|
||||
}
|
||||
|
||||
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::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("convert_scene_to_gltf2"), &SceneExporterGLTFPlugin::convert_scene_to_gltf2);
|
||||
ClassDB::bind_method(D_METHOD("_gltf2_dialog_action", "file"), &SceneExporterGLTFPlugin::_gltf2_dialog_action);
|
||||
}
|
||||
|
||||
void SceneExporterGLTFPlugin::convert_scene_to_gltf2(Variant p_null) {
|
||||
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 + ".gltf");
|
||||
file_export_lib->popup_centered_ratio();
|
||||
}
|
||||
|
||||
#endif // TOOLS_ENABLED
|
@ -1,56 +0,0 @@
|
||||
#ifndef EDITOR_SCENE_EXPORTER_GLTF_PLUGIN_H
|
||||
#define EDITOR_SCENE_EXPORTER_GLTF_PLUGIN_H
|
||||
/*************************************************************************/
|
||||
/* editor_scene_exporter_gltf_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/editor_file_dialog.h"
|
||||
#include "editor/editor_plugin.h"
|
||||
|
||||
#include "packed_scene_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(Variant p_null);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
virtual String get_name() const;
|
||||
bool has_main_screen() const;
|
||||
SceneExporterGLTFPlugin(class EditorNode *p_node);
|
||||
};
|
||||
|
||||
#endif // EDITOR_SCENE_EXPORTER_GLTF_PLUGIN_H
|
@ -1,63 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* editor_scene_importer_gltf.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "editor_scene_importer_gltf.h"
|
||||
#include "scene/animation/animation.h"
|
||||
|
||||
#include "gltf_state.h"
|
||||
#include "packed_scene_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, uint32_t p_compress_flags,
|
||||
List<String> *r_missing_deps,
|
||||
Error *r_err) {
|
||||
Ref<PackedSceneGLTF> importer;
|
||||
importer.instance();
|
||||
return importer->import_scene(p_path, p_flags, p_bake_fps, p_compress_flags, 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>();
|
||||
}
|
||||
|
||||
#endif // TOOLS_ENABLED
|
@ -1,56 +0,0 @@
|
||||
#ifndef EDITOR_SCENE_IMPORTER_GLTF_H
|
||||
#define EDITOR_SCENE_IMPORTER_GLTF_H
|
||||
/*************************************************************************/
|
||||
/* editor_scene_importer_gltf.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "editor/import/resource_importer_scene.h"
|
||||
|
||||
#include "gltf_document.h"
|
||||
#include "gltf_state.h"
|
||||
|
||||
class EditorSceneImporterGLTF : public EditorSceneImporter {
|
||||
GDCLASS(EditorSceneImporterGLTF, EditorSceneImporter);
|
||||
|
||||
public:
|
||||
virtual uint32_t get_import_flags() const;
|
||||
virtual void get_extensions(List<String> *r_extensions) const;
|
||||
virtual Node *import_scene(const String &p_path, uint32_t p_flags,
|
||||
int p_bake_fps, uint32_t p_compress_flags,
|
||||
List<String> *r_missing_deps = nullptr,
|
||||
Error *r_err = nullptr);
|
||||
virtual Ref<Animation> import_animation(const String &p_path,
|
||||
uint32_t p_flags, int p_bake_fps);
|
||||
};
|
||||
|
||||
#endif // EDITOR_SCENE_IMPORTER_GLTF_H
|
||||
|
||||
#endif // TOOLS_ENABLED
|
@ -1,10 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
Import("env")
|
||||
Import("env_modules")
|
||||
|
||||
env_gltf = env_modules.Clone()
|
||||
|
||||
# Godot source files
|
||||
env_gltf.add_source_files(env.modules_sources, "*.cpp")
|
||||
env_gltf.add_source_files(env.modules_sources, "physics/*.cpp")
|
@ -1,172 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_document_extension.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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_document_extension.h"
|
||||
|
||||
#include "../gltf_document.h"
|
||||
#include "scene/main/spatial.h"
|
||||
|
||||
void GLTFDocumentExtension::_bind_methods() {
|
||||
// Import process.
|
||||
BIND_VMETHOD(MethodInfo(Variant::INT, "_import_preflight", PropertyInfo(Variant::OBJECT, "state"), PropertyInfo(Variant::POOL_STRING_ARRAY, "extensions")));
|
||||
BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_supported_extensions"));
|
||||
BIND_VMETHOD(MethodInfo(Variant::INT, "_parse_node_extensions", PropertyInfo(Variant::OBJECT, "state"), PropertyInfo(Variant::OBJECT, "gltf_node"), PropertyInfo(Variant::DICTIONARY, "extensions")));
|
||||
BIND_VMETHOD(MethodInfo(Variant::OBJECT, "_generate_scene_node", PropertyInfo(Variant::OBJECT, "state"), PropertyInfo(Variant::OBJECT, "gltf_node"), PropertyInfo(Variant::OBJECT, "scene_parent")));
|
||||
BIND_VMETHOD(MethodInfo(Variant::INT, "_import_post_parse", PropertyInfo(Variant::OBJECT, "state")));
|
||||
BIND_VMETHOD(MethodInfo(Variant::INT, "_import_node", PropertyInfo(Variant::OBJECT, "state"), PropertyInfo(Variant::OBJECT, "gltf_node"), PropertyInfo(Variant::DICTIONARY, "json"), PropertyInfo(Variant::OBJECT, "node")));
|
||||
BIND_VMETHOD(MethodInfo(Variant::INT, "_import_post", PropertyInfo(Variant::OBJECT, "state"), PropertyInfo(Variant::OBJECT, "root")));
|
||||
// Export process.
|
||||
BIND_VMETHOD(MethodInfo(Variant::INT, "_export_preflight", PropertyInfo(Variant::OBJECT, "state"), PropertyInfo(Variant::OBJECT, "root")));
|
||||
BIND_VMETHOD(MethodInfo("_convert_scene_node", PropertyInfo(Variant::OBJECT, "state"), PropertyInfo(Variant::OBJECT, "gltf_node"), PropertyInfo(Variant::OBJECT, "scene_node")));
|
||||
BIND_VMETHOD(MethodInfo(Variant::INT, "_export_node", PropertyInfo(Variant::OBJECT, "state"), PropertyInfo(Variant::OBJECT, "gltf_node"), PropertyInfo(Variant::DICTIONARY, "json"), PropertyInfo(Variant::OBJECT, "node")));
|
||||
BIND_VMETHOD(MethodInfo(Variant::INT, "_export_post", PropertyInfo(Variant::OBJECT, "state")));
|
||||
}
|
||||
|
||||
// Import process.
|
||||
Error GLTFDocumentExtension::import_preflight(Ref<GLTFState> p_state, Vector<String> p_extensions) {
|
||||
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
|
||||
ScriptInstance *si = get_script_instance();
|
||||
if (!si) {
|
||||
return Error::OK;
|
||||
}
|
||||
int err = si->call("_import_preflight", p_state, p_extensions);
|
||||
return Error(err);
|
||||
}
|
||||
|
||||
Vector<String> GLTFDocumentExtension::get_supported_extensions() {
|
||||
Vector<String> ret;
|
||||
ScriptInstance *si = get_script_instance();
|
||||
if (!si) {
|
||||
return ret;
|
||||
}
|
||||
si->call("_get_supported_extensions");
|
||||
return ret;
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::parse_node_extensions(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &p_extensions) {
|
||||
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(p_gltf_node.is_null(), ERR_INVALID_PARAMETER);
|
||||
ScriptInstance *si = get_script_instance();
|
||||
if (!si) {
|
||||
return Error::OK;
|
||||
}
|
||||
int err = si->call("_parse_node_extensions", p_state, p_gltf_node, p_extensions);
|
||||
return Error(err);
|
||||
}
|
||||
|
||||
Spatial *GLTFDocumentExtension::generate_scene_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Node *p_scene_parent) {
|
||||
ERR_FAIL_COND_V(p_state.is_null(), nullptr);
|
||||
ERR_FAIL_COND_V(p_gltf_node.is_null(), nullptr);
|
||||
ERR_FAIL_NULL_V(p_scene_parent, nullptr);
|
||||
ScriptInstance *si = get_script_instance();
|
||||
if (!si) {
|
||||
return nullptr;
|
||||
}
|
||||
Variant ret = si->call("_generate_scene_node", p_state, p_gltf_node, p_scene_parent);
|
||||
Spatial *ret_node = cast_to<Spatial>(ret.operator Object *());
|
||||
return ret_node;
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::import_post_parse(Ref<GLTFState> p_state) {
|
||||
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
|
||||
ScriptInstance *si = get_script_instance();
|
||||
if (!si) {
|
||||
return Error::OK;
|
||||
}
|
||||
int err = si->call("_import_post_parse", p_state);
|
||||
return Error(err);
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::import_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_dict, Node *p_node) {
|
||||
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(p_gltf_node.is_null(), ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER);
|
||||
ScriptInstance *si = get_script_instance();
|
||||
if (!si) {
|
||||
return Error::OK;
|
||||
}
|
||||
int err = si->call("_import_node", p_state, p_gltf_node, r_dict, p_node);
|
||||
return Error(err);
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::import_post(Ref<GLTFState> p_state, Node *p_root) {
|
||||
ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
|
||||
ScriptInstance *si = get_script_instance();
|
||||
if (!si) {
|
||||
return Error::OK;
|
||||
}
|
||||
int err = si->call("_import_post", p_state, p_root);
|
||||
return Error(err);
|
||||
}
|
||||
|
||||
// Export process.
|
||||
Error GLTFDocumentExtension::export_preflight(Ref<GLTFState> p_state, Node *p_root) {
|
||||
ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER);
|
||||
ScriptInstance *si = get_script_instance();
|
||||
if (!si) {
|
||||
return Error::OK;
|
||||
}
|
||||
int err = si->call("_export_preflight", p_root);
|
||||
return Error(err);
|
||||
}
|
||||
|
||||
void GLTFDocumentExtension::convert_scene_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Node *p_scene_node) {
|
||||
ERR_FAIL_COND(p_state.is_null());
|
||||
ERR_FAIL_COND(p_gltf_node.is_null());
|
||||
ERR_FAIL_NULL(p_scene_node);
|
||||
ScriptInstance *si = get_script_instance();
|
||||
if (!si) {
|
||||
return;
|
||||
}
|
||||
si->call("_convert_scene_node", p_state, p_gltf_node, p_scene_node);
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_dict, Node *p_node) {
|
||||
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(p_gltf_node.is_null(), ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER);
|
||||
ScriptInstance *si = get_script_instance();
|
||||
if (!si) {
|
||||
return Error::OK;
|
||||
}
|
||||
int err = si->call("_export_node", p_state, p_gltf_node, r_dict, p_node);
|
||||
return Error(err);
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtension::export_post(Ref<GLTFState> p_state) {
|
||||
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
|
||||
ScriptInstance *si = get_script_instance();
|
||||
if (!si) {
|
||||
return Error::OK;
|
||||
}
|
||||
int err = si->call("_export_post", p_state);
|
||||
return Error(err);
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_document_extension.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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_EXTENSION_H
|
||||
#define GLTF_DOCUMENT_EXTENSION_H
|
||||
|
||||
#include "core/object/resource.h"
|
||||
|
||||
#include "../gltf_state.h"
|
||||
|
||||
class Spatial;
|
||||
|
||||
class GLTFDocumentExtension : public Resource {
|
||||
GDCLASS(GLTFDocumentExtension, Resource);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
// Import process.
|
||||
virtual Error import_preflight(Ref<GLTFState> p_state, Vector<String> p_extensions);
|
||||
virtual Vector<String> get_supported_extensions();
|
||||
virtual Error parse_node_extensions(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &p_extensions);
|
||||
virtual Spatial *generate_scene_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Node *p_scene_parent);
|
||||
virtual Error import_post_parse(Ref<GLTFState> p_state);
|
||||
virtual Error import_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_json, Node *p_node);
|
||||
virtual Error import_post(Ref<GLTFState> p_state, Node *p_node);
|
||||
// Export process.
|
||||
virtual Error export_preflight(Ref<GLTFState> p_state, Node *p_root);
|
||||
virtual void convert_scene_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Node *p_scene_node);
|
||||
virtual Error export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_json, Node *p_node);
|
||||
virtual Error export_post(Ref<GLTFState> p_state);
|
||||
};
|
||||
|
||||
#endif // GLTF_DOCUMENT_EXTENSION_H
|
@ -1,219 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_light.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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"
|
||||
|
||||
#include "scene/3d/light.h"
|
||||
|
||||
void GLTFLight::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("to_node"), &GLTFLight::to_node);
|
||||
ClassDB::bind_method(D_METHOD("to_dictionary"), &GLTFLight::to_dictionary);
|
||||
|
||||
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::REAL, "intensity"), "set_intensity", "get_intensity"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "type"), "set_type", "get_type"); // String
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "range"), "set_range", "get_range"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "inner_cone_angle"), "set_inner_cone_angle", "get_inner_cone_angle"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "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;
|
||||
}
|
||||
|
||||
Ref<GLTFLight> GLTFLight::from_node(const Light *p_light) {
|
||||
Ref<GLTFLight> l;
|
||||
l.instance();
|
||||
ERR_FAIL_COND_V_MSG(!p_light, l, "Tried to create a GLTFLight from a Light node, but the given node was null.");
|
||||
l->color = p_light->get_color();
|
||||
if (cast_to<const DirectionalLight>(p_light)) {
|
||||
l->type = "directional";
|
||||
const DirectionalLight *light = cast_to<const DirectionalLight>(p_light);
|
||||
l->intensity = light->get_param(DirectionalLight::PARAM_ENERGY);
|
||||
l->range = FLT_MAX; // Range for directional lights is infinite in Godot.
|
||||
} else if (cast_to<const OmniLight>(p_light)) {
|
||||
l->type = "point";
|
||||
const OmniLight *light = cast_to<const OmniLight>(p_light);
|
||||
l->range = light->get_param(OmniLight::PARAM_RANGE);
|
||||
l->intensity = light->get_param(OmniLight::PARAM_ENERGY);
|
||||
} else if (cast_to<const SpotLight>(p_light)) {
|
||||
l->type = "spot";
|
||||
const SpotLight *light = cast_to<const SpotLight>(p_light);
|
||||
l->range = light->get_param(SpotLight::PARAM_RANGE);
|
||||
l->intensity = light->get_param(SpotLight::PARAM_ENERGY);
|
||||
l->outer_cone_angle = Math::deg2rad(light->get_param(SpotLight::PARAM_SPOT_ANGLE));
|
||||
// This equation is the inverse of the import equation (which has a desmos link).
|
||||
float angle_ratio = 1 - (0.2 / (0.1 + light->get_param(SpotLight::PARAM_SPOT_ATTENUATION)));
|
||||
angle_ratio = MAX(0, angle_ratio);
|
||||
l->inner_cone_angle = l->outer_cone_angle * angle_ratio;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
Light *GLTFLight::to_node() const {
|
||||
if (type == "directional") {
|
||||
DirectionalLight *light = memnew(DirectionalLight);
|
||||
light->set_param(Light::PARAM_ENERGY, intensity);
|
||||
light->set_color(color);
|
||||
return light;
|
||||
}
|
||||
if (type == "point") {
|
||||
OmniLight *light = memnew(OmniLight);
|
||||
light->set_param(OmniLight::PARAM_ENERGY, intensity);
|
||||
light->set_param(OmniLight::PARAM_RANGE, CLAMP(range, 0, 4096));
|
||||
light->set_color(color);
|
||||
return light;
|
||||
}
|
||||
if (type == "spot") {
|
||||
SpotLight *light = memnew(SpotLight);
|
||||
light->set_param(SpotLight::PARAM_ENERGY, intensity);
|
||||
light->set_param(SpotLight::PARAM_RANGE, CLAMP(range, 0, 4096));
|
||||
light->set_param(SpotLight::PARAM_SPOT_ANGLE, Math::rad2deg(outer_cone_angle));
|
||||
light->set_color(color);
|
||||
// Line of best fit derived from guessing, see https://www.desmos.com/calculator/biiflubp8b
|
||||
// The points in desmos are not exact, except for (1, infinity).
|
||||
float angle_ratio = inner_cone_angle / outer_cone_angle;
|
||||
float angle_attenuation = 0.2 / (1 - angle_ratio) - 0.1;
|
||||
light->set_param(SpotLight::PARAM_SPOT_ATTENUATION, angle_attenuation);
|
||||
return light;
|
||||
}
|
||||
return memnew(Light);
|
||||
}
|
||||
|
||||
Ref<GLTFLight> GLTFLight::from_dictionary(const Dictionary p_dictionary) {
|
||||
ERR_FAIL_COND_V_MSG(!p_dictionary.has("type"), Ref<GLTFLight>(), "Failed to parse GLTF light, missing required field 'type'.");
|
||||
Ref<GLTFLight> light;
|
||||
light.instance();
|
||||
const String &type = p_dictionary["type"];
|
||||
light->type = type;
|
||||
|
||||
if (p_dictionary.has("color")) {
|
||||
const Array &arr = p_dictionary["color"];
|
||||
if (arr.size() == 3) {
|
||||
light->color = Color(arr[0], arr[1], arr[2]).to_srgb();
|
||||
} else {
|
||||
ERR_PRINT("Error parsing GLTF light: The color must have exactly 3 numbers.");
|
||||
}
|
||||
}
|
||||
if (p_dictionary.has("intensity")) {
|
||||
light->intensity = p_dictionary["intensity"];
|
||||
}
|
||||
if (p_dictionary.has("range")) {
|
||||
light->range = p_dictionary["range"];
|
||||
}
|
||||
if (type == "spot") {
|
||||
const Dictionary &spot = p_dictionary["spot"];
|
||||
light->inner_cone_angle = spot["innerConeAngle"];
|
||||
light->outer_cone_angle = spot["outerConeAngle"];
|
||||
if (light->inner_cone_angle >= light->outer_cone_angle) {
|
||||
ERR_PRINT("Error parsing GLTF light: The inner angle must be smaller than the outer angle.");
|
||||
}
|
||||
} else if (type != "point" && type != "directional") {
|
||||
ERR_PRINT("Error parsing GLTF light: Light type '" + type + "' is unknown.");
|
||||
}
|
||||
return light;
|
||||
}
|
||||
|
||||
Dictionary GLTFLight::to_dictionary() const {
|
||||
Dictionary d;
|
||||
Array color_array;
|
||||
color_array.resize(3);
|
||||
color_array[0] = color.r;
|
||||
color_array[1] = color.g;
|
||||
color_array[2] = color.b;
|
||||
d["color"] = color_array;
|
||||
d["type"] = type;
|
||||
if (type == "spot") {
|
||||
Dictionary spot_dict;
|
||||
spot_dict["innerConeAngle"] = inner_cone_angle;
|
||||
spot_dict["outerConeAngle"] = outer_cone_angle;
|
||||
d["spot"] = spot_dict;
|
||||
}
|
||||
d["intensity"] = intensity;
|
||||
d["range"] = range;
|
||||
return d;
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
#ifndef GLTF_LIGHT_H
|
||||
#define GLTF_LIGHT_H
|
||||
/*************************************************************************/
|
||||
/* gltf_light.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/object/resource.h"
|
||||
|
||||
class Light;
|
||||
|
||||
// https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual
|
||||
|
||||
class GLTFLight : public Resource {
|
||||
GDCLASS(GLTFLight, Resource)
|
||||
friend class GLTFDocument;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Color color = Color(1.0f, 1.0f, 1.0f);
|
||||
float intensity = 1.0f;
|
||||
String type;
|
||||
float range = INFINITY;
|
||||
float inner_cone_angle = 0.0f;
|
||||
float outer_cone_angle = Math_TAU / 8.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);
|
||||
|
||||
static Ref<GLTFLight> from_node(const Light *p_light);
|
||||
Light *to_node() const;
|
||||
|
||||
static Ref<GLTFLight> from_dictionary(const Dictionary p_dictionary);
|
||||
Dictionary to_dictionary() const;
|
||||
};
|
||||
|
||||
#endif // GLTF_LIGHT_H
|
@ -1,90 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_spec_gloss.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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::REAL, "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;
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
#ifndef GLTF_SPEC_GLOSS_H
|
||||
#define GLTF_SPEC_GLOSS_H
|
||||
/*************************************************************************/
|
||||
/* gltf_spec_gloss.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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_defines.h"
|
||||
#include "core/io/image.h"
|
||||
#include "core/object/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
|
@ -1,304 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* gltf_collider.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "gltf_collider.h"
|
||||
|
||||
#include "../../gltf_state.h"
|
||||
#include "core/math/convex_hull.h"
|
||||
#include "scene/3d/area.h"
|
||||
#include "scene/resources/shapes/box_shape.h"
|
||||
#include "scene/resources/shapes/capsule_shape.h"
|
||||
#include "scene/resources/shapes/concave_polygon_shape.h"
|
||||
#include "scene/resources/shapes/convex_polygon_shape.h"
|
||||
#include "scene/resources/shapes/cylinder_shape.h"
|
||||
#include "scene/resources/shapes/sphere_shape.h"
|
||||
|
||||
void GLTFCollider::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("to_node", "cache_shapes"), &GLTFCollider::to_node, DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("to_dictionary"), &GLTFCollider::to_dictionary);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_shape_type"), &GLTFCollider::get_shape_type);
|
||||
ClassDB::bind_method(D_METHOD("set_shape_type", "shape_type"), &GLTFCollider::set_shape_type);
|
||||
ClassDB::bind_method(D_METHOD("get_size"), &GLTFCollider::get_size);
|
||||
ClassDB::bind_method(D_METHOD("set_size", "size"), &GLTFCollider::set_size);
|
||||
ClassDB::bind_method(D_METHOD("get_radius"), &GLTFCollider::get_radius);
|
||||
ClassDB::bind_method(D_METHOD("set_radius", "radius"), &GLTFCollider::set_radius);
|
||||
ClassDB::bind_method(D_METHOD("get_height"), &GLTFCollider::get_height);
|
||||
ClassDB::bind_method(D_METHOD("set_height", "height"), &GLTFCollider::set_height);
|
||||
ClassDB::bind_method(D_METHOD("get_is_trigger"), &GLTFCollider::get_is_trigger);
|
||||
ClassDB::bind_method(D_METHOD("set_is_trigger", "is_trigger"), &GLTFCollider::set_is_trigger);
|
||||
ClassDB::bind_method(D_METHOD("get_mesh_index"), &GLTFCollider::get_mesh_index);
|
||||
ClassDB::bind_method(D_METHOD("set_mesh_index", "mesh_index"), &GLTFCollider::set_mesh_index);
|
||||
ClassDB::bind_method(D_METHOD("get_array_mesh"), &GLTFCollider::get_array_mesh);
|
||||
ClassDB::bind_method(D_METHOD("set_array_mesh", "array_mesh"), &GLTFCollider::set_array_mesh);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "shape_type"), "set_shape_type", "get_shape_type");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "size"), "set_size", "get_size");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "height"), "set_height", "get_height");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "is_trigger"), "set_is_trigger", "get_is_trigger");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "mesh_index"), "set_mesh_index", "get_mesh_index");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "array_mesh", PROPERTY_HINT_RESOURCE_TYPE, "ArrayMesh"), "set_array_mesh", "get_array_mesh");
|
||||
}
|
||||
|
||||
String GLTFCollider::get_shape_type() const {
|
||||
return shape_type;
|
||||
}
|
||||
|
||||
void GLTFCollider::set_shape_type(String p_shape_type) {
|
||||
shape_type = p_shape_type;
|
||||
}
|
||||
|
||||
Vector3 GLTFCollider::get_size() const {
|
||||
return size;
|
||||
}
|
||||
|
||||
void GLTFCollider::set_size(Vector3 p_size) {
|
||||
size = p_size;
|
||||
}
|
||||
|
||||
real_t GLTFCollider::get_radius() const {
|
||||
return radius;
|
||||
}
|
||||
|
||||
void GLTFCollider::set_radius(real_t p_radius) {
|
||||
radius = p_radius;
|
||||
}
|
||||
|
||||
real_t GLTFCollider::get_height() const {
|
||||
return height;
|
||||
}
|
||||
|
||||
void GLTFCollider::set_height(real_t p_height) {
|
||||
height = p_height;
|
||||
}
|
||||
|
||||
bool GLTFCollider::get_is_trigger() const {
|
||||
return is_trigger;
|
||||
}
|
||||
|
||||
void GLTFCollider::set_is_trigger(bool p_is_trigger) {
|
||||
is_trigger = p_is_trigger;
|
||||
}
|
||||
|
||||
GLTFMeshIndex GLTFCollider::get_mesh_index() const {
|
||||
return mesh_index;
|
||||
}
|
||||
|
||||
void GLTFCollider::set_mesh_index(GLTFMeshIndex p_mesh_index) {
|
||||
mesh_index = p_mesh_index;
|
||||
}
|
||||
|
||||
Ref<ArrayMesh> GLTFCollider::get_array_mesh() const {
|
||||
return array_mesh;
|
||||
}
|
||||
|
||||
void GLTFCollider::set_array_mesh(Ref<ArrayMesh> p_array_mesh) {
|
||||
array_mesh = p_array_mesh;
|
||||
}
|
||||
|
||||
Ref<GLTFCollider> GLTFCollider::from_node(const CollisionShape *p_collider_node) {
|
||||
Ref<GLTFCollider> collider;
|
||||
collider.instance();
|
||||
ERR_FAIL_NULL_V_MSG(p_collider_node, collider, "Tried to create a GLTFCollider from a CollisionShape node, but the given node was null.");
|
||||
Node *parent = p_collider_node->get_parent();
|
||||
if (cast_to<const Area>(parent)) {
|
||||
collider->set_is_trigger(true);
|
||||
}
|
||||
// All the code for working with the shape is below this comment.
|
||||
Ref<Shape> shape = p_collider_node->get_shape();
|
||||
ERR_FAIL_COND_V_MSG(shape.is_null(), collider, "Tried to create a GLTFCollider from a CollisionShape node, but the given node had a null shape.");
|
||||
collider->_shape_cache = shape;
|
||||
if (cast_to<BoxShape>(shape.ptr())) {
|
||||
collider->shape_type = "box";
|
||||
Ref<BoxShape> box = shape;
|
||||
collider->set_size(box->get_extents() * 2.0f);
|
||||
} else if (cast_to<const CapsuleShape>(shape.ptr())) {
|
||||
collider->shape_type = "capsule";
|
||||
Ref<CapsuleShape> capsule = shape;
|
||||
collider->set_radius(capsule->get_radius());
|
||||
collider->set_height(capsule->get_height());
|
||||
} else if (cast_to<const CylinderShape>(shape.ptr())) {
|
||||
collider->shape_type = "cylinder";
|
||||
Ref<CylinderShape> cylinder = shape;
|
||||
collider->set_radius(cylinder->get_radius());
|
||||
collider->set_height(cylinder->get_height());
|
||||
} else if (cast_to<const SphereShape>(shape.ptr())) {
|
||||
collider->shape_type = "sphere";
|
||||
Ref<SphereShape> sphere = shape;
|
||||
collider->set_radius(sphere->get_radius());
|
||||
} else if (cast_to<const ConvexPolygonShape>(shape.ptr())) {
|
||||
collider->shape_type = "hull";
|
||||
Ref<ConvexPolygonShape> convex = shape;
|
||||
PoolVector<Vector3> hull_points = convex->get_points();
|
||||
ERR_FAIL_COND_V_MSG(hull_points.size() < 3, collider, "GLTFCollider: Convex hull has fewer points (" + itos(hull_points.size()) + ") than the minimum of 3. At least 3 points are required in order to save to GLTF, since it uses a mesh to represent convex hulls.");
|
||||
if (hull_points.size() > 255) {
|
||||
WARN_PRINT("GLTFCollider: Convex hull has more points (" + itos(hull_points.size()) + ") than the recommended maximum of 255. This may not load correctly in other engines.");
|
||||
}
|
||||
// Convert the convex hull points into an array of faces.
|
||||
Geometry::MeshData md;
|
||||
Error err = ConvexHullComputer::convex_hull(hull_points, md);
|
||||
ERR_FAIL_COND_V_MSG(err != OK, collider, "GLTFCollider: Failed to compute convex hull.");
|
||||
Vector<Vector3> face_vertices;
|
||||
for (uint32_t i = 0; i < (uint32_t)md.faces.size(); i++) {
|
||||
uint32_t index_count = md.faces[i].indices.size();
|
||||
for (uint32_t j = 1; j < index_count - 1; j++) {
|
||||
face_vertices.push_back(hull_points[md.faces[i].indices[0]]);
|
||||
face_vertices.push_back(hull_points[md.faces[i].indices[j]]);
|
||||
face_vertices.push_back(hull_points[md.faces[i].indices[j + 1]]);
|
||||
}
|
||||
}
|
||||
// Create an ArrayMesh from the faces.
|
||||
Ref<ArrayMesh> array_mesh;
|
||||
array_mesh.instance();
|
||||
Array surface_array;
|
||||
surface_array.resize(Mesh::ArrayType::ARRAY_MAX);
|
||||
surface_array[Mesh::ArrayType::ARRAY_VERTEX] = face_vertices;
|
||||
array_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, surface_array);
|
||||
collider->set_array_mesh(array_mesh);
|
||||
} else if (cast_to<const ConcavePolygonShape>(shape.ptr())) {
|
||||
collider->shape_type = "trimesh";
|
||||
Ref<ConcavePolygonShape> concave = shape;
|
||||
Ref<ArrayMesh> array_mesh;
|
||||
array_mesh.instance();
|
||||
Array surface_array;
|
||||
surface_array.resize(Mesh::ArrayType::ARRAY_MAX);
|
||||
surface_array[Mesh::ArrayType::ARRAY_VERTEX] = concave->get_faces();
|
||||
array_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, surface_array);
|
||||
collider->set_array_mesh(array_mesh);
|
||||
} else {
|
||||
ERR_PRINT("Tried to create a GLTFCollider from a CollisionShape node, but the given node's shape '" + String(Variant(shape)) +
|
||||
"' had an unsupported shape type. Only BoxShape, CapsuleShape, CylinderShape, SphereShape, ConcavePolygonShape, and ConvexPolygonShape are supported.");
|
||||
}
|
||||
return collider;
|
||||
}
|
||||
|
||||
CollisionShape *GLTFCollider::to_node(bool p_cache_shapes) {
|
||||
CollisionShape *collider = memnew(CollisionShape);
|
||||
if (!p_cache_shapes || _shape_cache == nullptr) {
|
||||
if (shape_type == "box") {
|
||||
Ref<BoxShape> box;
|
||||
box.instance();
|
||||
box->set_extents(size * 0.5f);
|
||||
_shape_cache = box;
|
||||
} else if (shape_type == "capsule") {
|
||||
Ref<CapsuleShape> capsule;
|
||||
capsule.instance();
|
||||
capsule->set_radius(radius);
|
||||
capsule->set_height(height);
|
||||
_shape_cache = capsule;
|
||||
} else if (shape_type == "cylinder") {
|
||||
Ref<CylinderShape> cylinder;
|
||||
cylinder.instance();
|
||||
cylinder->set_radius(radius);
|
||||
cylinder->set_height(height);
|
||||
_shape_cache = cylinder;
|
||||
} else if (shape_type == "sphere") {
|
||||
Ref<SphereShape> sphere;
|
||||
sphere.instance();
|
||||
sphere->set_radius(radius);
|
||||
_shape_cache = sphere;
|
||||
} else if (shape_type == "hull") {
|
||||
ERR_FAIL_COND_V_MSG(array_mesh.is_null(), collider, "GLTFCollider: Error converting convex hull collider to a node: The mesh resource is null.");
|
||||
Ref<ConvexPolygonShape> convex = array_mesh->create_convex_shape();
|
||||
_shape_cache = convex;
|
||||
} else if (shape_type == "trimesh") {
|
||||
ERR_FAIL_COND_V_MSG(array_mesh.is_null(), collider, "GLTFCollider: Error converting concave mesh collider to a node: The mesh resource is null.");
|
||||
Ref<ConcavePolygonShape> concave = array_mesh->create_trimesh_shape();
|
||||
_shape_cache = concave;
|
||||
} else {
|
||||
ERR_PRINT("GLTFCollider: Error converting to a node: Shape type '" + shape_type + "' is unknown.");
|
||||
}
|
||||
}
|
||||
collider->set_shape(_shape_cache);
|
||||
return collider;
|
||||
}
|
||||
|
||||
Ref<GLTFCollider> GLTFCollider::from_dictionary(const Dictionary p_dictionary) {
|
||||
ERR_FAIL_COND_V_MSG(!p_dictionary.has("type"), Ref<GLTFCollider>(), "Failed to parse GLTF collider, missing required field 'type'.");
|
||||
Ref<GLTFCollider> collider;
|
||||
collider.instance();
|
||||
const String &shape_type = p_dictionary["type"];
|
||||
collider->shape_type = shape_type;
|
||||
if (shape_type != "box" && shape_type != "capsule" && shape_type != "cylinder" && shape_type != "sphere" && shape_type != "hull" && shape_type != "trimesh") {
|
||||
ERR_PRINT("Error parsing GLTF collider: Shape type '" + shape_type + "' is unknown. Only box, capsule, cylinder, sphere, hull, and trimesh are supported.");
|
||||
}
|
||||
if (p_dictionary.has("radius")) {
|
||||
collider->set_radius(p_dictionary["radius"]);
|
||||
}
|
||||
if (p_dictionary.has("height")) {
|
||||
collider->set_height(p_dictionary["height"]);
|
||||
}
|
||||
if (p_dictionary.has("size")) {
|
||||
const Array &arr = p_dictionary["size"];
|
||||
if (arr.size() == 3) {
|
||||
collider->set_size(Vector3(arr[0], arr[1], arr[2]));
|
||||
} else {
|
||||
ERR_PRINT("Error parsing GLTF collider: The size must have exactly 3 numbers.");
|
||||
}
|
||||
}
|
||||
if (p_dictionary.has("isTrigger")) {
|
||||
collider->set_is_trigger(p_dictionary["isTrigger"]);
|
||||
}
|
||||
if (p_dictionary.has("mesh")) {
|
||||
collider->set_mesh_index(p_dictionary["mesh"]);
|
||||
}
|
||||
if (unlikely(collider->get_mesh_index() < 0 && (shape_type == "hull" || shape_type == "trimesh"))) {
|
||||
ERR_PRINT("Error parsing GLTF collider: The mesh-based shape type '" + shape_type + "' does not have a valid mesh index.");
|
||||
}
|
||||
return collider;
|
||||
}
|
||||
|
||||
Dictionary GLTFCollider::to_dictionary() const {
|
||||
Dictionary d;
|
||||
d["type"] = shape_type;
|
||||
if (shape_type == "box") {
|
||||
Array size_array;
|
||||
size_array.resize(3);
|
||||
size_array[0] = size.x;
|
||||
size_array[1] = size.y;
|
||||
size_array[2] = size.z;
|
||||
d["size"] = size_array;
|
||||
} else if (shape_type == "capsule") {
|
||||
d["radius"] = get_radius();
|
||||
d["height"] = get_height();
|
||||
} else if (shape_type == "cylinder") {
|
||||
d["radius"] = get_radius();
|
||||
d["height"] = get_height();
|
||||
} else if (shape_type == "sphere") {
|
||||
d["radius"] = get_radius();
|
||||
} else if (shape_type == "trimesh" || shape_type == "hull") {
|
||||
d["mesh"] = get_mesh_index();
|
||||
}
|
||||
if (is_trigger) {
|
||||
d["isTrigger"] = is_trigger;
|
||||
}
|
||||
return d;
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* gltf_collider.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef GLTF_COLLIDER_H
|
||||
#define GLTF_COLLIDER_H
|
||||
|
||||
#include "../../gltf_defines.h"
|
||||
#include "scene/3d/collision_shape.h"
|
||||
|
||||
class GLTFState;
|
||||
|
||||
// GLTFCollider is an intermediary between OMI_collider and Godot's collision shape nodes.
|
||||
// https://github.com/omigroup/gltf-extensions/tree/main/extensions/2.0/OMI_collider
|
||||
|
||||
class GLTFCollider : public Resource {
|
||||
GDCLASS(GLTFCollider, Resource)
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
String shape_type;
|
||||
Vector3 size = Vector3(1.0, 1.0, 1.0);
|
||||
real_t radius = 0.5;
|
||||
real_t height = 2.0;
|
||||
bool is_trigger = false;
|
||||
GLTFMeshIndex mesh_index = -1;
|
||||
Ref<ArrayMesh> array_mesh = nullptr;
|
||||
// Internal only, for caching Godot shape resources. Used in `to_node`.
|
||||
Ref<Shape> _shape_cache = nullptr;
|
||||
|
||||
public:
|
||||
String get_shape_type() const;
|
||||
void set_shape_type(String p_shape_type);
|
||||
|
||||
Vector3 get_size() const;
|
||||
void set_size(Vector3 p_size);
|
||||
|
||||
real_t get_radius() const;
|
||||
void set_radius(real_t p_radius);
|
||||
|
||||
real_t get_height() const;
|
||||
void set_height(real_t p_height);
|
||||
|
||||
bool get_is_trigger() const;
|
||||
void set_is_trigger(bool p_is_trigger);
|
||||
|
||||
GLTFMeshIndex get_mesh_index() const;
|
||||
void set_mesh_index(GLTFMeshIndex p_mesh_index);
|
||||
|
||||
Ref<ArrayMesh> get_array_mesh() const;
|
||||
void set_array_mesh(Ref<ArrayMesh> p_array_mesh);
|
||||
|
||||
static Ref<GLTFCollider> from_node(const CollisionShape *p_collider_node);
|
||||
CollisionShape *to_node(bool p_cache_shapes = false);
|
||||
|
||||
static Ref<GLTFCollider> from_dictionary(const Dictionary p_dictionary);
|
||||
Dictionary to_dictionary() const;
|
||||
};
|
||||
|
||||
#endif // GLTF_COLLIDER_H
|
@ -1,274 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* gltf_document_extension_physics.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "gltf_document_extension_physics.h"
|
||||
|
||||
#include "scene/3d/area.h"
|
||||
|
||||
// Import process.
|
||||
Error GLTFDocumentExtensionPhysics::import_preflight(Ref<GLTFState> p_state, Vector<String> p_extensions) {
|
||||
if (p_extensions.find("OMI_collider") < 0 && p_extensions.find("OMI_physics_body") < 0) {
|
||||
return ERR_SKIP;
|
||||
}
|
||||
Dictionary state_json = p_state->get_json();
|
||||
if (state_json.has("extensions")) {
|
||||
Dictionary state_extensions = state_json["extensions"];
|
||||
if (state_extensions.has("OMI_collider")) {
|
||||
Dictionary omi_collider_ext = state_extensions["OMI_collider"];
|
||||
if (omi_collider_ext.has("colliders")) {
|
||||
Array state_collider_dicts = omi_collider_ext["colliders"];
|
||||
if (state_collider_dicts.size() > 0) {
|
||||
Array state_colliders;
|
||||
for (int i = 0; i < state_collider_dicts.size(); i++) {
|
||||
state_colliders.push_back(GLTFCollider::from_dictionary(state_collider_dicts[i]));
|
||||
}
|
||||
p_state->set_additional_data("GLTFColliders", state_colliders);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
Vector<String> GLTFDocumentExtensionPhysics::get_supported_extensions() {
|
||||
Vector<String> ret;
|
||||
ret.push_back("OMI_collider");
|
||||
ret.push_back("OMI_physics_body");
|
||||
return ret;
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtensionPhysics::parse_node_extensions(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &p_extensions) {
|
||||
if (p_extensions.has("OMI_collider")) {
|
||||
Dictionary node_collider_ext = p_extensions["OMI_collider"];
|
||||
if (node_collider_ext.has("collider")) {
|
||||
// "collider" is the index of the collider in the state colliders array.
|
||||
int node_collider_index = node_collider_ext["collider"];
|
||||
Array state_colliders = p_state->get_additional_data("GLTFColliders");
|
||||
ERR_FAIL_INDEX_V_MSG(node_collider_index, state_colliders.size(), Error::ERR_FILE_CORRUPT, "GLTF Physics: On node " + p_gltf_node->get_name() + ", the collider index " + itos(node_collider_index) + " is not in the state colliders (size: " + itos(state_colliders.size()) + ").");
|
||||
p_gltf_node->set_additional_data("GLTFCollider", state_colliders[node_collider_index]);
|
||||
} else {
|
||||
p_gltf_node->set_additional_data("GLTFCollider", GLTFCollider::from_dictionary(p_extensions["OMI_collider"]));
|
||||
}
|
||||
}
|
||||
if (p_extensions.has("OMI_physics_body")) {
|
||||
p_gltf_node->set_additional_data("GLTFPhysicsBody", GLTFPhysicsBody::from_dictionary(p_extensions["OMI_physics_body"]));
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
void _setup_collider_mesh_resource_from_index_if_needed(Ref<GLTFState> p_state, Ref<GLTFCollider> p_collider) {
|
||||
GLTFMeshIndex collider_mesh_index = p_collider->get_mesh_index();
|
||||
if (collider_mesh_index == -1) {
|
||||
return; // No mesh for this collider.
|
||||
}
|
||||
Ref<ArrayMesh> array_mesh = p_collider->get_array_mesh();
|
||||
if (array_mesh.is_valid()) {
|
||||
return; // The mesh resource is already set up.
|
||||
}
|
||||
Array state_meshes = p_state->get_meshes();
|
||||
ERR_FAIL_INDEX_MSG(collider_mesh_index, state_meshes.size(), "GLTF Physics: When importing '" + p_state->get_scene_name() + "', the collider mesh index " + itos(collider_mesh_index) + " is not in the state meshes (size: " + itos(state_meshes.size()) + ").");
|
||||
Ref<GLTFMesh> gltf_mesh = state_meshes[collider_mesh_index];
|
||||
ERR_FAIL_COND(gltf_mesh.is_null());
|
||||
array_mesh = gltf_mesh->get_mesh();
|
||||
ERR_FAIL_COND(array_mesh.is_null());
|
||||
p_collider->set_array_mesh(array_mesh);
|
||||
}
|
||||
|
||||
CollisionObject *_generate_collision_with_body(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Ref<GLTFCollider> p_collider, Ref<GLTFPhysicsBody> p_physics_body) {
|
||||
print_verbose("glTF: Creating collision for: " + p_gltf_node->get_name());
|
||||
bool is_trigger = p_collider->get_is_trigger();
|
||||
// This method is used for the case where we must generate a parent body.
|
||||
// This is can happen for multiple reasons. One possibility is that this
|
||||
// GLTF file is using OMI_collider but not OMI_physics_body, or at least
|
||||
// this particular node is not using it. Another possibility is that the
|
||||
// physics body information is set up on the same GLTF node, not a parent.
|
||||
CollisionObject *body;
|
||||
if (p_physics_body.is_valid()) {
|
||||
// This code is run when the physics body is on the same GLTF node.
|
||||
body = p_physics_body->to_node();
|
||||
if (is_trigger != (p_physics_body->get_body_type() == "trigger")) {
|
||||
// Edge case: If the body's trigger and the collider's trigger
|
||||
// are in disagreement, we need to create another new body.
|
||||
CollisionObject *child = _generate_collision_with_body(p_state, p_gltf_node, p_collider, nullptr);
|
||||
child->set_name(p_gltf_node->get_name() + (is_trigger ? String("Trigger") : String("Solid")));
|
||||
body->add_child(child);
|
||||
return body;
|
||||
}
|
||||
} else if (is_trigger) {
|
||||
body = memnew(Area);
|
||||
} else {
|
||||
body = memnew(StaticBody);
|
||||
}
|
||||
CollisionShape *shape = p_collider->to_node();
|
||||
shape->set_name(p_gltf_node->get_name() + "Shape");
|
||||
body->add_child(shape);
|
||||
return body;
|
||||
}
|
||||
|
||||
Spatial *GLTFDocumentExtensionPhysics::generate_scene_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Node *p_scene_parent) {
|
||||
Ref<GLTFPhysicsBody> physics_body = p_gltf_node->get_additional_data("GLTFPhysicsBody");
|
||||
Ref<GLTFCollider> collider = p_gltf_node->get_additional_data("GLTFCollider");
|
||||
if (collider.is_valid()) {
|
||||
_setup_collider_mesh_resource_from_index_if_needed(p_state, collider);
|
||||
// If the collider has the correct type of parent, we just return one node.
|
||||
if (collider->get_is_trigger()) {
|
||||
if (Object::cast_to<Area>(p_scene_parent)) {
|
||||
return collider->to_node(true);
|
||||
}
|
||||
} else {
|
||||
if (Object::cast_to<PhysicsBody>(p_scene_parent)) {
|
||||
return collider->to_node(true);
|
||||
}
|
||||
}
|
||||
return _generate_collision_with_body(p_state, p_gltf_node, collider, physics_body);
|
||||
}
|
||||
if (physics_body.is_valid()) {
|
||||
return physics_body->to_node();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Export process.
|
||||
bool _are_all_faces_equal(const PoolVector<Face3> &p_a, const PoolVector<Face3> &p_b) {
|
||||
if (p_a.size() != p_b.size()) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < p_a.size(); i++) {
|
||||
Face3 a_face = p_a[i];
|
||||
Face3 b_face = p_b[i];
|
||||
const Vector3 *a_vertices = a_face.vertex;
|
||||
const Vector3 *b_vertices = b_face.vertex;
|
||||
for (int j = 0; j < 3; j++) {
|
||||
if (!a_vertices[j].is_equal_approx(b_vertices[j])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
GLTFMeshIndex _get_or_insert_mesh_in_state(Ref<GLTFState> p_state, Ref<ArrayMesh> p_mesh) {
|
||||
ERR_FAIL_COND_V(p_mesh.is_null(), -1);
|
||||
Array state_meshes = p_state->get_meshes();
|
||||
PoolVector<Face3> mesh_faces = p_mesh->get_faces();
|
||||
// De-duplication: If the state already has the mesh we need, use that one.
|
||||
for (GLTFMeshIndex i = 0; i < state_meshes.size(); i++) {
|
||||
Ref<GLTFMesh> state_gltf_mesh = state_meshes[i];
|
||||
ERR_CONTINUE(state_gltf_mesh.is_null());
|
||||
Ref<ArrayMesh> state_array_mesh = state_gltf_mesh->get_mesh();
|
||||
ERR_CONTINUE(state_array_mesh.is_null());
|
||||
if (state_array_mesh == p_mesh) {
|
||||
return i;
|
||||
}
|
||||
if (_are_all_faces_equal(state_array_mesh->get_faces(), mesh_faces)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
// After the loop, we have checked that the mesh is not equal to any of the
|
||||
// meshes in the state. So we insert a new mesh into the state mesh array.
|
||||
Ref<GLTFMesh> gltf_mesh;
|
||||
gltf_mesh.instance();
|
||||
gltf_mesh->set_mesh(p_mesh);
|
||||
GLTFMeshIndex mesh_index = state_meshes.size();
|
||||
state_meshes.push_back(gltf_mesh);
|
||||
p_state->set_meshes(state_meshes);
|
||||
return mesh_index;
|
||||
}
|
||||
|
||||
void GLTFDocumentExtensionPhysics::convert_scene_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Node *p_scene_node) {
|
||||
if (cast_to<CollisionShape>(p_scene_node)) {
|
||||
CollisionShape *shape = Object::cast_to<CollisionShape>(p_scene_node);
|
||||
Ref<GLTFCollider> collider = GLTFCollider::from_node(shape);
|
||||
{
|
||||
Ref<ArrayMesh> array_mesh = collider->get_array_mesh();
|
||||
if (array_mesh.is_valid()) {
|
||||
collider->set_mesh_index(_get_or_insert_mesh_in_state(p_state, array_mesh));
|
||||
}
|
||||
}
|
||||
p_gltf_node->set_additional_data("GLTFCollider", collider);
|
||||
} else if (cast_to<CollisionObject>(p_scene_node)) {
|
||||
CollisionObject *body = Object::cast_to<CollisionObject>(p_scene_node);
|
||||
p_gltf_node->set_additional_data("GLTFPhysicsBody", GLTFPhysicsBody::from_node(body));
|
||||
}
|
||||
}
|
||||
|
||||
Array _get_or_create_state_colliders_in_state(Ref<GLTFState> p_state) {
|
||||
Dictionary state_json = p_state->get_json();
|
||||
Dictionary state_extensions;
|
||||
if (state_json.has("extensions")) {
|
||||
state_extensions = state_json["extensions"];
|
||||
} else {
|
||||
state_json["extensions"] = state_extensions;
|
||||
}
|
||||
Dictionary omi_collider_ext;
|
||||
if (state_extensions.has("OMI_collider")) {
|
||||
omi_collider_ext = state_extensions["OMI_collider"];
|
||||
} else {
|
||||
state_extensions["OMI_collider"] = omi_collider_ext;
|
||||
p_state->add_used_extension("OMI_collider");
|
||||
}
|
||||
Array state_colliders;
|
||||
if (omi_collider_ext.has("colliders")) {
|
||||
state_colliders = omi_collider_ext["colliders"];
|
||||
} else {
|
||||
omi_collider_ext["colliders"] = state_colliders;
|
||||
}
|
||||
return state_colliders;
|
||||
}
|
||||
|
||||
Error GLTFDocumentExtensionPhysics::export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_node_json, Node *p_node) {
|
||||
Dictionary node_extensions = r_node_json["extensions"];
|
||||
Ref<GLTFPhysicsBody> physics_body = p_gltf_node->get_additional_data("GLTFPhysicsBody");
|
||||
if (physics_body.is_valid()) {
|
||||
node_extensions["OMI_physics_body"] = physics_body->to_dictionary();
|
||||
p_state->add_used_extension("OMI_physics_body");
|
||||
}
|
||||
Ref<GLTFCollider> collider = p_gltf_node->get_additional_data("GLTFCollider");
|
||||
if (collider.is_valid()) {
|
||||
Array state_colliders = _get_or_create_state_colliders_in_state(p_state);
|
||||
int size = state_colliders.size();
|
||||
Dictionary omi_collider_ext;
|
||||
node_extensions["OMI_collider"] = omi_collider_ext;
|
||||
Dictionary collider_dict = collider->to_dictionary();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Dictionary other = state_colliders[i];
|
||||
if (other == collider_dict) {
|
||||
// De-duplication: If we already have an identical collider,
|
||||
// set the collider index to the existing one and return.
|
||||
omi_collider_ext["collider"] = i;
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
// If we don't have an identical collider, add it to the array.
|
||||
state_colliders.push_back(collider_dict);
|
||||
omi_collider_ext["collider"] = size;
|
||||
}
|
||||
return OK;
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* gltf_document_extension_physics.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef GLTF_DOCUMENT_EXTENSION_PHYSICS_H
|
||||
#define GLTF_DOCUMENT_EXTENSION_PHYSICS_H
|
||||
|
||||
#include "../gltf_document_extension.h"
|
||||
|
||||
#include "gltf_collider.h"
|
||||
#include "gltf_physics_body.h"
|
||||
|
||||
class GLTFDocumentExtensionPhysics : public GLTFDocumentExtension {
|
||||
GDCLASS(GLTFDocumentExtensionPhysics, GLTFDocumentExtension);
|
||||
|
||||
public:
|
||||
// Import process.
|
||||
Error import_preflight(Ref<GLTFState> p_state, Vector<String> p_extensions);
|
||||
Vector<String> get_supported_extensions();
|
||||
Error parse_node_extensions(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &p_extensions);
|
||||
Spatial *generate_scene_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Node *p_scene_parent);
|
||||
// Export process.
|
||||
void convert_scene_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Node *p_scene_node);
|
||||
Error export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_node_json, Node *p_scene_node);
|
||||
};
|
||||
|
||||
#endif // GLTF_DOCUMENT_EXTENSION_PHYSICS_H
|
@ -1,196 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* gltf_physics_body.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "gltf_physics_body.h"
|
||||
|
||||
#include "scene/3d/area.h"
|
||||
#include "scene/3d/vehicle_body.h"
|
||||
|
||||
void GLTFPhysicsBody::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("to_node"), &GLTFPhysicsBody::to_node);
|
||||
ClassDB::bind_method(D_METHOD("to_dictionary"), &GLTFPhysicsBody::to_dictionary);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_body_type"), &GLTFPhysicsBody::get_body_type);
|
||||
ClassDB::bind_method(D_METHOD("set_body_type", "body_type"), &GLTFPhysicsBody::set_body_type);
|
||||
ClassDB::bind_method(D_METHOD("get_mass"), &GLTFPhysicsBody::get_mass);
|
||||
ClassDB::bind_method(D_METHOD("set_mass", "mass"), &GLTFPhysicsBody::set_mass);
|
||||
ClassDB::bind_method(D_METHOD("get_linear_velocity"), &GLTFPhysicsBody::get_linear_velocity);
|
||||
ClassDB::bind_method(D_METHOD("set_linear_velocity", "linear_velocity"), &GLTFPhysicsBody::set_linear_velocity);
|
||||
ClassDB::bind_method(D_METHOD("get_angular_velocity"), &GLTFPhysicsBody::get_angular_velocity);
|
||||
ClassDB::bind_method(D_METHOD("set_angular_velocity", "angular_velocity"), &GLTFPhysicsBody::set_angular_velocity);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "body_type"), "set_body_type", "get_body_type");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "mass"), "set_mass", "get_mass");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "linear_velocity"), "set_linear_velocity", "get_linear_velocity");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "angular_velocity"), "set_angular_velocity", "get_angular_velocity");
|
||||
}
|
||||
|
||||
String GLTFPhysicsBody::get_body_type() const {
|
||||
return body_type;
|
||||
}
|
||||
|
||||
void GLTFPhysicsBody::set_body_type(String p_body_type) {
|
||||
body_type = p_body_type;
|
||||
}
|
||||
|
||||
real_t GLTFPhysicsBody::get_mass() const {
|
||||
return mass;
|
||||
}
|
||||
|
||||
void GLTFPhysicsBody::set_mass(real_t p_mass) {
|
||||
mass = p_mass;
|
||||
}
|
||||
|
||||
Vector3 GLTFPhysicsBody::get_linear_velocity() const {
|
||||
return linear_velocity;
|
||||
}
|
||||
|
||||
void GLTFPhysicsBody::set_linear_velocity(Vector3 p_linear_velocity) {
|
||||
linear_velocity = p_linear_velocity;
|
||||
}
|
||||
|
||||
Vector3 GLTFPhysicsBody::get_angular_velocity() const {
|
||||
return angular_velocity;
|
||||
}
|
||||
|
||||
void GLTFPhysicsBody::set_angular_velocity(Vector3 p_angular_velocity) {
|
||||
angular_velocity = p_angular_velocity;
|
||||
}
|
||||
|
||||
Ref<GLTFPhysicsBody> GLTFPhysicsBody::from_node(const CollisionObject *p_body_node) {
|
||||
Ref<GLTFPhysicsBody> physics_body;
|
||||
physics_body.instance();
|
||||
ERR_FAIL_COND_V_MSG(!p_body_node, physics_body, "Tried to create a GLTFPhysicsBody from a CollisionObject node, but the given node was null.");
|
||||
if (cast_to<KinematicBody>(p_body_node)) {
|
||||
physics_body->body_type = "kinematic";
|
||||
} else if (cast_to<RigidBody>(p_body_node)) {
|
||||
const RigidBody *body = cast_to<const RigidBody>(p_body_node);
|
||||
physics_body->mass = body->get_mass();
|
||||
physics_body->linear_velocity = body->get_linear_velocity();
|
||||
physics_body->angular_velocity = body->get_angular_velocity();
|
||||
if (cast_to<VehicleBody>(p_body_node)) {
|
||||
physics_body->body_type = "vehicle";
|
||||
} else {
|
||||
physics_body->body_type = "rigid";
|
||||
}
|
||||
} else if (cast_to<StaticBody>(p_body_node)) {
|
||||
physics_body->body_type = "static";
|
||||
} else if (cast_to<Area>(p_body_node)) {
|
||||
physics_body->body_type = "trigger";
|
||||
}
|
||||
return physics_body;
|
||||
}
|
||||
|
||||
CollisionObject *GLTFPhysicsBody::to_node() const {
|
||||
if (body_type == "character" || body_type == "kinematic") {
|
||||
KinematicBody *body = memnew(KinematicBody);
|
||||
return body;
|
||||
}
|
||||
if (body_type == "vehicle") {
|
||||
VehicleBody *body = memnew(VehicleBody);
|
||||
body->set_mass(mass);
|
||||
body->set_linear_velocity(linear_velocity);
|
||||
body->set_angular_velocity(angular_velocity);
|
||||
return body;
|
||||
}
|
||||
if (body_type == "rigid") {
|
||||
RigidBody *body = memnew(RigidBody);
|
||||
body->set_mass(mass);
|
||||
body->set_linear_velocity(linear_velocity);
|
||||
body->set_angular_velocity(angular_velocity);
|
||||
return body;
|
||||
}
|
||||
if (body_type == "static") {
|
||||
StaticBody *body = memnew(StaticBody);
|
||||
return body;
|
||||
}
|
||||
if (body_type == "trigger") {
|
||||
Area *body = memnew(Area);
|
||||
return body;
|
||||
}
|
||||
ERR_FAIL_V_MSG(nullptr, "Error converting GLTFPhysicsBody to a node: Body type '" + body_type + "' is unknown.");
|
||||
}
|
||||
|
||||
Ref<GLTFPhysicsBody> GLTFPhysicsBody::from_dictionary(const Dictionary p_dictionary) {
|
||||
Ref<GLTFPhysicsBody> physics_body;
|
||||
physics_body.instance();
|
||||
ERR_FAIL_COND_V_MSG(!p_dictionary.has("type"), physics_body, "Failed to parse GLTF physics body, missing required field 'type'.");
|
||||
const String &body_type = p_dictionary["type"];
|
||||
physics_body->body_type = body_type;
|
||||
|
||||
if (p_dictionary.has("mass")) {
|
||||
physics_body->mass = p_dictionary["mass"];
|
||||
}
|
||||
if (p_dictionary.has("linearVelocity")) {
|
||||
const Array &arr = p_dictionary["linearVelocity"];
|
||||
if (arr.size() == 3) {
|
||||
physics_body->set_linear_velocity(Vector3(arr[0], arr[1], arr[2]));
|
||||
} else {
|
||||
ERR_PRINT("Error parsing GLTF physics body: The linear velocity vector must have exactly 3 numbers.");
|
||||
}
|
||||
}
|
||||
if (p_dictionary.has("angularVelocity")) {
|
||||
const Array &arr = p_dictionary["angularVelocity"];
|
||||
if (arr.size() == 3) {
|
||||
physics_body->set_angular_velocity(Vector3(arr[0], arr[1], arr[2]));
|
||||
} else {
|
||||
ERR_PRINT("Error parsing GLTF physics body: The angular velocity vector must have exactly 3 numbers.");
|
||||
}
|
||||
}
|
||||
if (body_type != "character" && body_type != "kinematic" && body_type != "rigid" && body_type != "static" && body_type != "trigger" && body_type != "vehicle") {
|
||||
ERR_PRINT("Error parsing GLTF physics body: Body type '" + body_type + "' is unknown.");
|
||||
}
|
||||
return physics_body;
|
||||
}
|
||||
|
||||
Dictionary GLTFPhysicsBody::to_dictionary() const {
|
||||
Dictionary d;
|
||||
d["type"] = body_type;
|
||||
if (mass != 1.0) {
|
||||
d["mass"] = mass;
|
||||
}
|
||||
if (linear_velocity != Vector3()) {
|
||||
Array velocity_array;
|
||||
velocity_array.resize(3);
|
||||
velocity_array[0] = linear_velocity.x;
|
||||
velocity_array[1] = linear_velocity.y;
|
||||
velocity_array[2] = linear_velocity.z;
|
||||
d["linearVelocity"] = velocity_array;
|
||||
}
|
||||
if (angular_velocity != Vector3()) {
|
||||
Array velocity_array;
|
||||
velocity_array.resize(3);
|
||||
velocity_array[0] = angular_velocity.x;
|
||||
velocity_array[1] = angular_velocity.y;
|
||||
velocity_array[2] = angular_velocity.z;
|
||||
d["angularVelocity"] = velocity_array;
|
||||
}
|
||||
return d;
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* gltf_physics_body.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef GLTF_PHYSICS_BODY_H
|
||||
#define GLTF_PHYSICS_BODY_H
|
||||
|
||||
#include "scene/3d/physics_body.h"
|
||||
|
||||
// GLTFPhysicsBody is an intermediary between OMI_physics_body and Godot's physics body nodes.
|
||||
// https://github.com/omigroup/gltf-extensions/tree/main/extensions/2.0/OMI_physics_body
|
||||
|
||||
class GLTFPhysicsBody : public Resource {
|
||||
GDCLASS(GLTFPhysicsBody, Resource)
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
String body_type = "static";
|
||||
real_t mass = 1.0;
|
||||
Vector3 linear_velocity = Vector3();
|
||||
Vector3 angular_velocity = Vector3();
|
||||
|
||||
public:
|
||||
String get_body_type() const;
|
||||
void set_body_type(String p_body_type);
|
||||
|
||||
real_t get_mass() const;
|
||||
void set_mass(real_t p_mass);
|
||||
|
||||
Vector3 get_linear_velocity() const;
|
||||
void set_linear_velocity(Vector3 p_linear_velocity);
|
||||
|
||||
Vector3 get_angular_velocity() const;
|
||||
void set_angular_velocity(Vector3 p_angular_velocity);
|
||||
|
||||
static Ref<GLTFPhysicsBody> from_node(const CollisionObject *p_body_node);
|
||||
CollisionObject *to_node() const;
|
||||
|
||||
static Ref<GLTFPhysicsBody> from_dictionary(const Dictionary p_dictionary);
|
||||
Dictionary to_dictionary() const;
|
||||
};
|
||||
|
||||
#endif // GLTF_PHYSICS_BODY_H
|
@ -1,91 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_defines.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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_DEFINES_H
|
||||
#define GLTF_DEFINES_H
|
||||
|
||||
// This file should only be included by other headers.
|
||||
|
||||
// Godot classes used by GLTF headers.
|
||||
class AnimationPlayer;
|
||||
class BoneAttachment;
|
||||
class CSGShape;
|
||||
class DirectionalLight;
|
||||
class GridMap;
|
||||
class Light;
|
||||
class MultiMeshInstance;
|
||||
class Skeleton;
|
||||
class Skin;
|
||||
|
||||
// GLTF classes.
|
||||
struct GLTFAccessor;
|
||||
class GLTFAnimation;
|
||||
class GLTFBufferView;
|
||||
class GLTFCamera;
|
||||
class GLTFDocument;
|
||||
class GLTFDocumentExtension;
|
||||
class GLTFLight;
|
||||
class GLTFMesh;
|
||||
class GLTFNode;
|
||||
class GLTFSkeleton;
|
||||
class GLTFSkin;
|
||||
class GLTFSpecGloss;
|
||||
class GLTFState;
|
||||
class GLTFTexture;
|
||||
class GLTFTextureSampler;
|
||||
class PackedSceneGLTF;
|
||||
|
||||
// GLTF index aliases.
|
||||
using GLTFAccessorIndex = int;
|
||||
using GLTFAnimationIndex = int;
|
||||
using GLTFBufferIndex = int;
|
||||
using GLTFBufferViewIndex = int;
|
||||
using GLTFCameraIndex = int;
|
||||
using GLTFImageIndex = int;
|
||||
using GLTFLightIndex = int;
|
||||
using GLTFMaterialIndex = int;
|
||||
using GLTFMeshIndex = int;
|
||||
using GLTFNodeIndex = int;
|
||||
using GLTFSkeletonIndex = int;
|
||||
using GLTFSkinIndex = int;
|
||||
using GLTFTextureIndex = int;
|
||||
using GLTFTextureSamplerIndex = int;
|
||||
|
||||
enum GLTFType {
|
||||
TYPE_SCALAR,
|
||||
TYPE_VEC2,
|
||||
TYPE_VEC3,
|
||||
TYPE_VEC4,
|
||||
TYPE_MAT2,
|
||||
TYPE_MAT3,
|
||||
TYPE_MAT4,
|
||||
};
|
||||
|
||||
#endif // GLTF_DEFINES_H
|
File diff suppressed because it is too large
Load Diff
@ -1,395 +0,0 @@
|
||||
#ifndef GLTF_DOCUMENT_H
|
||||
#define GLTF_DOCUMENT_H
|
||||
/*************************************************************************/
|
||||
/* gltf_document.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/3d/camera.h"
|
||||
#include "scene/3d/light.h"
|
||||
#include "scene/3d/mesh_instance.h"
|
||||
#include "scene/main/spatial.h"
|
||||
#include "scene/animation/animation_player.h"
|
||||
#include "scene/resources/material/material.h"
|
||||
#include "scene/resources/material/spatial_material.h"
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
#include "extensions/gltf_document_extension.h"
|
||||
#include "gltf_defines.h"
|
||||
#include "structures/gltf_animation.h"
|
||||
|
||||
#include "modules/modules_enabled.gen.h" // For csg, gridmap.
|
||||
|
||||
#ifdef MODULE_SKELETON_3D_ENABLED
|
||||
class Skeleton;
|
||||
class BoneAttachment;
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_CSG_ENABLED
|
||||
class CSGShape;
|
||||
#endif // MODULE_CSG_ENABLED
|
||||
|
||||
#ifdef MODULE_GRIDMAP_ENABLED
|
||||
class GridMap;
|
||||
#endif // MODULE_GRIDMAP_ENABLED
|
||||
|
||||
class GLTFDocument : public Resource {
|
||||
GDCLASS(GLTFDocument, Resource);
|
||||
|
||||
private:
|
||||
static Vector<Ref<GLTFDocumentExtension>> all_document_extensions;
|
||||
Vector<Ref<GLTFDocumentExtension>> document_extensions;
|
||||
|
||||
const float BAKE_FPS = 30.0f;
|
||||
|
||||
public:
|
||||
const int32_t JOINT_GROUP_SIZE = 4;
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void _register_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension, bool p_first_priority = false);
|
||||
void _unregister_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension);
|
||||
void _unregister_all_gltf_document_extensions();
|
||||
static void register_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension, bool p_first_priority = false);
|
||||
static void unregister_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension);
|
||||
static void unregister_all_gltf_document_extensions();
|
||||
|
||||
private:
|
||||
double _filter_number(double p_float);
|
||||
String _get_component_type_name(const uint32_t p_component);
|
||||
int _get_component_type_size(const int p_component_type);
|
||||
Error _parse_scenes(Ref<GLTFState> p_state);
|
||||
Error _parse_nodes(Ref<GLTFState> p_state);
|
||||
String _get_type_name(const GLTFType p_component);
|
||||
String _get_accessor_type_name(const GLTFType p_type);
|
||||
String _gen_unique_name(Ref<GLTFState> p_state, const String &p_name);
|
||||
String _sanitize_animation_name(const String &p_name);
|
||||
String _gen_unique_animation_name(Ref<GLTFState> p_state, const String &p_name);
|
||||
String _sanitize_bone_name(Ref<GLTFState> p_state, const String &p_name);
|
||||
String _gen_unique_bone_name(Ref<GLTFState> p_state,
|
||||
const GLTFSkeletonIndex skel_i,
|
||||
const String &p_name);
|
||||
GLTFTextureIndex _set_texture(Ref<GLTFState> p_state, Ref<Texture> p_texture);
|
||||
Ref<Texture> _get_texture(Ref<GLTFState> p_state,
|
||||
const GLTFTextureIndex p_texture);
|
||||
GLTFTextureSamplerIndex _set_sampler_for_mode(Ref<GLTFState> p_state,
|
||||
uint32_t p_mode);
|
||||
Ref<GLTFTextureSampler> _get_sampler_for_texture(Ref<GLTFState> p_state,
|
||||
const GLTFTextureIndex p_texture);
|
||||
Error _parse_json(const String &p_path, Ref<GLTFState> p_state);
|
||||
Error _parse_glb(const String &p_path, Ref<GLTFState> p_state);
|
||||
void _compute_node_heights(Ref<GLTFState> p_state);
|
||||
Error _parse_buffers(Ref<GLTFState> p_state, const String &p_base_path);
|
||||
Error _parse_buffer_views(Ref<GLTFState> p_state);
|
||||
GLTFType _get_type_from_str(const String &p_string);
|
||||
Error _parse_accessors(Ref<GLTFState> p_state);
|
||||
Error _decode_buffer_view(Ref<GLTFState> p_state, double *p_dst,
|
||||
const GLTFBufferViewIndex p_buffer_view,
|
||||
const int p_skip_every, const int p_skip_bytes,
|
||||
const int p_element_size, const int p_count,
|
||||
const GLTFType p_type, const int p_component_count,
|
||||
const int p_component_type, const int p_component_size,
|
||||
const bool p_normalized, const int p_byte_offset,
|
||||
const bool p_for_vertex);
|
||||
Vector<double> _decode_accessor(Ref<GLTFState> p_state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<float> _decode_accessor_as_floats(Ref<GLTFState> p_state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<int> _decode_accessor_as_ints(Ref<GLTFState> p_state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<Vector2> _decode_accessor_as_vec2(Ref<GLTFState> p_state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<Vector3> _decode_accessor_as_vec3(Ref<GLTFState> p_state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<Color> _decode_accessor_as_color(Ref<GLTFState> p_state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<Quaternion> _decode_accessor_as_quat(Ref<GLTFState> p_state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<Transform2D> _decode_accessor_as_xform2d(Ref<GLTFState> p_state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<Basis> _decode_accessor_as_basis(Ref<GLTFState> p_state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Vector<Transform> _decode_accessor_as_xform(Ref<GLTFState> p_state,
|
||||
const GLTFAccessorIndex p_accessor,
|
||||
const bool p_for_vertex);
|
||||
Error _parse_meshes(Ref<GLTFState> p_state);
|
||||
Error _serialize_textures(Ref<GLTFState> p_state);
|
||||
Error _serialize_texture_samplers(Ref<GLTFState> p_state);
|
||||
Error _serialize_images(Ref<GLTFState> p_state, const String &p_path);
|
||||
Error _serialize_lights(Ref<GLTFState> p_state);
|
||||
Error _parse_images(Ref<GLTFState> p_state, const String &p_base_path);
|
||||
Error _parse_textures(Ref<GLTFState> p_state);
|
||||
Error _parse_texture_samplers(Ref<GLTFState> p_state);
|
||||
Error _parse_materials(Ref<GLTFState> p_state);
|
||||
void _set_texture_transform_uv1(const Dictionary &p_d, Ref<SpatialMaterial> p_material);
|
||||
void spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> p_r_spec_gloss,
|
||||
Ref<SpatialMaterial> p_material);
|
||||
static void spec_gloss_to_metal_base_color(const Color &p_specular_factor,
|
||||
const Color &p_diffuse,
|
||||
Color &p_r_base_color,
|
||||
float &p_r_metallic);
|
||||
GLTFNodeIndex _find_highest_node(Ref<GLTFState> p_state,
|
||||
const Vector<GLTFNodeIndex> &p_subset);
|
||||
bool _capture_nodes_in_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin,
|
||||
const GLTFNodeIndex p_node_index);
|
||||
void _capture_nodes_for_multirooted_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin);
|
||||
Error _expand_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin);
|
||||
Error _verify_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin);
|
||||
Error _parse_skins(Ref<GLTFState> p_state);
|
||||
Error _determine_skeletons(Ref<GLTFState> p_state);
|
||||
Error _reparent_non_joint_skeleton_subtrees(Ref<GLTFState> p_state, Ref<GLTFSkeleton> p_skeleton, const Vector<GLTFNodeIndex> &p_non_joints);
|
||||
Error _determine_skeleton_roots(Ref<GLTFState> p_state, const GLTFSkeletonIndex p_skel_i);
|
||||
|
||||
#ifdef MODULE_SKELETON_3D_ENABLED
|
||||
Error _create_skeletons(Ref<GLTFState> p_state);
|
||||
#endif
|
||||
|
||||
Error _map_skin_joints_indices_to_skeleton_bone_indices(Ref<GLTFState> p_state);
|
||||
Error _serialize_skins(Ref<GLTFState> p_state);
|
||||
Error _create_skins(Ref<GLTFState> p_state);
|
||||
#ifdef MODULE_SKELETON_3D_ENABLED
|
||||
bool _skins_are_same(const Ref<Skin> p_skin_a, const Ref<Skin> p_skin_b);
|
||||
#endif
|
||||
void _remove_duplicate_skins(Ref<GLTFState> p_state);
|
||||
Error _serialize_cameras(Ref<GLTFState> p_state);
|
||||
Error _parse_cameras(Ref<GLTFState> p_state);
|
||||
Error _parse_lights(Ref<GLTFState> p_state);
|
||||
Error _parse_animations(Ref<GLTFState> p_state);
|
||||
Error _serialize_animations(Ref<GLTFState> p_state);
|
||||
|
||||
#ifdef MODULE_SKELETON_3D_ENABLED
|
||||
BoneAttachment *_generate_bone_attachment(Ref<GLTFState> p_state, Skeleton *p_skeleton, const GLTFNodeIndex p_node_index, const GLTFNodeIndex p_bone_index);
|
||||
#endif
|
||||
|
||||
Spatial *_generate_mesh_instance(Ref<GLTFState> p_state, Node *p_scene_parent, const GLTFNodeIndex p_node_index);
|
||||
Camera *_generate_camera(Ref<GLTFState> p_state, Node *p_scene_parent,
|
||||
const GLTFNodeIndex p_node_index);
|
||||
Spatial *_generate_light(Ref<GLTFState> p_state, Node *p_scene_parent, const GLTFNodeIndex p_node_index);
|
||||
Spatial *_generate_spatial(Ref<GLTFState> p_state, Node *p_scene_parent,
|
||||
const GLTFNodeIndex p_node_index);
|
||||
void _assign_scene_names(Ref<GLTFState> p_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> p_state,
|
||||
const Vector<Quaternion> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
GLTFAccessorIndex _encode_accessor_as_weights(Ref<GLTFState> p_state,
|
||||
const Vector<Color> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
GLTFAccessorIndex _encode_accessor_as_joints(Ref<GLTFState> p_state,
|
||||
const Vector<Color> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
GLTFAccessorIndex _encode_accessor_as_floats(Ref<GLTFState> p_state,
|
||||
const Vector<real_t> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
GLTFAccessorIndex _encode_accessor_as_vec2(Ref<GLTFState> p_state,
|
||||
const Vector<Vector2> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
|
||||
void _calc_accessor_vec2_min_max(int p_i, const int p_element_count, Vector<double> &p_type_max, Vector2 p_attribs, Vector<double> &p_type_min) {
|
||||
if (p_i == 0) {
|
||||
for (int32_t type_i = 0; type_i < p_element_count; type_i++) {
|
||||
p_type_max.write[type_i] = p_attribs[(p_i * p_element_count) + type_i];
|
||||
p_type_min.write[type_i] = p_attribs[(p_i * p_element_count) + type_i];
|
||||
}
|
||||
}
|
||||
for (int32_t type_i = 0; type_i < p_element_count; type_i++) {
|
||||
p_type_max.write[type_i] = MAX(p_attribs[(p_i * p_element_count) + type_i], p_type_max[type_i]);
|
||||
p_type_min.write[type_i] = MIN(p_attribs[(p_i * p_element_count) + type_i], p_type_min[type_i]);
|
||||
p_type_max.write[type_i] = _filter_number(p_type_max.write[type_i]);
|
||||
p_type_min.write[type_i] = _filter_number(p_type_min.write[type_i]);
|
||||
}
|
||||
}
|
||||
|
||||
GLTFAccessorIndex _encode_accessor_as_vec3(Ref<GLTFState> p_state,
|
||||
const Vector<Vector3> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
GLTFAccessorIndex _encode_accessor_as_color(Ref<GLTFState> p_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> p_state,
|
||||
const Vector<int32_t> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
GLTFAccessorIndex _encode_accessor_as_xform(Ref<GLTFState> p_state,
|
||||
const Vector<Transform> p_attribs,
|
||||
const bool p_for_vertex);
|
||||
Error _encode_buffer_view(Ref<GLTFState> p_state, const double *p_src,
|
||||
const int p_count, const GLTFType p_type,
|
||||
const int p_component_type, const bool p_normalized,
|
||||
const int p_byte_offset, const bool p_for_vertex,
|
||||
GLTFBufferViewIndex &p_r_accessor);
|
||||
Error _encode_accessors(Ref<GLTFState> p_state);
|
||||
Error _encode_buffer_views(Ref<GLTFState> p_state);
|
||||
Error _serialize_materials(Ref<GLTFState> p_state);
|
||||
Error _serialize_meshes(Ref<GLTFState> p_state);
|
||||
Error _serialize_nodes(Ref<GLTFState> p_state);
|
||||
Error _serialize_scenes(Ref<GLTFState> p_state);
|
||||
String interpolation_to_string(const GLTFAnimation::Interpolation p_interp);
|
||||
GLTFAnimation::Track _convert_animation_track(Ref<GLTFState> p_state, GLTFAnimation::Track p_track, Ref<Animation> p_animation, int32_t p_track_i, GLTFNodeIndex p_node_i);
|
||||
Error _encode_buffer_bins(Ref<GLTFState> p_state, const String &p_path);
|
||||
Error _encode_buffer_glb(Ref<GLTFState> p_state, const String &p_path);
|
||||
Dictionary _serialize_texture_transform_uv1(Ref<SpatialMaterial> p_material);
|
||||
Dictionary _serialize_texture_transform_uv2(Ref<SpatialMaterial> p_material);
|
||||
Error _serialize_version(Ref<GLTFState> p_state);
|
||||
Error _serialize_file(Ref<GLTFState> p_state, const String p_path);
|
||||
Error _serialize_gltf_extensions(Ref<GLTFState> p_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 p_diffuse,
|
||||
float p_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 extension_generate_scene(Ref<GLTFState> p_state);
|
||||
|
||||
String _sanitize_scene_name(Ref<GLTFState> p_state, const String &p_name);
|
||||
String _legacy_validate_node_name(const String &p_name);
|
||||
|
||||
Error _parse_gltf_extensions(Ref<GLTFState> p_state);
|
||||
|
||||
void _process_mesh_instances(Ref<GLTFState> p_state, Node *scene_root);
|
||||
void _generate_scene_node(Ref<GLTFState> p_state, Node *scene_parent,
|
||||
Spatial *p_scene_root,
|
||||
const GLTFNodeIndex p_node_index);
|
||||
|
||||
#ifdef MODULE_SKELETON_3D_ENABLED
|
||||
void _generate_skeleton_bone_node(Ref<GLTFState> p_state, Node *scene_parent, Spatial *scene_root, const GLTFNodeIndex node_index);
|
||||
#endif
|
||||
|
||||
void _import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_ap,
|
||||
const GLTFAnimationIndex p_index, const int p_bake_fps);
|
||||
void _convert_mesh_instances(Ref<GLTFState> p_state);
|
||||
GLTFCameraIndex _convert_camera(Ref<GLTFState> p_state, Camera *p_camera);
|
||||
void _convert_light_to_gltf(Light *p_light, Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node);
|
||||
GLTFLightIndex _convert_light(Ref<GLTFState> p_state, Light *p_light);
|
||||
void _convert_spatial(Ref<GLTFState> p_state, Spatial *p_spatial, Ref<GLTFNode> p_node);
|
||||
void _convert_scene_node(Ref<GLTFState> p_state, Node *p_current,
|
||||
const GLTFNodeIndex p_gltf_current,
|
||||
const GLTFNodeIndex p_gltf_root);
|
||||
|
||||
#ifdef MODULE_CSG_ENABLED
|
||||
void _convert_csg_shape_to_gltf(CSGShape *p_current, GLTFNodeIndex p_gltf_parent, Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state);
|
||||
#endif // MODULE_CSG_ENABLED
|
||||
|
||||
void _create_gltf_node(Ref<GLTFState> p_state,
|
||||
Node *p_scene_parent,
|
||||
GLTFNodeIndex p_current_node_i,
|
||||
GLTFNodeIndex p_parent_node_index,
|
||||
GLTFNodeIndex p_root_gltf_node,
|
||||
Ref<GLTFNode> p_gltf_node);
|
||||
void _convert_animation_player_to_gltf(
|
||||
AnimationPlayer *p_animation_player, Ref<GLTFState> p_state,
|
||||
GLTFNodeIndex p_gltf_current,
|
||||
GLTFNodeIndex p_gltf_root_index,
|
||||
Ref<GLTFNode> p_gltf_node, Node *p_scene_parent);
|
||||
void _check_visibility(Node *p_node, bool &p_retflag);
|
||||
void _convert_camera_to_gltf(Camera *p_camera, Ref<GLTFState> p_state,
|
||||
Ref<GLTFNode> p_gltf_node);
|
||||
#ifdef MODULE_GRIDMAP_ENABLED
|
||||
void _convert_grid_map_to_gltf(
|
||||
GridMap *p_grid_map,
|
||||
GLTFNodeIndex p_parent_node_index,
|
||||
GLTFNodeIndex p_root_node_index,
|
||||
Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state);
|
||||
#endif // MODULE_GRIDMAP_ENABLED
|
||||
void _convert_mult_mesh_instance_to_gltf(
|
||||
MultiMeshInstance *p_scene_parent,
|
||||
GLTFNodeIndex p_parent_node_index,
|
||||
GLTFNodeIndex p_root_node_index,
|
||||
Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state);
|
||||
|
||||
#ifdef MODULE_SKELETON_3D_ENABLED
|
||||
void _convert_skeleton_to_gltf(Skeleton *p_scene_parent, Ref<GLTFState> p_state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> p_gltf_node);
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_SKELETON_3D_ENABLED
|
||||
void _convert_bone_attachment_to_gltf(BoneAttachment *p_bone_attachment,
|
||||
Ref<GLTFState> p_state,
|
||||
GLTFNodeIndex p_parent_node_index,
|
||||
GLTFNodeIndex p_root_node_index,
|
||||
Ref<GLTFNode> p_gltf_node);
|
||||
#endif
|
||||
|
||||
void _convert_mesh_instance_to_gltf(MeshInstance *p_mesh_instance,
|
||||
Ref<GLTFState> p_state,
|
||||
Ref<GLTFNode> p_gltf_node);
|
||||
GLTFMeshIndex _convert_mesh_to_gltf(Ref<GLTFState> p_state,
|
||||
MeshInstance *p_mesh_instance);
|
||||
void _convert_animation(Ref<GLTFState> p_state, AnimationPlayer *p_ap,
|
||||
String p_animation_track_name);
|
||||
Error serialize(Ref<GLTFState> p_state, Node *p_root, const String &p_path);
|
||||
Error parse(Ref<GLTFState> p_state, String p_paths, bool p_read_binary = false);
|
||||
};
|
||||
|
||||
#endif // GLTF_DOCUMENT_H
|
@ -1,353 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_state.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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"
|
||||
|
||||
#include "scene/animation/animation_player.h"
|
||||
|
||||
void GLTFState::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("add_used_extension", "extension_name", "required"), &GLTFState::add_used_extension);
|
||||
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", "idx"), &GLTFState::get_animation_players_count);
|
||||
ClassDB::bind_method(D_METHOD("get_animation_player", "idx"), &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_texture_samplers"), &GLTFState::get_texture_samplers);
|
||||
ClassDB::bind_method(D_METHOD("set_texture_samplers", "texture_samplers"), &GLTFState::set_texture_samplers);
|
||||
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_unique_animation_names"), &GLTFState::get_unique_animation_names);
|
||||
ClassDB::bind_method(D_METHOD("set_unique_animation_names", "unique_animation_names"), &GLTFState::set_unique_animation_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_create_animations"), &GLTFState::get_create_animations);
|
||||
ClassDB::bind_method(D_METHOD("set_create_animations", "create_animations"), &GLTFState::set_create_animations);
|
||||
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", "idx"), &GLTFState::get_scene_node);
|
||||
ClassDB::bind_method(D_METHOD("get_additional_data", "extension_name"), &GLTFState::get_additional_data);
|
||||
ClassDB::bind_method(D_METHOD("set_additional_data", "extension_name", "additional_data"), &GLTFState::set_additional_data);
|
||||
|
||||
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::POOL_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::POOL_INT_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, "texture_samplers", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_texture_samplers", "get_texture_samplers"); //Vector<Ref<GLTFTextureSampler>>
|
||||
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"); // RBSet<String>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "unique_animation_names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_unique_animation_names", "get_unique_animation_names"); // RBSet<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"); // RBMap<GLTFSkeletonIndex,
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "create_animations"), "set_create_animations", "get_create_animations"); // bool
|
||||
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>>
|
||||
}
|
||||
|
||||
void GLTFState::add_used_extension(const String &p_extension_name, bool p_required) {
|
||||
if (extensions_used.find(p_extension_name) == -1) {
|
||||
extensions_used.push_back(p_extension_name);
|
||||
}
|
||||
if (p_required) {
|
||||
if (extensions_required.find(p_extension_name) == -1) {
|
||||
extensions_required.push_back(p_extension_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 GLTFTemplateConvert::to_array(nodes);
|
||||
}
|
||||
|
||||
void GLTFState::set_nodes(Array p_nodes) {
|
||||
GLTFTemplateConvert::set_from_array(nodes, p_nodes);
|
||||
}
|
||||
|
||||
Array GLTFState::get_buffers() {
|
||||
return GLTFTemplateConvert::to_array(buffers);
|
||||
}
|
||||
|
||||
void GLTFState::set_buffers(Array p_buffers) {
|
||||
GLTFTemplateConvert::set_from_array(buffers, p_buffers);
|
||||
}
|
||||
|
||||
Array GLTFState::get_buffer_views() {
|
||||
return GLTFTemplateConvert::to_array(buffer_views);
|
||||
}
|
||||
|
||||
void GLTFState::set_buffer_views(Array p_buffer_views) {
|
||||
GLTFTemplateConvert::set_from_array(buffer_views, p_buffer_views);
|
||||
}
|
||||
|
||||
Array GLTFState::get_accessors() {
|
||||
return GLTFTemplateConvert::to_array(accessors);
|
||||
}
|
||||
|
||||
void GLTFState::set_accessors(Array p_accessors) {
|
||||
GLTFTemplateConvert::set_from_array(accessors, p_accessors);
|
||||
}
|
||||
|
||||
Array GLTFState::get_meshes() {
|
||||
return GLTFTemplateConvert::to_array(meshes);
|
||||
}
|
||||
|
||||
void GLTFState::set_meshes(Array p_meshes) {
|
||||
GLTFTemplateConvert::set_from_array(meshes, p_meshes);
|
||||
}
|
||||
|
||||
Array GLTFState::get_materials() {
|
||||
return GLTFTemplateConvert::to_array(materials);
|
||||
}
|
||||
|
||||
void GLTFState::set_materials(Array p_materials) {
|
||||
GLTFTemplateConvert::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 GLTFTemplateConvert::to_array(root_nodes);
|
||||
}
|
||||
|
||||
void GLTFState::set_root_nodes(Array p_root_nodes) {
|
||||
GLTFTemplateConvert::set_from_array(root_nodes, p_root_nodes);
|
||||
}
|
||||
|
||||
Array GLTFState::get_textures() {
|
||||
return GLTFTemplateConvert::to_array(textures);
|
||||
}
|
||||
|
||||
void GLTFState::set_textures(Array p_textures) {
|
||||
GLTFTemplateConvert::set_from_array(textures, p_textures);
|
||||
}
|
||||
|
||||
Array GLTFState::get_texture_samplers() {
|
||||
return GLTFTemplateConvert::to_array(texture_samplers);
|
||||
}
|
||||
|
||||
void GLTFState::set_texture_samplers(Array p_texture_samplers) {
|
||||
GLTFTemplateConvert::set_from_array(texture_samplers, p_texture_samplers);
|
||||
}
|
||||
|
||||
Array GLTFState::get_images() {
|
||||
return GLTFTemplateConvert::to_array(images);
|
||||
}
|
||||
|
||||
void GLTFState::set_images(Array p_images) {
|
||||
GLTFTemplateConvert::set_from_array(images, p_images);
|
||||
}
|
||||
|
||||
Array GLTFState::get_skins() {
|
||||
return GLTFTemplateConvert::to_array(skins);
|
||||
}
|
||||
|
||||
void GLTFState::set_skins(Array p_skins) {
|
||||
GLTFTemplateConvert::set_from_array(skins, p_skins);
|
||||
}
|
||||
|
||||
Array GLTFState::get_cameras() {
|
||||
return GLTFTemplateConvert::to_array(cameras);
|
||||
}
|
||||
|
||||
void GLTFState::set_cameras(Array p_cameras) {
|
||||
GLTFTemplateConvert::set_from_array(cameras, p_cameras);
|
||||
}
|
||||
|
||||
Array GLTFState::get_lights() {
|
||||
return GLTFTemplateConvert::to_array(lights);
|
||||
}
|
||||
|
||||
void GLTFState::set_lights(Array p_lights) {
|
||||
GLTFTemplateConvert::set_from_array(lights, p_lights);
|
||||
}
|
||||
|
||||
Array GLTFState::get_unique_names() {
|
||||
return GLTFTemplateConvert::to_array(unique_names);
|
||||
}
|
||||
|
||||
void GLTFState::set_unique_names(Array p_unique_names) {
|
||||
GLTFTemplateConvert::set_from_array(unique_names, p_unique_names);
|
||||
}
|
||||
|
||||
Array GLTFState::get_unique_animation_names() {
|
||||
return GLTFTemplateConvert::to_array(unique_animation_names);
|
||||
}
|
||||
|
||||
void GLTFState::set_unique_animation_names(Array p_unique_animation_names) {
|
||||
GLTFTemplateConvert::set_from_array(unique_animation_names, p_unique_animation_names);
|
||||
}
|
||||
|
||||
Array GLTFState::get_skeletons() {
|
||||
return GLTFTemplateConvert::to_array(skeletons);
|
||||
}
|
||||
|
||||
void GLTFState::set_skeletons(Array p_skeletons) {
|
||||
GLTFTemplateConvert::set_from_array(skeletons, p_skeletons);
|
||||
}
|
||||
|
||||
Dictionary GLTFState::get_skeleton_to_node() {
|
||||
return GLTFTemplateConvert::to_dict(skeleton_to_node);
|
||||
}
|
||||
|
||||
void GLTFState::set_skeleton_to_node(Dictionary p_skeleton_to_node) {
|
||||
GLTFTemplateConvert::set_from_dict(skeleton_to_node, p_skeleton_to_node);
|
||||
}
|
||||
|
||||
bool GLTFState::get_create_animations() {
|
||||
return create_animations;
|
||||
}
|
||||
|
||||
void GLTFState::set_create_animations(bool p_create_animations) {
|
||||
create_animations = p_create_animations;
|
||||
}
|
||||
|
||||
Array GLTFState::get_animations() {
|
||||
return GLTFTemplateConvert::to_array(animations);
|
||||
}
|
||||
|
||||
void GLTFState::set_animations(Array p_animations) {
|
||||
GLTFTemplateConvert::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];
|
||||
}
|
||||
|
||||
Variant GLTFState::get_additional_data(const String &p_extension_name) {
|
||||
return additional_data[p_extension_name];
|
||||
}
|
||||
|
||||
void GLTFState::set_additional_data(const String &p_extension_name, Variant p_additional_data) {
|
||||
additional_data[p_extension_name] = p_additional_data;
|
||||
}
|
@ -1,190 +0,0 @@
|
||||
#ifndef GLTF_STATE_H
|
||||
#define GLTF_STATE_H
|
||||
/*************************************************************************/
|
||||
/* gltf_state.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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 "extensions/gltf_light.h"
|
||||
#include "gltf_template_convert.h"
|
||||
#include "structures/gltf_accessor.h"
|
||||
#include "structures/gltf_animation.h"
|
||||
#include "structures/gltf_buffer_view.h"
|
||||
#include "structures/gltf_camera.h"
|
||||
#include "structures/gltf_mesh.h"
|
||||
#include "structures/gltf_node.h"
|
||||
#include "structures/gltf_skeleton.h"
|
||||
#include "structures/gltf_skin.h"
|
||||
#include "structures/gltf_texture.h"
|
||||
#include "structures/gltf_texture_sampler.h"
|
||||
|
||||
class GLTFState : public Resource {
|
||||
GDCLASS(GLTFState, Resource);
|
||||
friend class GLTFDocument;
|
||||
friend class PackedSceneGLTF;
|
||||
|
||||
String filename;
|
||||
Dictionary json;
|
||||
int major_version = 0;
|
||||
int minor_version = 0;
|
||||
Vector<uint8_t> glb_data;
|
||||
|
||||
bool use_named_skin_binds = false;
|
||||
bool use_khr_texture_transform = false;
|
||||
bool use_legacy_names = false;
|
||||
uint32_t compress_flags = 0;
|
||||
bool create_animations = true;
|
||||
|
||||
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;
|
||||
RBMap<Ref<Material>, GLTFMaterialIndex> material_cache;
|
||||
Vector<Ref<Material>> materials;
|
||||
|
||||
String scene_name;
|
||||
Vector<int> root_nodes;
|
||||
Vector<Ref<GLTFTexture>> textures;
|
||||
Vector<Ref<GLTFTextureSampler>> texture_samplers;
|
||||
Ref<GLTFTextureSampler> default_texture_sampler;
|
||||
Vector<Ref<Image>> images;
|
||||
RBMap<GLTFTextureIndex, Ref<Texture>> texture_cache;
|
||||
Vector<String> extensions_used;
|
||||
Vector<String> extensions_required;
|
||||
|
||||
Vector<Ref<GLTFSkin>> skins;
|
||||
Vector<Ref<GLTFCamera>> cameras;
|
||||
Vector<Ref<GLTFLight>> lights;
|
||||
RBSet<String> unique_names;
|
||||
RBSet<String> unique_animation_names;
|
||||
|
||||
Vector<Ref<GLTFSkeleton>> skeletons;
|
||||
RBMap<GLTFSkeletonIndex, GLTFNodeIndex> skeleton_to_node;
|
||||
Vector<Ref<GLTFAnimation>> animations;
|
||||
RBMap<GLTFNodeIndex, Node *> scene_nodes;
|
||||
|
||||
RBMap<ObjectID, GLTFSkeletonIndex> skeleton3d_to_gltf_skeleton;
|
||||
RBMap<ObjectID, RBMap<ObjectID, GLTFSkinIndex>> skin_and_skeleton3d_to_gltf_skin;
|
||||
Dictionary additional_data;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void add_used_extension(const String &p_extension, bool p_required = false);
|
||||
|
||||
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_texture_samplers();
|
||||
void set_texture_samplers(Array p_texture_samplers);
|
||||
|
||||
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_unique_animation_names();
|
||||
void set_unique_animation_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);
|
||||
|
||||
bool get_create_animations();
|
||||
void set_create_animations(bool p_create_animations);
|
||||
|
||||
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);
|
||||
|
||||
Variant get_additional_data(const String &p_extension_name);
|
||||
void set_additional_data(const String &p_extension_name, Variant p_additional_data);
|
||||
};
|
||||
|
||||
#endif // GLTF_STATE_H
|
@ -1,94 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_template_convert.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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_TEMPLATE_CONVERT_H
|
||||
#define GLTF_TEMPLATE_CONVERT_H
|
||||
|
||||
#include "core/variant/array.h"
|
||||
#include "core/variant/dictionary.h"
|
||||
#include "core/containers/rb_set.h"
|
||||
|
||||
namespace GLTFTemplateConvert {
|
||||
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 RBSet<T> &p_inp) {
|
||||
Array ret;
|
||||
typename RBSet<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(RBSet<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 RBMap<K, V> &p_inp) {
|
||||
Dictionary ret;
|
||||
for (typename RBMap<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(RBMap<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]];
|
||||
}
|
||||
}
|
||||
} //namespace GLTFTemplateConvert
|
||||
|
||||
#endif // GLTF_TEMPLATE_CONVERT_H
|
@ -1,162 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* packed_scene_gltf.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "packed_scene_gltf.h"
|
||||
|
||||
#include "editor/import/resource_importer_scene.h"
|
||||
#include "scene/main/spatial.h"
|
||||
#include "scene/animation/animation_player.h"
|
||||
#include "scene/resources/mesh/mesh.h"
|
||||
|
||||
#include "gltf_document.h"
|
||||
|
||||
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", "compress_flags", "state"),
|
||||
&PackedSceneGLTF::pack_gltf, DEFVAL(0), DEFVAL(1000.0f), DEFVAL(Mesh::ARRAY_COMPRESS_DEFAULT), DEFVAL(Ref<GLTFState>()));
|
||||
ClassDB::bind_method(D_METHOD("import_gltf_scene", "path", "flags", "bake_fps", "compress_flags", "state"),
|
||||
&PackedSceneGLTF::import_gltf_scene, DEFVAL(0), DEFVAL(1000.0f), DEFVAL(Mesh::ARRAY_COMPRESS_DEFAULT), DEFVAL(Ref<GLTFState>()));
|
||||
}
|
||||
|
||||
Node *PackedSceneGLTF::import_gltf_scene(const String &p_path, uint32_t p_flags, float p_bake_fps, uint32_t p_compress_flags, Ref<GLTFState> r_state) {
|
||||
Error err = FAILED;
|
||||
List<String> deps;
|
||||
return import_scene(p_path, p_flags, p_bake_fps, p_compress_flags, &deps, &err, r_state);
|
||||
}
|
||||
|
||||
Node *PackedSceneGLTF::import_scene(const String &p_path, uint32_t p_flags,
|
||||
int p_bake_fps, uint32_t p_compress_flags,
|
||||
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;
|
||||
r_state->use_legacy_names =
|
||||
p_flags & EditorSceneImporter::IMPORT_USE_LEGACY_NAMES;
|
||||
r_state->compress_flags = p_compress_flags;
|
||||
r_state->set_create_animations(p_flags & EditorSceneImporter::IMPORT_ANIMATION);
|
||||
|
||||
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);
|
||||
|
||||
Spatial *root = memnew(Spatial);
|
||||
if (r_state->use_legacy_names) {
|
||||
root->set_name(gltf_document->_legacy_validate_node_name(r_state->scene_name));
|
||||
} else {
|
||||
root->set_name(r_state->scene_name);
|
||||
}
|
||||
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->get_create_animations() && 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);
|
||||
}
|
||||
}
|
||||
|
||||
gltf_document->extension_generate_scene(r_state);
|
||||
|
||||
return cast_to<Spatial>(root);
|
||||
}
|
||||
|
||||
void PackedSceneGLTF::pack_gltf(String p_path, int32_t p_flags,
|
||||
real_t p_bake_fps, uint32_t p_compress_flags, Ref<GLTFState> r_state) {
|
||||
Error err = FAILED;
|
||||
List<String> deps;
|
||||
Node *root = import_scene(p_path, p_flags, p_bake_fps, p_compress_flags, &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;
|
||||
}
|
||||
|
||||
#endif // TOOLS_ENABLED
|
@ -1,65 +0,0 @@
|
||||
#ifndef PACKED_SCENE_GLTF_H
|
||||
#define PACKED_SCENE_GLTF_H
|
||||
/*************************************************************************/
|
||||
/* packed_scene_gltf.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/resources/packed_scene.h"
|
||||
|
||||
#include "gltf_state.h"
|
||||
|
||||
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 = nullptr);
|
||||
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, uint32_t p_compress_flags,
|
||||
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, uint32_t p_compress_flags, 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, uint32_t p_compress_flags = Mesh::ARRAY_COMPRESS_DEFAULT, Ref<GLTFState> r_state = Ref<GLTFState>());
|
||||
};
|
||||
|
||||
#endif // PACKED_SCENE_GLTF_H
|
||||
|
||||
#endif // TOOLS_ENABLED
|
@ -1,99 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* register_types.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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 _3D_DISABLED
|
||||
|
||||
#include "register_types.h"
|
||||
|
||||
#include "extensions/gltf_document_extension.h"
|
||||
#include "extensions/gltf_spec_gloss.h"
|
||||
#include "extensions/physics/gltf_document_extension_physics.h"
|
||||
#include "gltf_document.h"
|
||||
#include "gltf_state.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor_scene_exporter_gltf_plugin.h"
|
||||
#include "editor_scene_importer_gltf.h"
|
||||
#endif
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
static void _editor_init() {
|
||||
Ref<EditorSceneImporterGLTF> import_gltf;
|
||||
import_gltf.instance();
|
||||
ResourceImporterScene::get_singleton()->add_importer(import_gltf);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define GLTF_REGISTER_DOCUMENT_EXTENSION(m_doc_ext_class) \
|
||||
Ref<m_doc_ext_class> extension_##m_doc_ext_class; \
|
||||
extension_##m_doc_ext_class.instance(); \
|
||||
GLTFDocument::register_gltf_document_extension(extension_##m_doc_ext_class);
|
||||
|
||||
void register_gltf_types(ModuleRegistrationLevel p_level) {
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_EDITOR) {
|
||||
ClassDB::APIType prev_api = ClassDB::get_current_api();
|
||||
ClassDB::set_current_api(ClassDB::API_EDITOR);
|
||||
//ClassDB::register_class<EditorSceneImporterGLTF>();
|
||||
EditorPlugins::add_by_type<SceneExporterGLTFPlugin>();
|
||||
ClassDB::set_current_api(prev_api);
|
||||
EditorNode::add_init_callback(_editor_init);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) {
|
||||
ClassDB::register_class<GLTFSpecGloss>();
|
||||
ClassDB::register_class<GLTFNode>();
|
||||
ClassDB::register_class<GLTFAnimation>();
|
||||
ClassDB::register_class<GLTFBufferView>();
|
||||
ClassDB::register_class<GLTFAccessor>();
|
||||
ClassDB::register_class<GLTFCollider>();
|
||||
ClassDB::register_class<GLTFTexture>();
|
||||
ClassDB::register_class<GLTFTextureSampler>();
|
||||
ClassDB::register_class<GLTFSkeleton>();
|
||||
ClassDB::register_class<GLTFSkin>();
|
||||
ClassDB::register_class<GLTFCamera>();
|
||||
ClassDB::register_class<GLTFMesh>();
|
||||
ClassDB::register_class<GLTFLight>();
|
||||
ClassDB::register_class<GLTFPhysicsBody>();
|
||||
ClassDB::register_class<GLTFState>();
|
||||
ClassDB::register_class<GLTFDocument>();
|
||||
ClassDB::register_class<GLTFDocumentExtension>();
|
||||
ClassDB::register_class<PackedSceneGLTF>();
|
||||
GLTF_REGISTER_DOCUMENT_EXTENSION(GLTFDocumentExtensionPhysics);
|
||||
}
|
||||
}
|
||||
|
||||
void unregister_gltf_types(ModuleRegistrationLevel p_level) {
|
||||
GLTFDocument::unregister_all_gltf_document_extensions();
|
||||
}
|
||||
|
||||
#endif // _3D_DISABLED
|
@ -1,42 +0,0 @@
|
||||
#ifndef GLTF_REGISTER_TYPES_H
|
||||
#define GLTF_REGISTER_TYPES_H
|
||||
/*************************************************************************/
|
||||
/* register_types.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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 _3D_DISABLED
|
||||
|
||||
#include "modules/register_module_types.h"
|
||||
|
||||
void register_gltf_types(ModuleRegistrationLevel p_level);
|
||||
void unregister_gltf_types(ModuleRegistrationLevel p_level);
|
||||
|
||||
#endif // _3D_DISABLED
|
||||
|
||||
#endif // GLTF_REGISTER_TYPES_H
|
@ -1,189 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_accessor.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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"); // GLTFType
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_REAL_ARRAY, "min"), "set_min", "get_min"); // Vector<real_t>
|
||||
ADD_PROPERTY(PropertyInfo(Variant::POOL_REAL_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 = (GLTFType)p_type; // TODO: Register enum
|
||||
}
|
||||
|
||||
PoolVector<float> GLTFAccessor::get_min() {
|
||||
return min;
|
||||
}
|
||||
|
||||
void GLTFAccessor::set_min(PoolVector<float> p_min) {
|
||||
min = p_min;
|
||||
}
|
||||
|
||||
PoolVector<float> GLTFAccessor::get_max() {
|
||||
return max;
|
||||
}
|
||||
|
||||
void GLTFAccessor::set_max(PoolVector<float> 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;
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
#ifndef GLTF_ACCESSOR_H
|
||||
#define GLTF_ACCESSOR_H
|
||||
/*************************************************************************/
|
||||
/* gltf_accessor.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/object/resource.h"
|
||||
|
||||
#include "../gltf_defines.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;
|
||||
GLTFType type = TYPE_SCALAR;
|
||||
PoolVector<float> min;
|
||||
PoolVector<float> 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);
|
||||
|
||||
PoolVector<float> get_min();
|
||||
void set_min(PoolVector<float> p_min);
|
||||
|
||||
PoolVector<float> get_max();
|
||||
void set_max(PoolVector<float> 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
|
@ -1,53 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_animation.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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;
|
||||
}
|
||||
|
||||
RBMap<int, GLTFAnimation::Track> &GLTFAnimation::get_tracks() {
|
||||
return tracks;
|
||||
}
|
||||
|
||||
GLTFAnimation::GLTFAnimation() {
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
#ifndef GLTF_ANIMATION_H
|
||||
#define GLTF_ANIMATION_H
|
||||
/*************************************************************************/
|
||||
/* gltf_animation.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/object/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<Quaternion> rotation_track;
|
||||
Channel<Vector3> scale_track;
|
||||
Vector<Channel<float>> weight_tracks;
|
||||
};
|
||||
|
||||
public:
|
||||
bool get_loop() const;
|
||||
void set_loop(bool p_val);
|
||||
RBMap<int, GLTFAnimation::Track> &get_tracks();
|
||||
GLTFAnimation();
|
||||
|
||||
private:
|
||||
bool loop = false;
|
||||
RBMap<int, Track> tracks;
|
||||
};
|
||||
|
||||
#endif // GLTF_ANIMATION_H
|
@ -1,90 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_buffer_view.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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;
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
#ifndef GLTF_BUFFER_VIEW_H
|
||||
#define GLTF_BUFFER_VIEW_H
|
||||
/*************************************************************************/
|
||||
/* gltf_buffer_view.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/object/resource.h"
|
||||
|
||||
#include "../gltf_defines.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
|
@ -1,131 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* gltf_camera.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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"
|
||||
|
||||
#include "scene/3d/camera.h"
|
||||
|
||||
void GLTFCamera::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("to_node"), &GLTFCamera::to_node);
|
||||
ClassDB::bind_method(D_METHOD("to_dictionary"), &GLTFCamera::to_dictionary);
|
||||
|
||||
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_size_mag"), &GLTFCamera::get_size_mag);
|
||||
ClassDB::bind_method(D_METHOD("set_size_mag", "size_mag"), &GLTFCamera::set_size_mag);
|
||||
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::REAL, "fov_size"), "set_fov_size", "get_fov_size"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "size_mag"), "set_size_mag", "get_size_mag"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "zfar"), "set_zfar", "get_zfar"); // float
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "znear"), "set_znear", "get_znear"); // float
|
||||
}
|
||||
|
||||
Ref<GLTFCamera> GLTFCamera::from_node(const Camera *p_camera) {
|
||||
Ref<GLTFCamera> c;
|
||||
c.instance();
|
||||
ERR_FAIL_COND_V_MSG(!p_camera, c, "Tried to create a GLTFCamera from a Camera node, but the given node was null.");
|
||||
c->set_perspective(p_camera->get_projection() == Camera::PROJECTION_PERSPECTIVE);
|
||||
// GLTF spec (yfov) is in radians, Godot's camera (fov) is in degrees.
|
||||
c->set_fov_size(Math::deg2rad(p_camera->get_fov()));
|
||||
// GLTF spec (xmag and ymag) is a radius in meters, Godot's camera (size) is a diameter in meters.
|
||||
c->set_size_mag(p_camera->get_size() * 0.5f);
|
||||
c->set_zfar(p_camera->get_zfar());
|
||||
c->set_znear(p_camera->get_znear());
|
||||
return c;
|
||||
}
|
||||
|
||||
Camera *GLTFCamera::to_node() const {
|
||||
Camera *camera = memnew(Camera);
|
||||
camera->set_projection(perspective ? Camera::PROJECTION_PERSPECTIVE : Camera::PROJECTION_ORTHOGONAL);
|
||||
// GLTF spec (yfov) is in radians, Godot's camera (fov) is in degrees.
|
||||
camera->set_fov(Math::rad2deg(fov));
|
||||
// GLTF spec (xmag and ymag) is a radius in meters, Godot's camera (size) is a diameter in meters.
|
||||
camera->set_size(size_mag * 2.0f);
|
||||
camera->set_znear(znear);
|
||||
camera->set_zfar(zfar);
|
||||
return camera;
|
||||
}
|
||||
|
||||
Ref<GLTFCamera> GLTFCamera::from_dictionary(const Dictionary p_dictionary) {
|
||||
ERR_FAIL_COND_V_MSG(!p_dictionary.has("type"), Ref<GLTFCamera>(), "Failed to parse GLTF camera, missing required field 'type'.");
|
||||
Ref<GLTFCamera> camera;
|
||||
camera.instance();
|
||||
const String &type = p_dictionary["type"];
|
||||
if (type == "perspective") {
|
||||
camera->set_perspective(true);
|
||||
if (p_dictionary.has("perspective")) {
|
||||
const Dictionary &persp = p_dictionary["perspective"];
|
||||
camera->set_fov_size(persp["yfov"]);
|
||||
if (persp.has("zfar")) {
|
||||
camera->set_zfar(persp["zfar"]);
|
||||
}
|
||||
camera->set_znear(persp["znear"]);
|
||||
}
|
||||
} else if (type == "orthographic") {
|
||||
camera->set_perspective(false);
|
||||
if (p_dictionary.has("orthographic")) {
|
||||
const Dictionary &ortho = p_dictionary["orthographic"];
|
||||
camera->set_size_mag(ortho["ymag"]);
|
||||
camera->set_zfar(ortho["zfar"]);
|
||||
camera->set_znear(ortho["znear"]);
|
||||
}
|
||||
} else {
|
||||
ERR_PRINT("Error parsing GLTF camera: Camera type '" + type + "' is unknown, should be perspective or orthographic.");
|
||||
}
|
||||
return camera;
|
||||
}
|
||||
|
||||
Dictionary GLTFCamera::to_dictionary() const {
|
||||
Dictionary d;
|
||||
if (perspective) {
|
||||
Dictionary persp;
|
||||
persp["yfov"] = fov;
|
||||
persp["zfar"] = zfar;
|
||||
persp["znear"] = znear;
|
||||
d["perspective"] = persp;
|
||||
d["type"] = "perspective";
|
||||
} else {
|
||||
Dictionary ortho;
|
||||
ortho["ymag"] = size_mag;
|
||||
ortho["xmag"] = size_mag;
|
||||
ortho["zfar"] = zfar;
|
||||
ortho["znear"] = znear;
|
||||
d["orthographic"] = ortho;
|
||||
d["type"] = "orthographic";
|
||||
}
|
||||
return d;
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
#ifndef GLTF_CAMERA_H
|
||||
#define GLTF_CAMERA_H
|
||||
/*************************************************************************/
|
||||
/* gltf_camera.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 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/object/resource.h"
|
||||
|
||||
class Camera;
|
||||
|
||||
// Reference and test file:
|
||||
// https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_015_SimpleCameras.md
|
||||
|
||||
class GLTFCamera : public Resource {
|
||||
GDCLASS(GLTFCamera, Resource);
|
||||
|
||||
private:
|
||||
// GLTF has no default camera values, they should always be specified in
|
||||
// the GLTF file. Here we default to Godot's default camera settings.
|
||||
bool perspective = true;
|
||||
real_t fov = Math::deg2rad(75.0);
|
||||
real_t size_mag = 0.5;
|
||||
real_t zfar = 4000.0;
|
||||
real_t znear = 0.05;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
bool get_perspective() const { return perspective; }
|
||||
void set_perspective(bool p_val) { perspective = p_val; }
|
||||
real_t get_fov_size() const { return fov; }
|
||||
void set_fov_size(real_t p_val) { fov = p_val; }
|
||||
real_t get_size_mag() const { return size_mag; }
|
||||
void set_size_mag(real_t p_val) { size_mag = p_val; }
|
||||
real_t get_zfar() const { return zfar; }
|
||||
void set_zfar(real_t p_val) { zfar = p_val; }
|
||||
real_t get_znear() const { return znear; }
|
||||
void set_znear(real_t p_val) { znear = p_val; }
|
||||
|
||||
static Ref<GLTFCamera> from_node(const Camera *p_camera);
|
||||
Camera *to_node() const;
|
||||
|
||||
static Ref<GLTFCamera> from_dictionary(const Dictionary p_dictionary);
|
||||
Dictionary to_dictionary() const;
|
||||
};
|
||||
|
||||
#endif // GLTF_CAMERA_H
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user