summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/bone_map.cpp1
-rw-r--r--scene/resources/fog_material.cpp2
-rw-r--r--scene/resources/importer_mesh.cpp24
-rw-r--r--scene/resources/material.cpp6
-rw-r--r--scene/resources/material.h2
-rw-r--r--scene/resources/packed_scene.cpp20
-rw-r--r--scene/resources/resource_format_text.cpp24
-rw-r--r--scene/resources/surface_tool.cpp3
-rw-r--r--scene/resources/surface_tool.h9
-rw-r--r--scene/resources/video_stream.cpp198
-rw-r--r--scene/resources/video_stream.h76
-rw-r--r--scene/resources/visual_shader.cpp14
-rw-r--r--scene/resources/visual_shader.h6
-rw-r--r--scene/resources/visual_shader_nodes.cpp35
-rw-r--r--scene/resources/world_2d.cpp22
-rw-r--r--scene/resources/world_2d.h2
-rw-r--r--scene/resources/world_3d.cpp24
-rw-r--r--scene/resources/world_3d.h2
18 files changed, 400 insertions, 70 deletions
diff --git a/scene/resources/bone_map.cpp b/scene/resources/bone_map.cpp
index c73f8ca0b0..759d189bfa 100644
--- a/scene/resources/bone_map.cpp
+++ b/scene/resources/bone_map.cpp
@@ -152,7 +152,6 @@ void BoneMap::_validate_bone_map() {
} else {
bone_map.clear();
}
- emit_signal("retarget_option_updated");
}
void BoneMap::_bind_methods() {
diff --git a/scene/resources/fog_material.cpp b/scene/resources/fog_material.cpp
index 4e51bbaa73..aabaa54505 100644
--- a/scene/resources/fog_material.cpp
+++ b/scene/resources/fog_material.cpp
@@ -159,7 +159,7 @@ uniform sampler3D density_texture: hint_default_white;
void fog() {
DENSITY = density * clamp(exp2(-height_falloff * (WORLD_POSITION.y - OBJECT_POSITION.y)), 0.0, 1.0);
DENSITY *= texture(density_texture, UVW).r;
- DENSITY *= pow(clamp(-SDF / min(min(EXTENTS.x, EXTENTS.y), EXTENTS.z), 0.0, 1.0), edge_fade);
+ DENSITY *= pow(clamp(-2.0 * SDF / min(min(SIZE.x, SIZE.y), SIZE.z), 0.0, 1.0), edge_fade);
ALBEDO = albedo.rgb;
EMISSION = emission.rgb;
}
diff --git a/scene/resources/importer_mesh.cpp b/scene/resources/importer_mesh.cpp
index 55b633a40c..672581bbe2 100644
--- a/scene/resources/importer_mesh.cpp
+++ b/scene/resources/importer_mesh.cpp
@@ -452,6 +452,7 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli
new_indices.resize(index_count);
Vector<float> merged_normals_f32 = vector3_to_float32_array(merged_normals.ptr(), merged_normals.size());
+ const int simplify_options = SurfaceTool::SIMPLIFY_LOCK_BORDER;
size_t new_index_count = SurfaceTool::simplify_with_attrib_func(
(unsigned int *)new_indices.ptrw(),
@@ -460,6 +461,7 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli
sizeof(float) * 3, // Vertex stride
index_target,
max_mesh_error,
+ simplify_options,
&mesh_error,
merged_normals_f32.ptr(),
normal_weights.ptr(), 3);
@@ -1058,6 +1060,8 @@ struct EditorSceneFormatImporterMeshLightmapSurface {
String name;
};
+static const uint32_t custom_shift[RS::ARRAY_CUSTOM_COUNT] = { Mesh::ARRAY_FORMAT_CUSTOM0_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM1_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM2_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM3_SHIFT };
+
Error ImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform, float p_texel_size, const Vector<uint8_t> &p_src_cache, Vector<uint8_t> &r_dst_cache) {
ERR_FAIL_COND_V(!array_mesh_lightmap_unwrap_callback, ERR_UNCONFIGURED);
ERR_FAIL_COND_V_MSG(blend_shapes.size() != 0, ERR_UNAVAILABLE, "Can't unwrap mesh with blend shapes.");
@@ -1178,9 +1182,6 @@ Error ImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform,
return ERR_CANT_CREATE;
}
- //remove surfaces
- clear();
-
//create surfacetools for each surface..
LocalVector<Ref<SurfaceTool>> surfaces_tools;
@@ -1190,9 +1191,16 @@ Error ImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform,
st->begin(Mesh::PRIMITIVE_TRIANGLES);
st->set_material(lightmap_surfaces[i].material);
st->set_meta("name", lightmap_surfaces[i].name);
+
+ for (int custom_i = 0; custom_i < RS::ARRAY_CUSTOM_COUNT; custom_i++) {
+ st->set_custom_format(custom_i, (SurfaceTool::CustomFormat)((lightmap_surfaces[i].format >> custom_shift[custom_i]) & RS::ARRAY_FORMAT_CUSTOM_MASK));
+ }
surfaces_tools.push_back(st); //stay there
}
+ //remove surfaces
+ clear();
+
print_verbose("Mesh: Gen indices: " + itos(gen_index_count));
//go through all indices
@@ -1229,6 +1237,11 @@ Error ImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform,
if (lightmap_surfaces[surface].format & Mesh::ARRAY_FORMAT_WEIGHTS) {
surfaces_tools[surface]->set_weights(v.weights);
}
+ for (int custom_i = 0; custom_i < RS::ARRAY_CUSTOM_COUNT; custom_i++) {
+ if ((lightmap_surfaces[surface].format >> custom_shift[custom_i]) & RS::ARRAY_FORMAT_CUSTOM_MASK) {
+ surfaces_tools[surface]->set_custom(custom_i, v.custom[custom_i]);
+ }
+ }
Vector2 uv2(gen_uvs[gen_indices[i + j] * 2 + 0], gen_uvs[gen_indices[i + j] * 2 + 1]);
surfaces_tools[surface]->set_uv2(uv2);
@@ -1238,10 +1251,11 @@ Error ImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform,
}
//generate surfaces
- for (Ref<SurfaceTool> &tool : surfaces_tools) {
+ for (int i = 0; i < lightmap_surfaces.size(); i++) {
+ Ref<SurfaceTool> &tool = surfaces_tools[i];
tool->index();
Array arrays = tool->commit_to_arrays();
- add_surface(tool->get_primitive_type(), arrays, Array(), Dictionary(), tool->get_material(), tool->get_meta("name"));
+ add_surface(tool->get_primitive_type(), arrays, Array(), Dictionary(), tool->get_material(), tool->get_meta("name"), lightmap_surfaces[i].format);
}
set_lightmap_size_hint(Size2(size_x, size_y));
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index d6393966b1..7e84814ab3 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -2316,7 +2316,7 @@ BaseMaterial3D::TextureChannel BaseMaterial3D::get_refraction_texture_channel()
return refraction_texture_channel;
}
-Ref<Material> BaseMaterial3D::get_material_for_2d(bool p_shaded, Transparency p_transparency, bool p_double_sided, bool p_billboard, bool p_billboard_y, bool p_msdf, bool p_no_depth, bool p_fixed_size, TextureFilter p_filter, RID *r_shader_rid) {
+Ref<Material> BaseMaterial3D::get_material_for_2d(bool p_shaded, Transparency p_transparency, bool p_double_sided, bool p_billboard, bool p_billboard_y, bool p_msdf, bool p_no_depth, bool p_fixed_size, TextureFilter p_filter, AlphaAntiAliasing p_alpha_antialiasing_mode, RID *r_shader_rid) {
uint64_t key = 0;
key |= ((int8_t)p_shaded & 0x01) << 0;
key |= ((int8_t)p_transparency & 0x07) << 1; // Bits 1-3.
@@ -2326,7 +2326,8 @@ Ref<Material> BaseMaterial3D::get_material_for_2d(bool p_shaded, Transparency p_
key |= ((int8_t)p_msdf & 0x01) << 7;
key |= ((int8_t)p_no_depth & 0x01) << 8;
key |= ((int8_t)p_fixed_size & 0x01) << 9;
- key |= ((int8_t)p_filter & 0x07) << 10; // Bits 10-13.
+ key |= ((int8_t)p_filter & 0x07) << 10; // Bits 10-12.
+ key |= ((int8_t)p_alpha_antialiasing_mode & 0x07) << 13; // Bits 13-15.
if (materials_for_2d.has(key)) {
if (r_shader_rid) {
@@ -2346,6 +2347,7 @@ Ref<Material> BaseMaterial3D::get_material_for_2d(bool p_shaded, Transparency p_
material->set_flag(FLAG_ALBEDO_TEXTURE_MSDF, p_msdf);
material->set_flag(FLAG_DISABLE_DEPTH_TEST, p_no_depth);
material->set_flag(FLAG_FIXED_SIZE, p_fixed_size);
+ material->set_alpha_antialiasing(p_alpha_antialiasing_mode);
material->set_texture_filter(p_filter);
if (p_billboard || p_billboard_y) {
material->set_flag(FLAG_BILLBOARD_KEEP_SCALE, true);
diff --git a/scene/resources/material.h b/scene/resources/material.h
index 23f3a8824d..5ea9a807d4 100644
--- a/scene/resources/material.h
+++ b/scene/resources/material.h
@@ -760,7 +760,7 @@ public:
static void finish_shaders();
static void flush_changes();
- static Ref<Material> get_material_for_2d(bool p_shaded, Transparency p_transparency, bool p_double_sided, bool p_billboard = false, bool p_billboard_y = false, bool p_msdf = false, bool p_no_depth = false, bool p_fixed_size = false, TextureFilter p_filter = TEXTURE_FILTER_LINEAR_WITH_MIPMAPS, RID *r_shader_rid = nullptr);
+ static Ref<Material> get_material_for_2d(bool p_shaded, Transparency p_transparency, bool p_double_sided, bool p_billboard = false, bool p_billboard_y = false, bool p_msdf = false, bool p_no_depth = false, bool p_fixed_size = false, TextureFilter p_filter = TEXTURE_FILTER_LINEAR_WITH_MIPMAPS, AlphaAntiAliasing p_alpha_antialiasing_mode = ALPHA_ANTIALIASING_OFF, RID *r_shader_rid = nullptr);
virtual RID get_shader_rid() const override;
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index e497a628aa..1e9038139e 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -43,7 +43,7 @@
#include "scene/main/missing_node.h"
#include "scene/property_utils.h"
-#define PACKED_SCENE_VERSION 2
+#define PACKED_SCENE_VERSION 3
#define META_POINTER_PROPERTY_BASE "metadata/_editor_prop_ptr_"
bool SceneState::can_instantiate() const {
return nodes.size() > 0;
@@ -314,7 +314,19 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
//must make a copy, because this res is local to scene
}
}
- } else if (p_edit_state == GEN_EDIT_STATE_INSTANCE) {
+ }
+ if (value.get_type() == Variant::ARRAY) {
+ Array set_array = value;
+ bool is_get_valid = false;
+ Variant get_value = node->get(snames[nprops[j].name], &is_get_valid);
+ if (is_get_valid && get_value.get_type() == Variant::ARRAY) {
+ Array get_array = get_value;
+ if (!set_array.is_same_typed(get_array)) {
+ value = Array(set_array, get_array.get_typed_builtin(), get_array.get_typed_class_name(), get_array.get_typed_script());
+ }
+ }
+ }
+ if (p_edit_state == GEN_EDIT_STATE_INSTANCE && value.get_type() != Variant::OBJECT) {
value = value.duplicate(true); // Duplicate arrays and dictionaries for the editor
}
@@ -1282,6 +1294,9 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
for (int j = 0; j < cd.binds.size(); j++) {
cd.binds.write[j] = r[idx++];
}
+ if (version >= 3) {
+ cd.unbinds = r[idx++];
+ }
}
}
@@ -1368,6 +1383,7 @@ Dictionary SceneState::get_bundled_scene() const {
for (int j = 0; j < cd.binds.size(); j++) {
rconns.push_back(cd.binds[j]);
}
+ rconns.push_back(cd.unbinds);
}
d["conns"] = rconns;
diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp
index 0ba177f882..608d15019e 100644
--- a/scene/resources/resource_format_text.cpp
+++ b/scene/resources/resource_format_text.cpp
@@ -636,6 +636,18 @@ Error ResourceLoaderText::load() {
}
}
+ if (value.get_type() == Variant::ARRAY) {
+ Array set_array = value;
+ bool is_get_valid = false;
+ Variant get_value = res->get(assign, &is_get_valid);
+ if (is_get_valid && get_value.get_type() == Variant::ARRAY) {
+ Array get_array = get_value;
+ if (!set_array.is_same_typed(get_array)) {
+ value = Array(set_array, get_array.get_typed_builtin(), get_array.get_typed_class_name(), get_array.get_typed_script());
+ }
+ }
+ }
+
if (set_valid) {
res->set(assign, value);
}
@@ -746,6 +758,18 @@ Error ResourceLoaderText::load() {
}
}
+ if (value.get_type() == Variant::ARRAY) {
+ Array set_array = value;
+ bool is_get_valid = false;
+ Variant get_value = resource->get(assign, &is_get_valid);
+ if (is_get_valid && get_value.get_type() == Variant::ARRAY) {
+ Array get_array = get_value;
+ if (!set_array.is_same_typed(get_array)) {
+ value = Array(set_array, get_array.get_typed_builtin(), get_array.get_typed_class_name(), get_array.get_typed_script());
+ }
+ }
+ }
+
if (set_valid) {
resource->set(assign, value);
}
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index 5a2b917b9a..16cc1c3370 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -1307,7 +1307,8 @@ Vector<int> SurfaceTool::generate_lod(float p_threshold, int p_target_index_coun
}
float error;
- uint32_t index_count = simplify_func((unsigned int *)lod.ptrw(), (unsigned int *)index_array.ptr(), index_array.size(), vertices.ptr(), vertex_array.size(), sizeof(float) * 3, p_target_index_count, p_threshold, &error);
+ const int simplify_options = SIMPLIFY_LOCK_BORDER;
+ uint32_t index_count = simplify_func((unsigned int *)lod.ptrw(), (unsigned int *)index_array.ptr(), index_array.size(), vertices.ptr(), vertex_array.size(), sizeof(float) * 3, p_target_index_count, p_threshold, simplify_options, &error);
ERR_FAIL_COND_V(index_count == 0, lod);
lod.resize(index_count);
diff --git a/scene/resources/surface_tool.h b/scene/resources/surface_tool.h
index 00438c4a53..77318bb061 100644
--- a/scene/resources/surface_tool.h
+++ b/scene/resources/surface_tool.h
@@ -74,11 +74,16 @@ public:
SKIN_8_WEIGHTS
};
+ enum {
+ /* Do not move vertices that are located on the topological border (vertices on triangle edges that don't have a paired triangle). Useful for simplifying portions of the larger mesh. */
+ SIMPLIFY_LOCK_BORDER = 1 << 0, // From meshopt_SimplifyLockBorder
+ };
+
typedef void (*OptimizeVertexCacheFunc)(unsigned int *destination, const unsigned int *indices, size_t index_count, size_t vertex_count);
static OptimizeVertexCacheFunc optimize_vertex_cache_func;
- typedef size_t (*SimplifyFunc)(unsigned int *destination, const unsigned int *indices, size_t index_count, const float *vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t target_index_count, float target_error, float *r_error);
+ typedef size_t (*SimplifyFunc)(unsigned int *destination, const unsigned int *indices, size_t index_count, const float *vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t target_index_count, float target_error, unsigned int options, float *r_error);
static SimplifyFunc simplify_func;
- typedef size_t (*SimplifyWithAttribFunc)(unsigned int *destination, const unsigned int *indices, size_t index_count, const float *vertex_data, size_t vertex_count, size_t vertex_stride, size_t target_index_count, float target_error, float *result_error, const float *attributes, const float *attribute_weights, size_t attribute_count);
+ typedef size_t (*SimplifyWithAttribFunc)(unsigned int *destination, const unsigned int *indices, size_t index_count, const float *vertex_data, size_t vertex_count, size_t vertex_stride, size_t target_index_count, float target_error, unsigned int options, float *result_error, const float *attributes, const float *attribute_weights, size_t attribute_count);
static SimplifyWithAttribFunc simplify_with_attrib_func;
typedef float (*SimplifyScaleFunc)(const float *vertex_positions, size_t vertex_count, size_t vertex_positions_stride);
static SimplifyScaleFunc simplify_scale_func;
diff --git a/scene/resources/video_stream.cpp b/scene/resources/video_stream.cpp
new file mode 100644
index 0000000000..ee1a47c338
--- /dev/null
+++ b/scene/resources/video_stream.cpp
@@ -0,0 +1,198 @@
+/**************************************************************************/
+/* video_stream.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 "video_stream.h"
+
+#include "core/config/project_settings.h"
+#include "servers/audio_server.h"
+
+// VideoStreamPlayback starts here.
+
+void VideoStreamPlayback::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("mix_audio", "num_frames", "buffer", "offset"), &VideoStreamPlayback::mix_audio, DEFVAL(PackedFloat32Array()), DEFVAL(0));
+ GDVIRTUAL_BIND(_stop);
+ GDVIRTUAL_BIND(_play);
+ GDVIRTUAL_BIND(_is_playing);
+ GDVIRTUAL_BIND(_set_paused, "paused");
+ GDVIRTUAL_BIND(_is_paused);
+ GDVIRTUAL_BIND(_get_length);
+ GDVIRTUAL_BIND(_get_playback_position);
+ GDVIRTUAL_BIND(_seek, "time");
+ GDVIRTUAL_BIND(_set_audio_track, "idx");
+ GDVIRTUAL_BIND(_get_texture);
+ GDVIRTUAL_BIND(_update, "delta");
+ GDVIRTUAL_BIND(_get_channels);
+ GDVIRTUAL_BIND(_get_mix_rate);
+}
+
+VideoStreamPlayback::VideoStreamPlayback() {
+}
+
+VideoStreamPlayback::~VideoStreamPlayback() {
+}
+
+void VideoStreamPlayback::stop() {
+ GDVIRTUAL_CALL(_stop);
+}
+
+void VideoStreamPlayback::play() {
+ GDVIRTUAL_CALL(_play);
+}
+
+bool VideoStreamPlayback::is_playing() const {
+ bool ret;
+ if (GDVIRTUAL_CALL(_is_playing, ret)) {
+ return ret;
+ }
+ return false;
+}
+
+void VideoStreamPlayback::set_paused(bool p_paused) {
+ GDVIRTUAL_CALL(_is_playing, p_paused);
+}
+
+bool VideoStreamPlayback::is_paused() const {
+ bool ret;
+ if (GDVIRTUAL_CALL(_is_paused, ret)) {
+ return ret;
+ }
+ return false;
+}
+
+double VideoStreamPlayback::get_length() const {
+ double ret;
+ if (GDVIRTUAL_CALL(_get_length, ret)) {
+ return ret;
+ }
+ return 0;
+}
+
+double VideoStreamPlayback::get_playback_position() const {
+ double ret;
+ if (GDVIRTUAL_CALL(_get_playback_position, ret)) {
+ return ret;
+ }
+ return 0;
+}
+
+void VideoStreamPlayback::seek(double p_time) {
+ GDVIRTUAL_CALL(_seek, p_time);
+}
+
+void VideoStreamPlayback::set_audio_track(int p_idx) {
+ GDVIRTUAL_CALL(_set_audio_track, p_idx);
+}
+
+Ref<Texture2D> VideoStreamPlayback::get_texture() const {
+ Ref<Texture2D> ret;
+ if (GDVIRTUAL_CALL(_get_texture, ret)) {
+ return ret;
+ }
+ return nullptr;
+}
+
+void VideoStreamPlayback::update(double p_delta) {
+ if (!GDVIRTUAL_CALL(_update, p_delta)) {
+ ERR_FAIL_MSG("VideoStreamPlayback::update unimplemented");
+ }
+}
+
+void VideoStreamPlayback::set_mix_callback(AudioMixCallback p_callback, void *p_userdata) {
+ mix_callback = p_callback;
+ mix_udata = p_userdata;
+}
+
+int VideoStreamPlayback::get_channels() const {
+ int ret;
+ if (GDVIRTUAL_CALL(_get_channels, ret)) {
+ _channel_count = ret;
+ return ret;
+ }
+ return 0;
+}
+
+int VideoStreamPlayback::get_mix_rate() const {
+ int ret;
+ if (GDVIRTUAL_CALL(_get_mix_rate, ret)) {
+ return ret;
+ }
+ return 0;
+}
+
+int VideoStreamPlayback::mix_audio(int num_frames, PackedFloat32Array buffer, int offset) {
+ if (num_frames <= 0) {
+ return 0;
+ }
+ if (!mix_callback) {
+ return -1;
+ }
+ ERR_FAIL_INDEX_V(offset, buffer.size(), -1);
+ ERR_FAIL_INDEX_V((_channel_count < 1 ? 1 : _channel_count) * num_frames - 1, buffer.size() - offset, -1);
+ return mix_callback(mix_udata, buffer.ptr() + offset, num_frames);
+}
+
+/* --- NOTE VideoStream starts here. ----- */
+
+Ref<VideoStreamPlayback> VideoStream::instantiate_playback() {
+ Ref<VideoStreamPlayback> ret;
+ if (GDVIRTUAL_CALL(_instantiate_playback, ret)) {
+ ERR_FAIL_COND_V_MSG(ret.is_null(), nullptr, "Plugin returned null playback");
+ ret->set_audio_track(audio_track);
+ return ret;
+ }
+ return nullptr;
+}
+
+void VideoStream::set_file(const String &p_file) {
+ file = p_file;
+}
+
+String VideoStream::get_file() {
+ return file;
+}
+
+void VideoStream::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_file", "file"), &VideoStream::set_file);
+ ClassDB::bind_method(D_METHOD("get_file"), &VideoStream::get_file);
+
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "file"), "set_file", "get_file");
+
+ GDVIRTUAL_BIND(_instantiate_playback);
+}
+
+VideoStream::VideoStream() {
+}
+
+VideoStream::~VideoStream() {
+}
+
+void VideoStream::set_audio_track(int p_track) {
+ audio_track = p_track;
+}
diff --git a/scene/resources/video_stream.h b/scene/resources/video_stream.h
index f83c621d0a..b91a7acf35 100644
--- a/scene/resources/video_stream.h
+++ b/scene/resources/video_stream.h
@@ -31,6 +31,7 @@
#ifndef VIDEO_STREAM_H
#define VIDEO_STREAM_H
+#include "core/io/file_access.h"
#include "scene/resources/texture.h"
class VideoStreamPlayback : public Resource {
@@ -39,40 +40,77 @@ class VideoStreamPlayback : public Resource {
public:
typedef int (*AudioMixCallback)(void *p_udata, const float *p_data, int p_frames);
- virtual void stop() = 0;
- virtual void play() = 0;
+protected:
+ AudioMixCallback mix_callback = nullptr;
+ void *mix_udata = nullptr;
+ mutable int _channel_count = 0; // Used only to assist with bounds checking in mix_audio.
+
+ static void _bind_methods();
+ GDVIRTUAL0(_stop);
+ GDVIRTUAL0(_play);
+ GDVIRTUAL0RC(bool, _is_playing);
+ GDVIRTUAL1(_set_paused, bool);
+ GDVIRTUAL0RC(bool, _is_paused);
+ GDVIRTUAL0RC(double, _get_length);
+ GDVIRTUAL0RC(double, _get_playback_position);
+ GDVIRTUAL1(_seek, double);
+ GDVIRTUAL1(_set_audio_track, int);
+ GDVIRTUAL0RC(Ref<Texture2D>, _get_texture);
+ GDVIRTUAL1(_update, double);
+ GDVIRTUAL0RC(int, _get_channels);
+ GDVIRTUAL0RC(int, _get_mix_rate);
+
+ int mix_audio(int num_frames, PackedFloat32Array buffer = {}, int offset = 0);
- virtual bool is_playing() const = 0;
+public:
+ VideoStreamPlayback();
+ virtual ~VideoStreamPlayback();
- virtual void set_paused(bool p_paused) = 0;
- virtual bool is_paused() const = 0;
+ virtual void stop();
+ virtual void play();
- virtual void set_loop(bool p_enable) = 0;
- virtual bool has_loop() const = 0;
+ virtual bool is_playing() const;
- virtual double get_length() const = 0;
+ virtual void set_paused(bool p_paused);
+ virtual bool is_paused() const;
- virtual double get_playback_position() const = 0;
- virtual void seek(double p_time) = 0;
+ virtual double get_length() const;
- virtual void set_audio_track(int p_idx) = 0;
+ virtual double get_playback_position() const;
+ virtual void seek(double p_time);
- virtual Ref<Texture2D> get_texture() const = 0;
+ virtual void set_audio_track(int p_idx);
- virtual void update(double p_delta) = 0;
+ virtual Ref<Texture2D> get_texture() const;
+ virtual void update(double p_delta);
- virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata) = 0;
- virtual int get_channels() const = 0;
- virtual int get_mix_rate() const = 0;
+ virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata);
+ virtual int get_channels() const;
+ virtual int get_mix_rate() const;
};
class VideoStream : public Resource {
GDCLASS(VideoStream, Resource);
- OBJ_SAVE_TYPE(VideoStream); // Saves derived classes with common type so they can be interchanged.
+ OBJ_SAVE_TYPE(VideoStream);
+
+protected:
+ static void
+ _bind_methods();
+
+ GDVIRTUAL0R(Ref<VideoStreamPlayback>, _instantiate_playback);
+
+ String file;
+ int audio_track = 0;
public:
- virtual void set_audio_track(int p_track) = 0;
- virtual Ref<VideoStreamPlayback> instantiate_playback() = 0;
+ void set_file(const String &p_file);
+ String get_file();
+
+ virtual void set_audio_track(int p_track);
+ virtual Ref<VideoStreamPlayback> instantiate_playback();
+
+ VideoStream();
+ ~VideoStream();
};
#endif // VIDEO_STREAM_H
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index bfcf5cb137..4132972cb3 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -427,7 +427,10 @@ void VisualShaderNodeCustom::update_ports() {
if (!GDVIRTUAL_CALL(_get_input_port_name, i, port.name)) {
port.name = "in" + itos(i);
}
- if (!GDVIRTUAL_CALL(_get_input_port_type, i, port.type)) {
+ PortType port_type;
+ if (GDVIRTUAL_CALL(_get_input_port_type, i, port_type)) {
+ port.type = (int)port_type;
+ } else {
port.type = (int)PortType::PORT_TYPE_SCALAR;
}
@@ -445,7 +448,10 @@ void VisualShaderNodeCustom::update_ports() {
if (!GDVIRTUAL_CALL(_get_output_port_name, i, port.name)) {
port.name = "out" + itos(i);
}
- if (!GDVIRTUAL_CALL(_get_output_port_type, i, port.type)) {
+ PortType port_type;
+ if (GDVIRTUAL_CALL(_get_output_port_type, i, port_type)) {
+ port.type = (int)port_type;
+ } else {
port.type = (int)PortType::PORT_TYPE_SCALAR;
}
@@ -2702,6 +2708,7 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR_INT, "view_index", "VIEW_INDEX" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR_INT, "view_mono_left", "VIEW_MONO_LEFT" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR_INT, "view_right", "VIEW_RIGHT" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "eye_offset", "EYE_OFFSET" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "node_position_world", "NODE_POSITION_WORLD" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "camera_position_world", "CAMERA_POSITION_WORLD" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "camera_direction_world", "CAMERA_DIRECTION_WORLD" },
@@ -2736,6 +2743,7 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR_INT, "view_index", "VIEW_INDEX" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR_INT, "view_mono_left", "VIEW_MONO_LEFT" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR_INT, "view_right", "VIEW_RIGHT" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "eye_offset", "EYE_OFFSET" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "node_position_world", "NODE_POSITION_WORLD" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "camera_position_world", "CAMERA_POSITION_WORLD" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "camera_direction_world", "CAMERA_DIRECTION_WORLD" },
@@ -2936,7 +2944,7 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR_3D, "world_position", "WORLD_POSITION" },
{ Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR_3D, "object_position", "OBJECT_POSITION" },
{ Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR_3D, "uvw", "UVW" },
- { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR_3D, "extents", "EXTENTS" },
+ { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR_3D, "size", "SIZE" },
{ Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_SCALAR, "sdf", "SDF" },
{ Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },
diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h
index 0d53589fa5..fc5e48410b 100644
--- a/scene/resources/visual_shader.h
+++ b/scene/resources/visual_shader.h
@@ -369,12 +369,12 @@ protected:
GDVIRTUAL0RC(String, _get_name)
GDVIRTUAL0RC(String, _get_description)
GDVIRTUAL0RC(String, _get_category)
- GDVIRTUAL0RC(int, _get_return_icon_type)
+ GDVIRTUAL0RC(PortType, _get_return_icon_type)
GDVIRTUAL0RC(int, _get_input_port_count)
- GDVIRTUAL1RC(int, _get_input_port_type, int)
+ GDVIRTUAL1RC(PortType, _get_input_port_type, int)
GDVIRTUAL1RC(String, _get_input_port_name, int)
GDVIRTUAL0RC(int, _get_output_port_count)
- GDVIRTUAL1RC(int, _get_output_port_type, int)
+ GDVIRTUAL1RC(PortType, _get_output_port_type, int)
GDVIRTUAL1RC(String, _get_output_port_name, int)
GDVIRTUAL4RC(String, _get_code, TypedArray<String>, TypedArray<String>, Shader::Mode, VisualShader::Type)
GDVIRTUAL2RC(String, _get_func_code, Shader::Mode, VisualShader::Type)
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index 12be0f46a6..0695492e7f 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -6923,15 +6923,34 @@ void VisualShaderNodeSwitch::_bind_methods() { // static
}
String VisualShaderNodeSwitch::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
+ bool use_mix = false;
+ switch (op_type) {
+ case OP_TYPE_FLOAT: {
+ use_mix = true;
+ } break;
+ case OP_TYPE_VECTOR_2D: {
+ use_mix = true;
+ } break;
+ case OP_TYPE_VECTOR_3D: {
+ use_mix = true;
+ } break;
+ case OP_TYPE_VECTOR_4D: {
+ use_mix = true;
+ } break;
+ default: {
+ } break;
+ }
+
String code;
- code += " if(" + p_input_vars[0] + ")\n";
- code += " {\n";
- code += " " + p_output_vars[0] + " = " + p_input_vars[1] + ";\n";
- code += " }\n";
- code += " else\n";
- code += " {\n";
- code += " " + p_output_vars[0] + " = " + p_input_vars[2] + ";\n";
- code += " }\n";
+ if (use_mix) {
+ code += " " + p_output_vars[0] + " = mix(" + p_input_vars[2] + ", " + p_input_vars[1] + ", float(" + p_input_vars[0] + "));\n";
+ } else {
+ code += " if (" + p_input_vars[0] + ") {\n";
+ code += " " + p_output_vars[0] + " = " + p_input_vars[1] + ";\n";
+ code += " } else {\n";
+ code += " " + p_output_vars[0] + " = " + p_input_vars[2] + ";\n";
+ code += " }\n";
+ }
return code;
}
diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp
index 2a70139bcb..c7304da358 100644
--- a/scene/resources/world_2d.cpp
+++ b/scene/resources/world_2d.cpp
@@ -43,6 +43,14 @@ RID World2D::get_canvas() const {
}
RID World2D::get_space() const {
+ if (space.is_null()) {
+ space = PhysicsServer2D::get_singleton()->space_create();
+ PhysicsServer2D::get_singleton()->space_set_active(space, true);
+ PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_GRAVITY, GLOBAL_GET("physics/2d/default_gravity"));
+ PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_GRAVITY_VECTOR, GLOBAL_GET("physics/2d/default_gravity_vector"));
+ PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_LINEAR_DAMP, GLOBAL_GET("physics/2d/default_linear_damp"));
+ PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_ANGULAR_DAMP, GLOBAL_GET("physics/2d/default_angular_damp"));
+ }
return space;
}
@@ -71,19 +79,11 @@ void World2D::_bind_methods() {
}
PhysicsDirectSpaceState2D *World2D::get_direct_space_state() {
- return PhysicsServer2D::get_singleton()->space_get_direct_state(space);
+ return PhysicsServer2D::get_singleton()->space_get_direct_state(get_space());
}
World2D::World2D() {
canvas = RenderingServer::get_singleton()->canvas_create();
-
- // Create and configure space2D to be more friendly with pixels than meters
- space = PhysicsServer2D::get_singleton()->space_create();
- PhysicsServer2D::get_singleton()->space_set_active(space, true);
- PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_GRAVITY, GLOBAL_DEF_BASIC("physics/2d/default_gravity", 980.0));
- PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_GRAVITY_VECTOR, GLOBAL_DEF_BASIC("physics/2d/default_gravity_vector", Vector2(0, 1)));
- PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_LINEAR_DAMP, GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/2d/default_linear_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"), 0.1));
- PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_ANGULAR_DAMP, GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/2d/default_angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"), 1.0));
}
World2D::~World2D() {
@@ -91,7 +91,9 @@ World2D::~World2D() {
ERR_FAIL_NULL(PhysicsServer2D::get_singleton());
ERR_FAIL_NULL(NavigationServer2D::get_singleton());
RenderingServer::get_singleton()->free(canvas);
- PhysicsServer2D::get_singleton()->free(space);
+ if (space.is_valid()) {
+ PhysicsServer2D::get_singleton()->free(space);
+ }
if (navigation_map.is_valid()) {
NavigationServer2D::get_singleton()->free(navigation_map);
}
diff --git a/scene/resources/world_2d.h b/scene/resources/world_2d.h
index f02dddd2fe..0b3b9df7dc 100644
--- a/scene/resources/world_2d.h
+++ b/scene/resources/world_2d.h
@@ -43,7 +43,7 @@ class World2D : public Resource {
GDCLASS(World2D, Resource);
RID canvas;
- RID space;
+ mutable RID space;
mutable RID navigation_map;
HashSet<Viewport *> viewports;
diff --git a/scene/resources/world_3d.cpp b/scene/resources/world_3d.cpp
index cc4d261c0d..82c056d5ee 100644
--- a/scene/resources/world_3d.cpp
+++ b/scene/resources/world_3d.cpp
@@ -51,6 +51,14 @@ void World3D::_remove_camera(Camera3D *p_camera) {
}
RID World3D::get_space() const {
+ if (space.is_null()) {
+ space = PhysicsServer3D::get_singleton()->space_create();
+ PhysicsServer3D::get_singleton()->space_set_active(space, true);
+ PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_GRAVITY, GLOBAL_GET("physics/3d/default_gravity"));
+ PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR, GLOBAL_GET("physics/3d/default_gravity_vector"));
+ PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_LINEAR_DAMP, GLOBAL_GET("physics/3d/default_linear_damp"));
+ PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP, GLOBAL_GET("physics/3d/default_angular_damp"));
+ }
return space;
}
@@ -121,7 +129,7 @@ Ref<CameraAttributes> World3D::get_camera_attributes() const {
}
PhysicsDirectSpaceState3D *World3D::get_direct_space_state() {
- return PhysicsServer3D::get_singleton()->space_get_direct_state(space);
+ return PhysicsServer3D::get_singleton()->space_get_direct_state(get_space());
}
void World3D::_bind_methods() {
@@ -145,22 +153,18 @@ void World3D::_bind_methods() {
}
World3D::World3D() {
- space = PhysicsServer3D::get_singleton()->space_create();
scenario = RenderingServer::get_singleton()->scenario_create();
-
- PhysicsServer3D::get_singleton()->space_set_active(space, true);
- PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_GRAVITY, GLOBAL_DEF_BASIC("physics/3d/default_gravity", 9.8));
- PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR, GLOBAL_DEF_BASIC("physics/3d/default_gravity_vector", Vector3(0, -1, 0)));
- PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_LINEAR_DAMP, GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/default_linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), 0.1));
- PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP, GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "physics/3d/default_angular_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), 0.1));
}
World3D::~World3D() {
- ERR_FAIL_NULL(PhysicsServer3D::get_singleton());
ERR_FAIL_NULL(RenderingServer::get_singleton());
+ ERR_FAIL_NULL(PhysicsServer3D::get_singleton());
ERR_FAIL_NULL(NavigationServer3D::get_singleton());
- PhysicsServer3D::get_singleton()->free(space);
+
RenderingServer::get_singleton()->free(scenario);
+ if (space.is_valid()) {
+ PhysicsServer3D::get_singleton()->free(space);
+ }
if (navigation_map.is_valid()) {
NavigationServer3D::get_singleton()->free(navigation_map);
}
diff --git a/scene/resources/world_3d.h b/scene/resources/world_3d.h
index ad17daf466..518fff64e2 100644
--- a/scene/resources/world_3d.h
+++ b/scene/resources/world_3d.h
@@ -45,8 +45,8 @@ class World3D : public Resource {
GDCLASS(World3D, Resource);
private:
- RID space;
RID scenario;
+ mutable RID space;
mutable RID navigation_map;
Ref<Environment> environment;