@@ -107,63 +107,37 @@ Ref<ArrayMesh> Shape3D::get_debug_mesh() {
107107 debug_mesh_cache.instantiate ();
108108
109109 if (!lines.is_empty ()) {
110- // make mesh
111- Vector<Vector3> array;
112- array.resize (lines.size ());
113- Vector3 *v = array.ptrw ();
114-
115- Vector<Color> arraycol;
116- arraycol.resize (lines.size ());
117- Color *c = arraycol.ptrw ();
118-
119- for (int i = 0 ; i < lines.size (); i++) {
120- v[i] = lines[i];
121- c[i] = debug_color;
122- }
110+ Vector<Color> colors;
111+ colors.resize (lines.size ());
112+ colors.fill (debug_color);
123113
124114 Array lines_array;
125115 lines_array.resize (Mesh::ARRAY_MAX);
126- lines_array[Mesh::ARRAY_VERTEX] = array;
127- lines_array[Mesh::ARRAY_COLOR] = arraycol;
128-
129- Ref<StandardMaterial3D> material = get_debug_collision_material ();
116+ lines_array[Mesh::ARRAY_VERTEX] = lines;
117+ lines_array[Mesh::ARRAY_COLOR] = colors;
130118
131119 debug_mesh_cache->add_surface_from_arrays (Mesh::PRIMITIVE_LINES, lines_array);
132- debug_mesh_cache->surface_set_material (0 , material);
120+
121+ SceneTree *scene_tree = SceneTree::get_singleton ();
122+ if (scene_tree) {
123+ debug_mesh_cache->surface_set_material (0 , scene_tree->get_debug_collision_material ());
124+ }
133125
134126 if (debug_fill) {
135127 Ref<ArrayMesh> array_mesh = get_debug_arraymesh_faces (debug_color * Color (1.0 , 1.0 , 1.0 , 0.0625 ));
136128 if (array_mesh.is_valid () && array_mesh->get_surface_count () > 0 ) {
137129 Array solid_array = array_mesh->surface_get_arrays (0 );
138130 debug_mesh_cache->add_surface_from_arrays (Mesh::PRIMITIVE_TRIANGLES, solid_array);
139- debug_mesh_cache->surface_set_material (1 , material);
131+ if (scene_tree) {
132+ debug_mesh_cache->surface_set_material (1 , scene_tree->get_debug_collision_material ());
133+ }
140134 }
141135 }
142136 }
143137
144138 return debug_mesh_cache;
145139}
146140
147- Ref<Material> Shape3D::get_debug_collision_material () {
148- if (collision_material.is_valid ()) {
149- return collision_material;
150- }
151-
152- Ref<StandardMaterial3D> material = memnew (StandardMaterial3D);
153- material->set_albedo (Color (1.0 , 1.0 , 1.0 ));
154- material->set_shading_mode (StandardMaterial3D::SHADING_MODE_UNSHADED);
155- material->set_transparency (StandardMaterial3D::TRANSPARENCY_ALPHA);
156- material->set_render_priority (StandardMaterial3D::RENDER_PRIORITY_MIN + 1 );
157- material->set_cull_mode (StandardMaterial3D::CULL_BACK);
158- material->set_flag (StandardMaterial3D::FLAG_DISABLE_FOG, true );
159- material->set_flag (StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true );
160- material->set_flag (StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true );
161-
162- collision_material = material;
163-
164- return collision_material;
165- }
166-
167141void Shape3D::_update_shape () {
168142 emit_changed ();
169143 debug_mesh_cache.unref ();
0 commit comments