diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/cpu_particles_2d.cpp | 4 | ||||
-rw-r--r-- | scene/3d/cpu_particles.cpp | 4 | ||||
-rw-r--r-- | scene/3d/vehicle_body.cpp | 3 | ||||
-rw-r--r-- | scene/3d/voxel_light_baker.cpp | 2 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 2 | ||||
-rw-r--r-- | scene/resources/environment.cpp | 14 | ||||
-rw-r--r-- | scene/resources/environment.h | 3 | ||||
-rw-r--r-- | scene/resources/mesh.cpp | 117 | ||||
-rw-r--r-- | scene/resources/multimesh.cpp | 95 | ||||
-rw-r--r-- | scene/resources/multimesh.h | 33 | ||||
-rw-r--r-- | scene/resources/texture.cpp | 76 | ||||
-rw-r--r-- | scene/resources/texture.h | 4 |
12 files changed, 242 insertions, 115 deletions
diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index 0e5c1b8c02..b4d1052c04 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -59,7 +59,7 @@ void CPUParticles2D::set_amount(int p_amount) { } particle_data.resize((8 + 4 + 1) * p_amount); - VS::get_singleton()->multimesh_allocate(multimesh, p_amount, VS::MULTIMESH_TRANSFORM_2D, VS::MULTIMESH_COLOR_8BIT, VS::MULTIMESH_CUSTOM_DATA_FLOAT); + VS::get_singleton()->multimesh_allocate(multimesh, p_amount, VS::MULTIMESH_TRANSFORM_2D, true, true); particle_order.resize(p_amount); } @@ -1077,7 +1077,7 @@ void CPUParticles2D::_update_render_thread() { update_mutex->lock(); #endif - VS::get_singleton()->multimesh_set_as_bulk_array(multimesh, particle_data); + VS::get_singleton()->multimesh_set_buffer(multimesh, particle_data); #ifndef NO_THREADS update_mutex->unlock(); diff --git a/scene/3d/cpu_particles.cpp b/scene/3d/cpu_particles.cpp index aa7a413548..e8760983e9 100644 --- a/scene/3d/cpu_particles.cpp +++ b/scene/3d/cpu_particles.cpp @@ -73,7 +73,7 @@ void CPUParticles::set_amount(int p_amount) { } particle_data.resize((12 + 4 + 1) * p_amount); - VS::get_singleton()->multimesh_allocate(multimesh, p_amount, VS::MULTIMESH_TRANSFORM_3D, VS::MULTIMESH_COLOR_8BIT, VS::MULTIMESH_CUSTOM_DATA_FLOAT); + VS::get_singleton()->multimesh_allocate(multimesh, p_amount, VS::MULTIMESH_TRANSFORM_3D, true, true); particle_order.resize(p_amount); } @@ -1144,7 +1144,7 @@ void CPUParticles::_update_render_thread() { update_mutex->lock(); #endif if (can_update) { - VS::get_singleton()->multimesh_set_as_bulk_array(multimesh, particle_data); + VS::get_singleton()->multimesh_set_buffer(multimesh, particle_data); can_update = false; //wait for next time } diff --git a/scene/3d/vehicle_body.cpp b/scene/3d/vehicle_body.cpp index 92b17d5056..52e50aa84e 100644 --- a/scene/3d/vehicle_body.cpp +++ b/scene/3d/vehicle_body.cpp @@ -364,9 +364,8 @@ VehicleWheel::VehicleWheel() { steers = false; engine_traction = false; - m_steering = real_t(0.); - //m_engineForce = real_t(0.); + m_engineForce = real_t(0.); m_rotation = real_t(0.); m_deltaRotation = real_t(0.); m_brake = real_t(0.); diff --git a/scene/3d/voxel_light_baker.cpp b/scene/3d/voxel_light_baker.cpp index 1b6e328342..db8d7f0851 100644 --- a/scene/3d/voxel_light_baker.cpp +++ b/scene/3d/voxel_light_baker.cpp @@ -2339,7 +2339,7 @@ Ref<MultiMesh> VoxelLightBaker::create_debug_multimesh(DebugMode p_mode) { mm.instance(); mm->set_transform_format(MultiMesh::TRANSFORM_3D); - mm->set_color_format(MultiMesh::COLOR_8BIT); + mm->set_use_colors(true); mm->set_instance_count(leaf_voxel_count); Ref<ArrayMesh> mesh; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 976c66ad0c..19edf556fb 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -300,7 +300,7 @@ void Viewport::_notification(int p_what) { //3D PhysicsServer::get_singleton()->space_set_debug_contacts(find_world()->get_space(), get_tree()->get_collision_debug_contact_count()); contact_3d_debug_multimesh = VisualServer::get_singleton()->multimesh_create(); - VisualServer::get_singleton()->multimesh_allocate(contact_3d_debug_multimesh, get_tree()->get_collision_debug_contact_count(), VS::MULTIMESH_TRANSFORM_3D, VS::MULTIMESH_COLOR_8BIT); + VisualServer::get_singleton()->multimesh_allocate(contact_3d_debug_multimesh, get_tree()->get_collision_debug_contact_count(), VS::MULTIMESH_TRANSFORM_3D, true); VisualServer::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh, 0); VisualServer::get_singleton()->multimesh_set_mesh(contact_3d_debug_multimesh, get_tree()->get_debug_contact_mesh()->get_rid()); contact_3d_debug_instance = VisualServer::get_singleton()->instance_create(); diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index 5e18e73b5b..4ee8962702 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -937,6 +937,20 @@ float Environment::get_fog_height_curve() const { return fog_height_curve; } +#ifndef DISABLE_DEPRECATED +bool Environment::_set(const StringName &p_name, const Variant &p_value) { + if (p_name == "background_sky") { + set_sky(p_value); + return true; + } else if (p_name == "background_sky_custom_fov") { + set_sky_custom_fov(p_value); + return true; + } else { + return false; + } +} +#endif + void Environment::_bind_methods() { ClassDB::bind_method(D_METHOD("set_background", "mode"), &Environment::set_background); diff --git a/scene/resources/environment.h b/scene/resources/environment.h index 30f96e97fd..69f18c3424 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -194,6 +194,9 @@ private: protected: static void _bind_methods(); virtual void _validate_property(PropertyInfo &property) const; +#ifndef DISABLE_DEPRECATED + bool _set(const StringName &p_name, const Variant &p_value); +#endif public: void set_background(BGMode p_bg); diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 96c609174f..e102d944e8 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -590,6 +590,89 @@ Vector<Ref<Shape> > Mesh::convex_decompose() const { Mesh::Mesh() { } +static PoolVector<uint8_t> _fix_array_compatibility(const PoolVector<uint8_t> &p_src, uint32_t p_format, uint32_t p_elements) { + + bool vertex_16bit = p_format & ((1 << (Mesh::ARRAY_VERTEX + Mesh::ARRAY_COMPRESS_BASE))); + bool bone_32_bits = (p_format & Mesh::ARRAY_FORMAT_BONES) && !(p_format & (Mesh::ARRAY_COMPRESS_INDEX << 2)); + + print_line("convert vertex16: " + itos(vertex_16bit) + " bone 32 " + itos(bone_32_bits)); + if (!vertex_16bit && !bone_32_bits) { + return p_src; + } + + bool vertex_2d = (p_format & (Mesh::ARRAY_COMPRESS_INDEX << 1)); + + uint32_t src_stride = p_src.size() / p_elements; + uint32_t dst_stride = src_stride + (vertex_16bit ? 4 : 0) - (bone_32_bits ? 16 : 0); + + PoolVector<uint8_t> ret; + ret.resize(dst_stride * p_elements); + { + PoolVector<uint8_t>::Write w = ret.write(); + PoolVector<uint8_t>::Read r = p_src.read(); + + for (uint32_t i = 0; i < p_elements; i++) { + + uint32_t remaining = src_stride; + const uint8_t *src = (const uint8_t *)(r.ptr() + src_stride * i); + uint8_t *dst = (uint8_t *)(w.ptr() + dst_stride * i); + + if (!vertex_2d) { //3D + if (vertex_16bit) { + float *dstw = (float *)dst; + const uint16_t *srcr = (const uint16_t *)src; + dstw[0] = Math::half_to_float(srcr[0]); + dstw[1] = Math::half_to_float(srcr[1]); + dstw[2] = Math::half_to_float(srcr[2]); + remaining -= 8; + src += 8; + } else { + src += 12; + remaining -= 12; + } + dst += 12; + } else { + if (vertex_16bit) { + float *dstw = (float *)dst; + const uint16_t *srcr = (const uint16_t *)src; + dstw[0] = Math::half_to_float(srcr[0]); + dstw[1] = Math::half_to_float(srcr[1]); + remaining -= 4; + src += 4; + } else { + src += 8; + remaining -= 8; + } + dst += 8; + } + + if (bone_32_bits) { + + const uint32_t *src_bones = (const uint32_t *)&src[remaining - 32]; + const float *src_weights = (const float *)&src[remaining - 16]; + uint16_t *dstw = (uint16_t *)&dst[remaining - 32]; + + dstw[0] = src_bones[0]; + dstw[1] = src_bones[1]; + dstw[2] = src_bones[2]; + dstw[3] = src_bones[3]; + dstw[4] = CLAMP(src_weights[0] * 65535, 0, 65535); //16bits unorm + dstw[5] = CLAMP(src_weights[1] * 65535, 0, 65535); + dstw[6] = CLAMP(src_weights[2] * 65535, 0, 65535); + dstw[7] = CLAMP(src_weights[3] * 65535, 0, 65535); + + remaining -= 32; + } + + for (uint32_t j = 0; j < remaining; j++) { + dst[j] = src[j]; + } + } + } + + return ret; +} + bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { String sname = p_name; @@ -624,11 +707,11 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { return true; } -#ifdef ENABLE_DEPRECATED +#ifndef DISABLE_DEPRECATED if (!sname.begins_with("surfaces")) return false; - WARN_DEPRECATED("Mesh uses old surface format, which is deprecated (and loads slower). Consider re-importing or re-saving the scene."); + WARN_DEPRECATED_MSG("Mesh uses old surface format, which is deprecated (and loads slower). Consider re-importing or re-saving the scene."); int idx = sname.get_slicec('/', 1).to_int(); String what = sname.get_slicec('/', 2); @@ -640,12 +723,13 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { ERR_FAIL_COND_V(!d.has("primitive"), false); if (d.has("arrays")) { - //old format + //oldest format (2.x) ERR_FAIL_COND_V(!d.has("morph_arrays"), false); add_surface_from_arrays(PrimitiveType(int(d["primitive"])), d["arrays"], d["morph_arrays"]); } else if (d.has("array_data")) { - + print_line("array data (old style"); + //older format (3.x) PoolVector<uint8_t> array_data = d["array_data"]; PoolVector<uint8_t> array_index_data; if (d.has("array_index_data")) @@ -655,16 +739,24 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { uint32_t format = d["format"]; uint32_t primitive = d["primitive"]; - if (primitive > PRIMITIVE_LINE_STRIP) { - primitive--; //line loop was deprecated, so it's not supported and indices go down by one - } - if (primitive > PRIMITIVE_TRIANGLE_STRIP) { - primitive = PRIMITIVE_TRIANGLE_STRIP; //fan is no longer supported - } + + uint32_t primitive_remap[7] = { + PRIMITIVE_POINTS, + PRIMITIVE_LINES, + PRIMITIVE_LINE_STRIP, + PRIMITIVE_LINES, + PRIMITIVE_TRIANGLES, + PRIMITIVE_TRIANGLE_STRIP, + PRIMITIVE_TRIANGLE_STRIP + }; + + primitive = primitive_remap[primitive]; //compatibility ERR_FAIL_COND_V(!d.has("vertex_count"), false); int vertex_count = d["vertex_count"]; + array_data = _fix_array_compatibility(array_data, format, vertex_count); + int index_count = 0; if (d.has("index_count")) index_count = d["index_count"]; @@ -675,10 +767,15 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { Array blend_shape_data = d["blend_shape_data"]; for (int i = 0; i < blend_shape_data.size(); i++) { PoolVector<uint8_t> shape = blend_shape_data[i]; + shape = _fix_array_compatibility(shape, format, vertex_count); + blend_shapes.push_back(shape); } } + //clear unused flags + format &= ~((1 << (ARRAY_VERTEX + ARRAY_COMPRESS_BASE)) | (ARRAY_COMPRESS_INDEX << 2)); + ERR_FAIL_COND_V(!d.has("aabb"), false); AABB aabb = d["aabb"]; diff --git a/scene/resources/multimesh.cpp b/scene/resources/multimesh.cpp index ee831f36f5..946511c766 100644 --- a/scene/resources/multimesh.cpp +++ b/scene/resources/multimesh.cpp @@ -31,6 +31,8 @@ #include "multimesh.h" #include "servers/visual_server.h" +#ifndef DISABLE_DEPRECATED + void MultiMesh::_set_transform_array(const PoolVector<Vector3> &p_array) { if (transform_format != TRANSFORM_3D) return; @@ -146,7 +148,7 @@ void MultiMesh::_set_color_array(const PoolVector<Color> &p_array) { PoolVector<Color> MultiMesh::_get_color_array() const { - if (instance_count == 0 || color_format == COLOR_NONE) + if (instance_count == 0 || !use_colors) return PoolVector<Color>(); PoolVector<Color> colors; @@ -178,7 +180,7 @@ void MultiMesh::_set_custom_data_array(const PoolVector<Color> &p_array) { PoolVector<Color> MultiMesh::_get_custom_data_array() const { - if (instance_count == 0 || custom_data_format == CUSTOM_DATA_NONE) + if (instance_count == 0 || !use_custom_data) return PoolVector<Color>(); PoolVector<Color> custom_datas; @@ -191,6 +193,16 @@ PoolVector<Color> MultiMesh::_get_custom_data_array() const { return custom_datas; } + +#endif +void MultiMesh::set_buffer(const PoolVector<float> &p_buffer) { + VS::get_singleton()->multimesh_set_buffer(multimesh, p_buffer); +} + +PoolVector<float> MultiMesh::get_buffer() const { + return VS::get_singleton()->multimesh_get_buffer(multimesh); +} + void MultiMesh::set_mesh(const Ref<Mesh> &p_mesh) { mesh = p_mesh; @@ -207,7 +219,7 @@ Ref<Mesh> MultiMesh::get_mesh() const { void MultiMesh::set_instance_count(int p_count) { ERR_FAIL_COND(p_count < 0); - VisualServer::get_singleton()->multimesh_allocate(multimesh, p_count, VS::MultimeshTransformFormat(transform_format), VS::MultimeshColorFormat(color_format), VS::MultimeshCustomDataFormat(custom_data_format)); + VisualServer::get_singleton()->multimesh_allocate(multimesh, p_count, VS::MultimeshTransformFormat(transform_format), use_colors, use_custom_data); instance_count = p_count; } int MultiMesh::get_instance_count() const { @@ -217,6 +229,7 @@ int MultiMesh::get_instance_count() const { void MultiMesh::set_visible_instance_count(int p_count) { ERR_FAIL_COND(p_count < -1); + ERR_FAIL_COND(p_count > instance_count); VisualServer::get_singleton()->multimesh_set_visible_instances(multimesh, p_count); visible_instance_count = p_count; } @@ -263,11 +276,6 @@ Color MultiMesh::get_instance_custom_data(int p_instance) const { return VisualServer::get_singleton()->multimesh_instance_get_custom_data(multimesh, p_instance); } -void MultiMesh::set_as_bulk_array(const PoolVector<float> &p_array) { - - VisualServer::get_singleton()->multimesh_set_as_bulk_array(multimesh, p_array); -} - AABB MultiMesh::get_aabb() const { return VisualServer::get_singleton()->multimesh_get_aabb(multimesh); @@ -278,26 +286,22 @@ RID MultiMesh::get_rid() const { return multimesh; } -void MultiMesh::set_color_format(ColorFormat p_color_format) { - +void MultiMesh::set_use_colors(bool p_enable) { ERR_FAIL_COND(instance_count > 0); - color_format = p_color_format; + use_colors = p_enable; } -MultiMesh::ColorFormat MultiMesh::get_color_format() const { - - return color_format; +bool MultiMesh::is_using_colors() const { + return use_colors; } -void MultiMesh::set_custom_data_format(CustomDataFormat p_custom_data_format) { - +void MultiMesh::set_use_custom_data(bool p_enable) { ERR_FAIL_COND(instance_count > 0); - custom_data_format = p_custom_data_format; + use_custom_data = p_enable; } -MultiMesh::CustomDataFormat MultiMesh::get_custom_data_format() const { - - return custom_data_format; +bool MultiMesh::is_using_custom_data() const { + return use_custom_data; } void MultiMesh::set_transform_format(TransformFormat p_transform_format) { @@ -314,10 +318,10 @@ void MultiMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &MultiMesh::set_mesh); ClassDB::bind_method(D_METHOD("get_mesh"), &MultiMesh::get_mesh); - ClassDB::bind_method(D_METHOD("set_color_format", "format"), &MultiMesh::set_color_format); - ClassDB::bind_method(D_METHOD("get_color_format"), &MultiMesh::get_color_format); - ClassDB::bind_method(D_METHOD("set_custom_data_format", "format"), &MultiMesh::set_custom_data_format); - ClassDB::bind_method(D_METHOD("get_custom_data_format"), &MultiMesh::get_custom_data_format); + ClassDB::bind_method(D_METHOD("set_use_colors", "enable"), &MultiMesh::set_use_colors); + ClassDB::bind_method(D_METHOD("is_using_colors"), &MultiMesh::is_using_colors); + ClassDB::bind_method(D_METHOD("set_use_custom_data", "enable"), &MultiMesh::set_use_custom_data); + ClassDB::bind_method(D_METHOD("is_using_custom_data"), &MultiMesh::is_using_custom_data); ClassDB::bind_method(D_METHOD("set_transform_format", "format"), &MultiMesh::set_transform_format); ClassDB::bind_method(D_METHOD("get_transform_format"), &MultiMesh::get_transform_format); @@ -333,9 +337,22 @@ void MultiMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("get_instance_color", "instance"), &MultiMesh::get_instance_color); ClassDB::bind_method(D_METHOD("set_instance_custom_data", "instance", "custom_data"), &MultiMesh::set_instance_custom_data); ClassDB::bind_method(D_METHOD("get_instance_custom_data", "instance"), &MultiMesh::get_instance_custom_data); - ClassDB::bind_method(D_METHOD("set_as_bulk_array", "array"), &MultiMesh::set_as_bulk_array); ClassDB::bind_method(D_METHOD("get_aabb"), &MultiMesh::get_aabb); + ClassDB::bind_method(D_METHOD("get_buffer"), &MultiMesh::get_buffer); + ClassDB::bind_method(D_METHOD("set_buffer", "buffer"), &MultiMesh::set_buffer); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "transform_format", PROPERTY_HINT_ENUM, "2D,3D"), "set_transform_format", "get_transform_format"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_colors"), "set_use_colors", "is_using_colors"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_custom_data"), "set_use_custom_data", "is_using_custom_data"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "instance_count", PROPERTY_HINT_RANGE, "0,16384,1,or_greater"), "set_instance_count", "get_instance_count"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_instance_count", PROPERTY_HINT_RANGE, "-1,16384,1,or_greater"), "set_visible_instance_count", "get_visible_instance_count"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh"); + ADD_PROPERTY(PropertyInfo(Variant::POOL_REAL_ARRAY, "buffer", PROPERTY_HINT_NONE), "set_buffer", "get_buffer"); + +#ifndef DISABLE_DEPRECATED + //kept for compatibility + ClassDB::bind_method(D_METHOD("_set_transform_array"), &MultiMesh::_set_transform_array); ClassDB::bind_method(D_METHOD("_get_transform_array"), &MultiMesh::_get_transform_array); ClassDB::bind_method(D_METHOD("_set_transform_2d_array"), &MultiMesh::_set_transform_2d_array); @@ -345,34 +362,20 @@ void MultiMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_custom_data_array"), &MultiMesh::_set_custom_data_array); ClassDB::bind_method(D_METHOD("_get_custom_data_array"), &MultiMesh::_get_custom_data_array); - ADD_PROPERTY(PropertyInfo(Variant::INT, "color_format", PROPERTY_HINT_ENUM, "None,Byte,Float"), "set_color_format", "get_color_format"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "transform_format", PROPERTY_HINT_ENUM, "2D,3D"), "set_transform_format", "get_transform_format"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "custom_data_format", PROPERTY_HINT_ENUM, "None,Byte,Float"), "set_custom_data_format", "get_custom_data_format"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "instance_count", PROPERTY_HINT_RANGE, "0,16384,1,or_greater"), "set_instance_count", "get_instance_count"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_instance_count", PROPERTY_HINT_RANGE, "-1,16384,1,or_greater"), "set_visible_instance_count", "get_visible_instance_count"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh"); - ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR3_ARRAY, "transform_array", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_transform_array", "_get_transform_array"); - ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "transform_2d_array", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_transform_2d_array", "_get_transform_2d_array"); - ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "color_array", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_color_array", "_get_color_array"); - ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "custom_data_array", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_custom_data_array", "_get_custom_data_array"); - + ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR3_ARRAY, "transform_array", PROPERTY_HINT_NONE, "", 0), "_set_transform_array", "_get_transform_array"); + ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "transform_2d_array", PROPERTY_HINT_NONE, "", 0), "_set_transform_2d_array", "_get_transform_2d_array"); + ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "color_array", PROPERTY_HINT_NONE, "", 0), "_set_color_array", "_get_color_array"); + ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "custom_data_array", PROPERTY_HINT_NONE, "", 0), "_set_custom_data_array", "_get_custom_data_array"); +#endif BIND_ENUM_CONSTANT(TRANSFORM_2D); BIND_ENUM_CONSTANT(TRANSFORM_3D); - - BIND_ENUM_CONSTANT(COLOR_NONE); - BIND_ENUM_CONSTANT(COLOR_8BIT); - BIND_ENUM_CONSTANT(COLOR_FLOAT); - - BIND_ENUM_CONSTANT(CUSTOM_DATA_NONE); - BIND_ENUM_CONSTANT(CUSTOM_DATA_8BIT); - BIND_ENUM_CONSTANT(CUSTOM_DATA_FLOAT); } MultiMesh::MultiMesh() { multimesh = VisualServer::get_singleton()->multimesh_create(); - color_format = COLOR_NONE; - custom_data_format = CUSTOM_DATA_NONE; + use_colors = false; + use_custom_data = false; transform_format = TRANSFORM_2D; visible_instance_count = -1; instance_count = 0; diff --git a/scene/resources/multimesh.h b/scene/resources/multimesh.h index 9394737799..e7d62d0993 100644 --- a/scene/resources/multimesh.h +++ b/scene/resources/multimesh.h @@ -45,30 +45,20 @@ public: TRANSFORM_3D = VS::MULTIMESH_TRANSFORM_3D }; - enum ColorFormat { - COLOR_NONE = VS::MULTIMESH_COLOR_NONE, - COLOR_8BIT = VS::MULTIMESH_COLOR_8BIT, - COLOR_FLOAT = VS::MULTIMESH_COLOR_FLOAT, - }; - - enum CustomDataFormat { - CUSTOM_DATA_NONE, - CUSTOM_DATA_8BIT, - CUSTOM_DATA_FLOAT, - }; - private: Ref<Mesh> mesh; RID multimesh; TransformFormat transform_format; - ColorFormat color_format; - CustomDataFormat custom_data_format; + bool use_colors; + bool use_custom_data; int instance_count; int visible_instance_count; protected: static void _bind_methods(); +#ifndef DISABLE_DEPRECATED + void _set_transform_array(const PoolVector<Vector3> &p_array); PoolVector<Vector3> _get_transform_array() const; @@ -80,16 +70,19 @@ protected: void _set_custom_data_array(const PoolVector<Color> &p_array); PoolVector<Color> _get_custom_data_array() const; +#endif + void set_buffer(const PoolVector<float> &p_buffer); + PoolVector<float> get_buffer() const; public: void set_mesh(const Ref<Mesh> &p_mesh); Ref<Mesh> get_mesh() const; - void set_color_format(ColorFormat p_color_format); - ColorFormat get_color_format() const; + void set_use_colors(bool p_enable); + bool is_using_colors() const; - void set_custom_data_format(CustomDataFormat p_custom_data_format); - CustomDataFormat get_custom_data_format() const; + void set_use_custom_data(bool p_enable); + bool is_using_custom_data() const; void set_transform_format(TransformFormat p_transform_format); TransformFormat get_transform_format() const; @@ -111,8 +104,6 @@ public: void set_instance_custom_data(int p_instance, const Color &p_custom_data); Color get_instance_custom_data(int p_instance) const; - void set_as_bulk_array(const PoolVector<float> &p_array); - virtual AABB get_aabb() const; virtual RID get_rid() const; @@ -122,7 +113,5 @@ public: }; VARIANT_ENUM_CAST(MultiMesh::TransformFormat); -VARIANT_ENUM_CAST(MultiMesh::ColorFormat); -VARIANT_ENUM_CAST(MultiMesh::CustomDataFormat); #endif // MULTI_MESH_H diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 7085171043..c0311aca3a 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -394,7 +394,7 @@ Image::Format StreamTexture::get_format() const { return format; } -Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, Ref<Image> &image, int p_size_limit) { +Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, Ref<Image> &image, bool &r_request_3d, bool &r_request_normal, bool &r_request_roughness, int p_size_limit) { alpha_cache.unref(); @@ -420,29 +420,16 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &tw_ #ifdef TOOLS_ENABLED - if (request_3d_callback && df & FORMAT_BIT_DETECT_3D) { - //print_line("request detect 3D at " + p_path); - VS::get_singleton()->texture_set_detect_3d_callback(texture, _requested_3d, this); - } else { - //print_line("not requesting detect 3D at " + p_path); - VS::get_singleton()->texture_set_detect_3d_callback(texture, NULL, NULL); - } + r_request_3d = request_3d_callback && df & FORMAT_BIT_DETECT_3D; + r_request_roughness = request_roughness_callback && df & FORMAT_BIT_DETECT_ROUGNESS; + r_request_normal = request_normal_callback && df & FORMAT_BIT_DETECT_NORMAL; - if (request_roughness_callback && df & FORMAT_BIT_DETECT_ROUGNESS) { - //print_line("request detect srgb at " + p_path); - VS::get_singleton()->texture_set_detect_roughness_callback(texture, _requested_roughness, this); - } else { - //print_line("not requesting detect srgb at " + p_path); - VS::get_singleton()->texture_set_detect_roughness_callback(texture, NULL, NULL); - } +#else + + r_request_3d = false; + r_request_roughness = false; + r_request_normal = false; - if (request_normal_callback && df & FORMAT_BIT_DETECT_NORMAL) { - //print_line("request detect srgb at " + p_path); - VS::get_singleton()->texture_set_detect_normal_callback(texture, _requested_normal, this); - } else { - //print_line("not requesting detect normal at " + p_path); - VS::get_singleton()->texture_set_detect_normal_callback(texture, NULL, NULL); - } #endif if (!(df & FORMAT_BIT_STREAM)) { p_size_limit = 0; @@ -607,7 +594,7 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &tw_ } } - return ERR_BUG; //unreachable + ERR_FAIL_V(ERR_BUG); //unreachable } Error StreamTexture::load(const String &p_path) { @@ -615,14 +602,15 @@ Error StreamTexture::load(const String &p_path) { int lw, lh, lwc, lhc; Ref<Image> image; image.instance(); - Error err = _load_data(p_path, lw, lh, lwc, lhc, image); + + bool request_3d; + bool request_normal; + bool request_roughness; + + Error err = _load_data(p_path, lw, lh, lwc, lhc, image, request_3d, request_normal, request_roughness); if (err) return err; - if (get_path() == String()) { - //temporarily set path if no path set for resource, helps find errors - VisualServer::get_singleton()->texture_set_path(texture, p_path); - } if (texture.is_valid()) { RID new_texture = VS::get_singleton()->texture_2d_create(image); VS::get_singleton()->texture_replace(texture, new_texture); @@ -638,6 +626,38 @@ Error StreamTexture::load(const String &p_path) { path_to_file = p_path; format = image->get_format(); + if (get_path() == String()) { + //temporarily set path if no path set for resource, helps find errors + VisualServer::get_singleton()->texture_set_path(texture, p_path); + } + +#ifdef TOOLS_ENABLED + + if (request_3d) { + //print_line("request detect 3D at " + p_path); + VS::get_singleton()->texture_set_detect_3d_callback(texture, _requested_3d, this); + } else { + //print_line("not requesting detect 3D at " + p_path); + VS::get_singleton()->texture_set_detect_3d_callback(texture, NULL, NULL); + } + + if (request_roughness) { + //print_line("request detect srgb at " + p_path); + VS::get_singleton()->texture_set_detect_roughness_callback(texture, _requested_roughness, this); + } else { + //print_line("not requesting detect srgb at " + p_path); + VS::get_singleton()->texture_set_detect_roughness_callback(texture, NULL, NULL); + } + + if (request_normal) { + //print_line("request detect srgb at " + p_path); + VS::get_singleton()->texture_set_detect_normal_callback(texture, _requested_normal, this); + } else { + //print_line("not requesting detect normal at " + p_path); + VS::get_singleton()->texture_set_detect_normal_callback(texture, NULL, NULL); + } + +#endif _change_notify(); emit_changed(); return OK; diff --git a/scene/resources/texture.h b/scene/resources/texture.h index c18368fb85..173556da72 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -155,7 +155,7 @@ public: }; private: - Error _load_data(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, Ref<Image> &image, int p_size_limit = 0); + Error _load_data(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, Ref<Image> &image, bool &r_request_3d, bool &r_request_normal, bool &r_request_roughness, int p_size_limit = 0); String path_to_file; mutable RID texture; Image::Format format; @@ -390,6 +390,7 @@ public: class Cubemap : public TextureLayered { GDCLASS(Cubemap, TextureLayered); + public: Cubemap() : TextureLayered(VS::TEXTURE_LAYERED_CUBEMAP) {} @@ -398,6 +399,7 @@ public: class CubemapArray : public TextureLayered { GDCLASS(CubemapArray, TextureLayered); + public: CubemapArray() : TextureLayered(VS::TEXTURE_LAYERED_CUBEMAP_ARRAY) {} |