summaryrefslogtreecommitdiff
path: root/scene/resources/mesh.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/mesh.cpp')
-rw-r--r--scene/resources/mesh.cpp139
1 files changed, 67 insertions, 72 deletions
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index 58463abad8..08c4169167 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -63,9 +63,9 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const {
if (facecount == 0 || (facecount % 3) != 0)
return triangle_mesh;
- PoolVector<Vector3> faces;
+ Vector<Vector3> faces;
faces.resize(facecount);
- PoolVector<Vector3>::Write facesw = faces.write();
+ Vector3 *facesw = faces.ptrw();
int widx = 0;
@@ -78,14 +78,14 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const {
ERR_FAIL_COND_V(a.empty(), Ref<TriangleMesh>());
int vc = surface_get_array_len(i);
- PoolVector<Vector3> vertices = a[ARRAY_VERTEX];
- PoolVector<Vector3>::Read vr = vertices.read();
+ Vector<Vector3> vertices = a[ARRAY_VERTEX];
+ const Vector3 *vr = vertices.ptr();
if (surface_get_format(i) & ARRAY_FORMAT_INDEX) {
int ic = surface_get_array_index_len(i);
- PoolVector<int> indices = a[ARRAY_INDEX];
- PoolVector<int>::Read ir = indices.read();
+ Vector<int> indices = a[ARRAY_INDEX];
+ const int *ir = indices.ptr();
for (int j = 0; j < ic; j++) {
int index = ir[j];
@@ -99,8 +99,6 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const {
}
}
- facesw.release();
-
triangle_mesh = Ref<TriangleMesh>(memnew(TriangleMesh));
triangle_mesh->create(faces);
@@ -118,15 +116,15 @@ void Mesh::generate_debug_mesh_lines(Vector<Vector3> &r_lines) {
if (tm.is_null())
return;
- PoolVector<int> triangle_indices;
+ Vector<int> triangle_indices;
tm->get_indices(&triangle_indices);
const int triangles_num = tm->get_triangles().size();
- PoolVector<Vector3> vertices = tm->get_vertices();
+ Vector<Vector3> vertices = tm->get_vertices();
debug_lines.resize(tm->get_triangles().size() * 6); // 3 lines x 2 points each line
- PoolVector<int>::Read ind_r = triangle_indices.read();
- PoolVector<Vector3>::Read ver_r = vertices.read();
+ const int *ind_r = triangle_indices.ptr();
+ const Vector3 *ver_r = vertices.ptr();
for (int j = 0, x = 0, i = 0; i < triangles_num; j += 6, x += 3, ++i) {
// Triangle line 1
debug_lines.write[j + 0] = ver_r[ind_r[x + 0]];
@@ -148,7 +146,7 @@ void Mesh::generate_debug_mesh_indices(Vector<Vector3> &r_points) {
if (tm.is_null())
return;
- PoolVector<Vector3> vertices = tm->get_vertices();
+ Vector<Vector3> vertices = tm->get_vertices();
int vertices_size = vertices.size();
r_points.resize(vertices_size);
@@ -162,20 +160,20 @@ bool Mesh::surface_is_softbody_friendly(int p_idx) const {
return (surface_format & Mesh::ARRAY_FLAG_USE_DYNAMIC_UPDATE && (!(surface_format & Mesh::ARRAY_COMPRESS_NORMAL)));
}
-PoolVector<Face3> Mesh::get_faces() const {
+Vector<Face3> Mesh::get_faces() const {
Ref<TriangleMesh> tm = generate_triangle_mesh();
if (tm.is_valid())
return tm->get_faces();
- return PoolVector<Face3>();
+ return Vector<Face3>();
/*
for (int i=0;i<surfaces.size();i++) {
if (VisualServer::get_singleton()->mesh_surface_get_primitive_type( mesh, i ) != VisualServer::PRIMITIVE_TRIANGLES )
continue;
- PoolVector<int> indices;
- PoolVector<Vector3> vertices;
+ Vector<int> indices;
+ Vector<Vector3> vertices;
vertices=VisualServer::get_singleton()->mesh_surface_get_array(mesh, i,VisualServer::ARRAY_VERTEX);
@@ -196,10 +194,10 @@ PoolVector<Face3> Mesh::get_faces() const {
if (len<=0)
continue;
- PoolVector<int>::Read indicesr = indices.read();
+ const int* indicesr = indices.ptr();
const int *indicesptr = indicesr.ptr();
- PoolVector<Vector3>::Read verticesr = vertices.read();
+ const Vector3* verticesr = vertices.ptr();
const Vector3 *verticesptr = verticesr.ptr();
int old_faces=faces.size();
@@ -207,7 +205,7 @@ PoolVector<Face3> Mesh::get_faces() const {
faces.resize(new_faces);
- PoolVector<Face3>::Write facesw = faces.write();
+ Face3* facesw = faces.ptrw();
Face3 *facesptr=facesw.ptr();
@@ -230,13 +228,13 @@ PoolVector<Face3> Mesh::get_faces() const {
Ref<Shape> Mesh::create_convex_shape() const {
- PoolVector<Vector3> vertices;
+ Vector<Vector3> vertices;
for (int i = 0; i < get_surface_count(); i++) {
Array a = surface_get_arrays(i);
ERR_FAIL_COND_V(a.empty(), Ref<ConvexPolygonShape>());
- PoolVector<Vector3> v = a[ARRAY_VERTEX];
+ Vector<Vector3> v = a[ARRAY_VERTEX];
vertices.append_array(v);
}
@@ -247,11 +245,11 @@ Ref<Shape> Mesh::create_convex_shape() const {
Ref<Shape> Mesh::create_trimesh_shape() const {
- PoolVector<Face3> faces = get_faces();
+ Vector<Face3> faces = get_faces();
if (faces.size() == 0)
return Ref<Shape>();
- PoolVector<Vector3> face_points;
+ Vector<Vector3> face_points;
face_points.resize(faces.size() * 3);
for (int i = 0; i < face_points.size(); i++) {
@@ -279,7 +277,7 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
if (i == 0) {
arrays = a;
- PoolVector<Vector3> v = a[ARRAY_VERTEX];
+ Vector<Vector3> v = a[ARRAY_VERTEX];
index_accum += v.size();
} else {
@@ -297,8 +295,8 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
case ARRAY_VERTEX:
case ARRAY_NORMAL: {
- PoolVector<Vector3> dst = arrays[j];
- PoolVector<Vector3> src = a[j];
+ Vector<Vector3> dst = arrays[j];
+ Vector<Vector3> src = a[j];
if (j == ARRAY_VERTEX)
vcount = src.size();
if (dst.size() == 0 || src.size() == 0) {
@@ -312,8 +310,8 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
case ARRAY_BONES:
case ARRAY_WEIGHTS: {
- PoolVector<real_t> dst = arrays[j];
- PoolVector<real_t> src = a[j];
+ Vector<real_t> dst = arrays[j];
+ Vector<real_t> src = a[j];
if (dst.size() == 0 || src.size() == 0) {
arrays[j] = Variant();
continue;
@@ -323,8 +321,8 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
} break;
case ARRAY_COLOR: {
- PoolVector<Color> dst = arrays[j];
- PoolVector<Color> src = a[j];
+ Vector<Color> dst = arrays[j];
+ Vector<Color> src = a[j];
if (dst.size() == 0 || src.size() == 0) {
arrays[j] = Variant();
continue;
@@ -335,8 +333,8 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
} break;
case ARRAY_TEX_UV:
case ARRAY_TEX_UV2: {
- PoolVector<Vector2> dst = arrays[j];
- PoolVector<Vector2> src = a[j];
+ Vector<Vector2> dst = arrays[j];
+ Vector<Vector2> src = a[j];
if (dst.size() == 0 || src.size() == 0) {
arrays[j] = Variant();
continue;
@@ -346,15 +344,15 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
} break;
case ARRAY_INDEX: {
- PoolVector<int> dst = arrays[j];
- PoolVector<int> src = a[j];
+ Vector<int> dst = arrays[j];
+ Vector<int> src = a[j];
if (dst.size() == 0 || src.size() == 0) {
arrays[j] = Variant();
continue;
}
{
int ss = src.size();
- PoolVector<int>::Write w = src.write();
+ int *w = src.ptrw();
for (int k = 0; k < ss; k++) {
w[k] += index_accum;
}
@@ -372,18 +370,18 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
ERR_FAIL_COND_V(arrays.size() != ARRAY_MAX, Ref<ArrayMesh>());
{
- PoolVector<int>::Write ir;
- PoolVector<int> indices = arrays[ARRAY_INDEX];
+ int *ir;
+ Vector<int> indices = arrays[ARRAY_INDEX];
bool has_indices = false;
- PoolVector<Vector3> vertices = arrays[ARRAY_VERTEX];
+ Vector<Vector3> vertices = arrays[ARRAY_VERTEX];
int vc = vertices.size();
ERR_FAIL_COND_V(!vc, Ref<ArrayMesh>());
- PoolVector<Vector3>::Write r = vertices.write();
+ Vector3 *r = vertices.ptrw();
if (indices.size()) {
ERR_FAIL_COND_V(indices.size() % 3 != 0, Ref<ArrayMesh>());
vc = indices.size();
- ir = indices.write();
+ ir = indices.ptrw();
has_indices = true;
}
@@ -440,14 +438,13 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
r[i] = t;
}
- r.release();
arrays[ARRAY_VERTEX] = vertices;
if (!has_indices) {
- PoolVector<int> new_indices;
+ Vector<int> new_indices;
new_indices.resize(vertices.size());
- PoolVector<int>::Write iw = new_indices.write();
+ int *iw = new_indices.ptrw();
for (int j = 0; j < vc2; j += 3) {
@@ -456,7 +453,6 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
iw[j + 2] = j + 1;
}
- iw.release();
arrays[ARRAY_INDEX] = new_indices;
} else {
@@ -465,7 +461,6 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
SWAP(ir[j + 1], ir[j + 2]);
}
- ir.release();
arrays[ARRAY_INDEX] = indices;
}
}
@@ -548,10 +543,10 @@ Vector<Ref<Shape> > Mesh::convex_decompose() const {
ERR_FAIL_COND_V(!convex_composition_function, Vector<Ref<Shape> >());
- PoolVector<Face3> faces = get_faces();
+ Vector<Face3> faces = get_faces();
Vector<Face3> f3;
f3.resize(faces.size());
- PoolVector<Face3>::Read f = faces.read();
+ const Face3 *f = faces.ptr();
for (int i = 0; i < f3.size(); i++) {
f3.write[i] = f[i];
}
@@ -568,10 +563,10 @@ Vector<Ref<Shape> > Mesh::convex_decompose() const {
points.insert(decomposed[i][j].vertex[2]);
}
- PoolVector<Vector3> convex_points;
+ Vector<Vector3> convex_points;
convex_points.resize(points.size());
{
- PoolVector<Vector3>::Write w = convex_points.write();
+ Vector3 *w = convex_points.ptrw();
int idx = 0;
for (Set<Vector3>::Element *E = points.front(); E; E = E->next()) {
w[idx++] = E->get();
@@ -590,7 +585,7 @@ 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) {
+static Vector<uint8_t> _fix_array_compatibility(const Vector<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 has_bones = (p_format & Mesh::ARRAY_FORMAT_BONES);
@@ -608,18 +603,18 @@ static PoolVector<uint8_t> _fix_array_compatibility(const PoolVector<uint8_t> &p
uint32_t src_stride = p_src.size() / p_elements;
uint32_t dst_stride = src_stride + (vertex_16bit ? 4 : 0) + (bone_8 ? 4 : 0) - (weight_32 ? 8 : 0);
- PoolVector<uint8_t> ret = p_src;
+ Vector<uint8_t> ret = p_src;
ret.resize(dst_stride * p_elements);
{
- PoolVector<uint8_t>::Write w = ret.write();
- PoolVector<uint8_t>::Read r = p_src.read();
+ uint8_t *w = ret.ptrw();
+ const uint8_t *r = p_src.ptr();
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);
+ const uint8_t *src = (const uint8_t *)(r + src_stride * i);
+ uint8_t *dst = (uint8_t *)(w + dst_stride * i);
if (!vertex_2d) { //3D
if (vertex_16bit) {
@@ -714,9 +709,9 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) {
if (p_name == "blend_shape/names") {
- PoolVector<String> sk = p_value;
+ Vector<String> sk = p_value;
int sz = sk.size();
- PoolVector<String>::Read r = sk.read();
+ const String *r = sk.ptr();
for (int i = 0; i < sz; i++)
add_blend_shape(r[i]);
return true;
@@ -766,8 +761,8 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) {
} 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;
+ Vector<uint8_t> array_data = d["array_data"];
+ Vector<uint8_t> array_index_data;
if (d.has("array_index_data"))
array_index_data = d["array_index_data"];
@@ -797,12 +792,12 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) {
if (d.has("index_count"))
index_count = d["index_count"];
- Vector<PoolVector<uint8_t> > blend_shapes;
+ Vector<Vector<uint8_t> > blend_shapes;
if (d.has("blend_shape_data")) {
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];
+ Vector<uint8_t> shape = blend_shape_data[i];
shape = _fix_array_compatibility(shape, format, vertex_count);
blend_shapes.push_back(shape);
@@ -1049,7 +1044,7 @@ bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const {
if (p_name == "blend_shape/names") {
- PoolVector<String> sk;
+ Vector<String> sk;
for (int i = 0; i < blend_shapes.size(); i++)
sk.push_back(blend_shapes[i]);
r_ret = sk;
@@ -1081,7 +1076,7 @@ void ArrayMesh::_get_property_list(List<PropertyInfo> *p_list) const {
return;
if (blend_shapes.size()) {
- p_list->push_back(PropertyInfo(Variant::POOL_STRING_ARRAY, "blend_shape/names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
+ p_list->push_back(PropertyInfo(Variant::PACKED_STRING_ARRAY, "blend_shape/names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
p_list->push_back(PropertyInfo(Variant::INT, "blend_shape/mode", PROPERTY_HINT_ENUM, "Normalized,Relative"));
}
@@ -1112,7 +1107,7 @@ void ArrayMesh::_recompute_aabb() {
#ifndef _MSC_VER
#warning need to add binding to add_surface using future MeshSurfaceData object
#endif
-void ArrayMesh::add_surface(uint32_t p_format, PrimitiveType p_primitive, const PoolVector<uint8_t> &p_array, int p_vertex_count, const PoolVector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<PoolVector<uint8_t> > &p_blend_shapes, const Vector<AABB> &p_bone_aabb, const Vector<VS::SurfaceData::LOD> &p_lods) {
+void ArrayMesh::add_surface(uint32_t p_format, PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t> > &p_blend_shapes, const Vector<AABB> &p_bone_aabb, const Vector<VS::SurfaceData::LOD> &p_lods) {
_create_if_empty();
@@ -1293,7 +1288,7 @@ String ArrayMesh::surface_get_name(int p_idx) const {
return surfaces[p_idx].name;
}
-void ArrayMesh::surface_update_region(int p_surface, int p_offset, const PoolVector<uint8_t> &p_data) {
+void ArrayMesh::surface_update_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data) {
ERR_FAIL_INDEX(p_surface, surfaces.size());
VS::get_singleton()->mesh_surface_update_region(mesh, p_surface, p_offset, p_data);
@@ -1404,12 +1399,12 @@ Error ArrayMesh::lightmap_unwrap(const Transform &p_base_transform, float p_texe
s.material = surface_get_material(i);
s.vertices = SurfaceTool::create_vertex_array_from_triangle_arrays(arrays);
- PoolVector<Vector3> rvertices = arrays[Mesh::ARRAY_VERTEX];
+ Vector<Vector3> rvertices = arrays[Mesh::ARRAY_VERTEX];
int vc = rvertices.size();
- PoolVector<Vector3>::Read r = rvertices.read();
+ const Vector3 *r = rvertices.ptr();
- PoolVector<Vector3> rnormals = arrays[Mesh::ARRAY_NORMAL];
- PoolVector<Vector3>::Read rn = rnormals.read();
+ Vector<Vector3> rnormals = arrays[Mesh::ARRAY_NORMAL];
+ const Vector3 *rn = rnormals.ptr();
int vertex_ofs = vertices.size() / 3;
@@ -1431,7 +1426,7 @@ Error ArrayMesh::lightmap_unwrap(const Transform &p_base_transform, float p_texe
uv_index.write[j + vertex_ofs] = Pair<int, int>(i, j);
}
- PoolVector<int> rindices = arrays[Mesh::ARRAY_INDEX];
+ Vector<int> rindices = arrays[Mesh::ARRAY_INDEX];
int ic = rindices.size();
if (ic == 0) {
@@ -1447,7 +1442,7 @@ Error ArrayMesh::lightmap_unwrap(const Transform &p_base_transform, float p_texe
}
} else {
- PoolVector<int>::Read ri = rindices.read();
+ const int *ri = rindices.ptr();
for (int j = 0; j < ic / 3; j++) {
if (Face3(r[ri[j * 3 + 0]], r[ri[j * 3 + 1]], r[ri[j * 3 + 2]]).is_degenerate())