void ArrayMesh::add_surface_from_mesh_data(const Geometry::MeshData &p_mesh_data) { VisualServer::get_singleton()->mesh_add_surface_from_mesh_data(mesh, p_mesh_data); AABB aabb; for (int i = 0; i < p_mesh_data.vertices.size(); i++) { if (i == 0) aabb.position = p_mesh_data.vertices[i]; else aabb.expand_to(p_mesh_data.vertices[i]); } Surface s; s.aabb = aabb; if (surfaces.size() == 0) aabb = s.aabb; else aabb.merge_with(s.aabb); _clear_triangle_mesh(); surfaces.push_back(s); _change_notify(); emit_changed(); }
/** PrimitiveMesh */ void PrimitiveMesh::_update() const { Array arr; arr.resize(VS::ARRAY_MAX); _create_mesh_array(arr); PoolVector<Vector3> points = arr[VS::ARRAY_VERTEX]; aabb = AABB(); int pc = points.size(); ERR_FAIL_COND(pc == 0); { PoolVector<Vector3>::Read r = points.read(); for (int i = 0; i < pc; i++) { if (i == 0) aabb.position = r[i]; else aabb.expand_to(r[i]); } } // in with the new VisualServer::get_singleton()->mesh_clear(mesh); VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh, (VisualServer::PrimitiveType)primitive_type, arr); VisualServer::get_singleton()->mesh_surface_set_material(mesh, 0, material.is_null() ? RID() : material->get_rid()); pending_request = false; _clear_triangle_mesh(); }
void ArrayMesh::surface_remove(int p_idx) { ERR_FAIL_INDEX(p_idx, surfaces.size()); VisualServer::get_singleton()->mesh_remove_surface(mesh, p_idx); surfaces.remove(p_idx); _clear_triangle_mesh(); _recompute_aabb(); _change_notify(); emit_changed(); }
void ArrayMesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, uint32_t p_flags) { ERR_FAIL_COND(p_arrays.size() != ARRAY_MAX); Surface s; VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh, (VisualServer::PrimitiveType)p_primitive, p_arrays, p_blend_shapes, p_flags); surfaces.push_back(s); /* make aABB? */ { Variant arr = p_arrays[ARRAY_VERTEX]; PoolVector<Vector3> vertices = arr; int len = vertices.size(); ERR_FAIL_COND(len == 0); PoolVector<Vector3>::Read r = vertices.read(); const Vector3 *vtx = r.ptr(); // check AABB AABB aabb; for (int i = 0; i < len; i++) { if (i == 0) aabb.position = vtx[i]; else aabb.expand_to(vtx[i]); } surfaces[surfaces.size() - 1].aabb = aabb; surfaces[surfaces.size() - 1].is_2d = arr.get_type() == Variant::POOL_VECTOR2_ARRAY; _recompute_aabb(); } _clear_triangle_mesh(); _change_notify(); emit_changed(); }