2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* mesh.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-08 00:11:42 +02:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* 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 "mesh.h"
|
|
|
|
#include "scene/resources/concave_polygon_shape.h"
|
|
|
|
#include "scene/resources/convex_polygon_shape.h"
|
2014-10-14 06:01:25 +02:00
|
|
|
#include "surface_tool.h"
|
2016-07-08 00:32:28 +02:00
|
|
|
|
2017-07-23 23:48:05 +02:00
|
|
|
void Mesh::_clear_triangle_mesh() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
triangle_mesh.unref();
|
|
|
|
;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<TriangleMesh> Mesh::generate_triangle_mesh() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (triangle_mesh.is_valid())
|
|
|
|
return triangle_mesh;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int facecount = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int i = 0; i < get_surface_count(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES)
|
|
|
|
continue;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (surface_get_format(i) & ARRAY_FORMAT_INDEX) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
facecount += surface_get_array_index_len(i);
|
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
facecount += surface_get_array_len(i);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (facecount == 0 || (facecount % 3) != 0)
|
|
|
|
return triangle_mesh;
|
2014-05-14 06:22:15 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<Vector3> faces;
|
|
|
|
faces.resize(facecount);
|
|
|
|
PoolVector<Vector3>::Write facesw = faces.write();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int widx = 0;
|
2014-05-05 03:50:23 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int i = 0; i < get_surface_count(); i++) {
|
2014-05-05 03:50:23 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES)
|
|
|
|
continue;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Array a = surface_get_arrays(i);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int vc = surface_get_array_len(i);
|
|
|
|
PoolVector<Vector3> vertices = a[ARRAY_VERTEX];
|
|
|
|
PoolVector<Vector3>::Read vr = vertices.read();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (surface_get_format(i) & ARRAY_FORMAT_INDEX) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int ic = surface_get_array_index_len(i);
|
|
|
|
PoolVector<int> indices = a[ARRAY_INDEX];
|
|
|
|
PoolVector<int>::Read ir = indices.read();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int i = 0; i < ic; i++) {
|
|
|
|
int index = ir[i];
|
|
|
|
facesw[widx++] = vr[index];
|
|
|
|
}
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
} else {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int i = 0; i < vc; i++)
|
|
|
|
facesw[widx++] = vr[i];
|
|
|
|
}
|
|
|
|
}
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
facesw = PoolVector<Vector3>::Write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
triangle_mesh = Ref<TriangleMesh>(memnew(TriangleMesh));
|
|
|
|
triangle_mesh->create(faces);
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
return triangle_mesh;
|
|
|
|
}
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<Face3> Mesh::get_faces() const {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<TriangleMesh> tm = generate_triangle_mesh();
|
|
|
|
if (tm.is_valid())
|
|
|
|
return tm->get_faces();
|
|
|
|
return PoolVector<Face3>();
|
|
|
|
/*
|
|
|
|
for (int i=0;i<surfaces.size();i++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (VisualServer::get_singleton()->mesh_surface_get_primitive_type( mesh, i ) != VisualServer::PRIMITIVE_TRIANGLES )
|
|
|
|
continue;
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<int> indices;
|
|
|
|
PoolVector<Vector3> vertices;
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
vertices=VisualServer::get_singleton()->mesh_surface_get_array(mesh, i,VisualServer::ARRAY_VERTEX);
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int len=VisualServer::get_singleton()->mesh_surface_get_array_index_len(mesh, i);
|
|
|
|
bool has_indices;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (len>0) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
indices=VisualServer::get_singleton()->mesh_surface_get_array(mesh, i,VisualServer::ARRAY_INDEX);
|
|
|
|
has_indices=true;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
len=vertices.size();
|
|
|
|
has_indices=false;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (len<=0)
|
|
|
|
continue;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<int>::Read indicesr = indices.read();
|
|
|
|
const int *indicesptr = indicesr.ptr();
|
2017-04-07 04:36:37 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<Vector3>::Read verticesr = vertices.read();
|
|
|
|
const Vector3 *verticesptr = verticesr.ptr();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int old_faces=faces.size();
|
|
|
|
int new_faces=old_faces+(len/3);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
faces.resize(new_faces);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<Face3>::Write facesw = faces.write();
|
|
|
|
Face3 *facesptr=facesw.ptr();
|
2014-05-14 06:22:15 +02:00
|
|
|
|
2014-05-05 03:50:23 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int i=0;i<len/3;i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Face3 face;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int j=0;j<3;j++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int idx=i*3+j;
|
|
|
|
face.vertex[j] = has_indices ? verticesptr[ indicesptr[ idx ] ] : verticesptr[idx];
|
|
|
|
}
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
facesptr[i+old_faces]=face;
|
|
|
|
}
|
2016-11-10 03:55:06 +01:00
|
|
|
|
|
|
|
}
|
2017-06-07 23:18:55 +02:00
|
|
|
*/
|
|
|
|
}
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<Shape> Mesh::create_convex_shape() const {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<Vector3> vertices;
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int i = 0; i < get_surface_count(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Array a = surface_get_arrays(i);
|
|
|
|
PoolVector<Vector3> v = a[ARRAY_VERTEX];
|
|
|
|
vertices.append_array(v);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<ConvexPolygonShape> shape = memnew(ConvexPolygonShape);
|
|
|
|
shape->set_points(vertices);
|
|
|
|
return shape;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<Shape> Mesh::create_trimesh_shape() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<Face3> faces = get_faces();
|
|
|
|
if (faces.size() == 0)
|
|
|
|
return Ref<Shape>();
|
2017-04-07 04:36:37 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<Vector3> face_points;
|
|
|
|
face_points.resize(faces.size() * 3);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int i = 0; i < face_points.size(); i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Face3 f = faces.get(i / 3);
|
|
|
|
face_points.set(i, f.vertex[i % 3]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2014-05-05 03:50:23 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<ConcavePolygonShape> shape = memnew(ConcavePolygonShape);
|
|
|
|
shape->set_faces(face_points);
|
|
|
|
return shape;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<Mesh> Mesh::create_outline(float p_margin) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Array arrays;
|
|
|
|
int index_accum = 0;
|
|
|
|
for (int i = 0; i < get_surface_count(); i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES)
|
|
|
|
continue;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Array a = surface_get_arrays(i);
|
|
|
|
int vcount = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (i == 0) {
|
|
|
|
arrays = a;
|
|
|
|
PoolVector<Vector3> v = a[ARRAY_VERTEX];
|
|
|
|
index_accum += v.size();
|
|
|
|
} else {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int j = 0; j < arrays.size(); j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (arrays[j].get_type() == Variant::NIL || a[j].get_type() == Variant::NIL) {
|
|
|
|
//mismatch, do not use
|
|
|
|
arrays[j] = Variant();
|
|
|
|
continue;
|
|
|
|
}
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
switch (j) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
case ARRAY_VERTEX:
|
|
|
|
case ARRAY_NORMAL: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<Vector3> dst = arrays[j];
|
|
|
|
PoolVector<Vector3> src = a[j];
|
|
|
|
if (j == ARRAY_VERTEX)
|
|
|
|
vcount = src.size();
|
|
|
|
if (dst.size() == 0 || src.size() == 0) {
|
|
|
|
arrays[j] = Variant();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dst.append_array(src);
|
|
|
|
arrays[j] = dst;
|
|
|
|
} break;
|
|
|
|
case ARRAY_TANGENT:
|
|
|
|
case ARRAY_BONES:
|
|
|
|
case ARRAY_WEIGHTS: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<real_t> dst = arrays[j];
|
|
|
|
PoolVector<real_t> src = a[j];
|
|
|
|
if (dst.size() == 0 || src.size() == 0) {
|
|
|
|
arrays[j] = Variant();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dst.append_array(src);
|
|
|
|
arrays[j] = dst;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
} break;
|
|
|
|
case ARRAY_COLOR: {
|
|
|
|
PoolVector<Color> dst = arrays[j];
|
|
|
|
PoolVector<Color> src = a[j];
|
|
|
|
if (dst.size() == 0 || src.size() == 0) {
|
|
|
|
arrays[j] = Variant();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dst.append_array(src);
|
|
|
|
arrays[j] = dst;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
} break;
|
|
|
|
case ARRAY_TEX_UV:
|
|
|
|
case ARRAY_TEX_UV2: {
|
|
|
|
PoolVector<Vector2> dst = arrays[j];
|
|
|
|
PoolVector<Vector2> src = a[j];
|
|
|
|
if (dst.size() == 0 || src.size() == 0) {
|
|
|
|
arrays[j] = Variant();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dst.append_array(src);
|
|
|
|
arrays[j] = dst;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
} break;
|
|
|
|
case ARRAY_INDEX: {
|
|
|
|
PoolVector<int> dst = arrays[j];
|
|
|
|
PoolVector<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();
|
|
|
|
for (int k = 0; k < ss; k++) {
|
|
|
|
w[k] += index_accum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst.append_array(src);
|
|
|
|
arrays[j] = dst;
|
|
|
|
index_accum += vcount;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-06-07 23:18:55 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
{
|
|
|
|
PoolVector<int>::Write ir;
|
|
|
|
PoolVector<int> indices = arrays[ARRAY_INDEX];
|
|
|
|
bool has_indices = false;
|
|
|
|
PoolVector<Vector3> vertices = arrays[ARRAY_VERTEX];
|
|
|
|
int vc = vertices.size();
|
|
|
|
ERR_FAIL_COND_V(!vc, Ref<ArrayMesh>());
|
|
|
|
PoolVector<Vector3>::Write r = vertices.write();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (indices.size()) {
|
|
|
|
vc = indices.size();
|
|
|
|
ir = indices.write();
|
|
|
|
has_indices = true;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Map<Vector3, Vector3> normal_accum;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
//fill normals with triangle normals
|
|
|
|
for (int i = 0; i < vc; i += 3) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Vector3 t[3];
|
|
|
|
|
|
|
|
if (has_indices) {
|
|
|
|
t[0] = r[ir[i + 0]];
|
|
|
|
t[1] = r[ir[i + 1]];
|
|
|
|
t[2] = r[ir[i + 2]];
|
|
|
|
} else {
|
|
|
|
t[0] = r[i + 0];
|
|
|
|
t[1] = r[i + 1];
|
|
|
|
t[2] = r[i + 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 n = Plane(t[0], t[1], t[2]).normal;
|
|
|
|
|
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
|
|
|
|
Map<Vector3, Vector3>::Element *E = normal_accum.find(t[j]);
|
|
|
|
if (!E) {
|
|
|
|
normal_accum[t[j]] = n;
|
|
|
|
} else {
|
|
|
|
float d = n.dot(E->get());
|
|
|
|
if (d < 1.0)
|
|
|
|
E->get() += n * (1.0 - d);
|
|
|
|
//E->get()+=n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//normalize
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (Map<Vector3, Vector3>::Element *E = normal_accum.front(); E; E = E->next()) {
|
|
|
|
E->get().normalize();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
//displace normals
|
|
|
|
int vc2 = vertices.size();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int i = 0; i < vc2; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Vector3 t = r[i];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Map<Vector3, Vector3>::Element *E = normal_accum.find(t);
|
|
|
|
ERR_CONTINUE(!E);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
t += E->get() * p_margin;
|
|
|
|
r[i] = t;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
r = PoolVector<Vector3>::Write();
|
|
|
|
arrays[ARRAY_VERTEX] = vertices;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (!has_indices) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<int> new_indices;
|
|
|
|
new_indices.resize(vertices.size());
|
|
|
|
PoolVector<int>::Write iw = new_indices.write();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int j = 0; j < vc2; j += 3) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
iw[j] = j;
|
|
|
|
iw[j + 1] = j + 2;
|
|
|
|
iw[j + 2] = j + 1;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
iw = PoolVector<int>::Write();
|
|
|
|
arrays[ARRAY_INDEX] = new_indices;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int j = 0; j < vc; j += 3) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
SWAP(ir[j + 1], ir[j + 2]);
|
|
|
|
}
|
|
|
|
ir = PoolVector<int>::Write();
|
|
|
|
arrays[ARRAY_INDEX] = indices;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<ArrayMesh> newmesh = memnew(ArrayMesh);
|
|
|
|
newmesh->add_surface_from_arrays(PRIMITIVE_TRIANGLES, arrays);
|
|
|
|
return newmesh;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-14 00:15:55 +02:00
|
|
|
void Mesh::_bind_methods() {
|
|
|
|
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(PRIMITIVE_POINTS);
|
|
|
|
BIND_ENUM_CONSTANT(PRIMITIVE_LINES);
|
|
|
|
BIND_ENUM_CONSTANT(PRIMITIVE_LINE_STRIP);
|
|
|
|
BIND_ENUM_CONSTANT(PRIMITIVE_LINE_LOOP);
|
|
|
|
BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLES);
|
|
|
|
BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLE_STRIP);
|
|
|
|
BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLE_FAN);
|
2017-07-14 00:15:55 +02:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Mesh::Mesh() {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
static const char *_array_name[] = {
|
|
|
|
"vertex_array",
|
|
|
|
"normal_array",
|
|
|
|
"tangent_array",
|
|
|
|
"color_array",
|
|
|
|
"tex_uv_array",
|
|
|
|
"tex_uv2_array",
|
|
|
|
"bone_array",
|
|
|
|
"weights_array",
|
|
|
|
"index_array",
|
|
|
|
NULL
|
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
static const ArrayMesh::ArrayType _array_types[] = {
|
|
|
|
|
|
|
|
ArrayMesh::ARRAY_VERTEX,
|
|
|
|
ArrayMesh::ARRAY_NORMAL,
|
|
|
|
ArrayMesh::ARRAY_TANGENT,
|
|
|
|
ArrayMesh::ARRAY_COLOR,
|
|
|
|
ArrayMesh::ARRAY_TEX_UV,
|
|
|
|
ArrayMesh::ARRAY_TEX_UV2,
|
|
|
|
ArrayMesh::ARRAY_BONES,
|
|
|
|
ArrayMesh::ARRAY_WEIGHTS,
|
|
|
|
ArrayMesh::ARRAY_INDEX
|
|
|
|
};
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
/* compatibility */
|
|
|
|
static const int _format_translate[] = {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ArrayMesh::ARRAY_FORMAT_VERTEX,
|
|
|
|
ArrayMesh::ARRAY_FORMAT_NORMAL,
|
|
|
|
ArrayMesh::ARRAY_FORMAT_TANGENT,
|
|
|
|
ArrayMesh::ARRAY_FORMAT_COLOR,
|
|
|
|
ArrayMesh::ARRAY_FORMAT_TEX_UV,
|
|
|
|
ArrayMesh::ARRAY_FORMAT_TEX_UV2,
|
|
|
|
ArrayMesh::ARRAY_FORMAT_BONES,
|
|
|
|
ArrayMesh::ARRAY_FORMAT_WEIGHTS,
|
|
|
|
ArrayMesh::ARRAY_FORMAT_INDEX,
|
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
String sname = p_name;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (p_name == "blend_shape/names") {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<String> sk = p_value;
|
|
|
|
int sz = sk.size();
|
|
|
|
PoolVector<String>::Read r = sk.read();
|
|
|
|
for (int i = 0; i < sz; i++)
|
|
|
|
add_blend_shape(r[i]);
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (p_name == "blend_shape/mode") {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
set_blend_shape_mode(BlendShapeMode(int(p_value)));
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (sname.begins_with("surface_")) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int sl = sname.find("/");
|
|
|
|
if (sl == -1)
|
|
|
|
return false;
|
|
|
|
int idx = sname.substr(8, sl - 8).to_int() - 1;
|
|
|
|
String what = sname.get_slicec('/', 1);
|
|
|
|
if (what == "material")
|
|
|
|
surface_set_material(idx, p_value);
|
|
|
|
else if (what == "name")
|
|
|
|
surface_set_name(idx, p_value);
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (sname == "custom_aabb/custom_aabb") {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
set_custom_aabb(p_value);
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (!sname.begins_with("surfaces"))
|
|
|
|
return false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int idx = sname.get_slicec('/', 1).to_int();
|
|
|
|
String what = sname.get_slicec('/', 2);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (idx == surfaces.size()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
//create
|
|
|
|
Dictionary d = p_value;
|
|
|
|
ERR_FAIL_COND_V(!d.has("primitive"), false);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (d.has("arrays")) {
|
|
|
|
//old format
|
|
|
|
ERR_FAIL_COND_V(!d.has("morph_arrays"), false);
|
|
|
|
add_surface_from_arrays(PrimitiveType(int(d["primitive"])), d["arrays"], d["morph_arrays"]);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
} else if (d.has("array_data")) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<uint8_t> array_data = d["array_data"];
|
|
|
|
PoolVector<uint8_t> array_index_data;
|
|
|
|
if (d.has("array_index_data"))
|
|
|
|
array_index_data = d["array_index_data"];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_COND_V(!d.has("format"), false);
|
|
|
|
uint32_t format = d["format"];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_COND_V(!d.has("primitive"), false);
|
|
|
|
uint32_t primitive = d["primitive"];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_COND_V(!d.has("vertex_count"), false);
|
|
|
|
int vertex_count = d["vertex_count"];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int index_count = 0;
|
|
|
|
if (d.has("index_count"))
|
|
|
|
index_count = d["index_count"];
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Vector<PoolVector<uint8_t> > blend_shapes;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
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];
|
|
|
|
blend_shapes.push_back(shape);
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_COND_V(!d.has("aabb"), false);
|
|
|
|
Rect3 aabb = d["aabb"];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Vector<Rect3> bone_aabb;
|
|
|
|
if (d.has("bone_aabb")) {
|
|
|
|
Array baabb = d["bone_aabb"];
|
|
|
|
bone_aabb.resize(baabb.size());
|
2016-05-27 19:18:40 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int i = 0; i < baabb.size(); i++) {
|
|
|
|
bone_aabb[i] = baabb[i];
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
add_surface(format, PrimitiveType(primitive), array_data, vertex_count, array_index_data, index_count, aabb, blend_shapes, bone_aabb);
|
|
|
|
} else {
|
|
|
|
ERR_FAIL_V(false);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (d.has("material")) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
surface_set_material(idx, d["material"]);
|
|
|
|
}
|
|
|
|
if (d.has("name")) {
|
|
|
|
surface_set_name(idx, d["name"]);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-05-05 03:50:23 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
return false;
|
2014-05-05 03:50:23 +02:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const {
|
2014-05-05 03:50:23 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (_is_generated())
|
|
|
|
return false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
String sname = p_name;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (p_name == "blend_shape/names") {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<String> sk;
|
|
|
|
for (int i = 0; i < blend_shapes.size(); i++)
|
|
|
|
sk.push_back(blend_shapes[i]);
|
|
|
|
r_ret = sk;
|
|
|
|
return true;
|
|
|
|
} else if (p_name == "blend_shape/mode") {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
r_ret = get_blend_shape_mode();
|
|
|
|
return true;
|
|
|
|
} else if (sname.begins_with("surface_")) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int sl = sname.find("/");
|
|
|
|
if (sl == -1)
|
|
|
|
return false;
|
|
|
|
int idx = sname.substr(8, sl - 8).to_int() - 1;
|
|
|
|
String what = sname.get_slicec('/', 1);
|
|
|
|
if (what == "material")
|
|
|
|
r_ret = surface_get_material(idx);
|
|
|
|
else if (what == "name")
|
|
|
|
r_ret = surface_get_name(idx);
|
|
|
|
return true;
|
|
|
|
} else if (sname == "custom_aabb/custom_aabb") {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
r_ret = custom_aabb;
|
|
|
|
return true;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
} else if (!sname.begins_with("surfaces"))
|
|
|
|
return false;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int idx = sname.get_slicec('/', 1).to_int();
|
|
|
|
ERR_FAIL_INDEX_V(idx, surfaces.size(), false);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Dictionary d;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
d["array_data"] = VS::get_singleton()->mesh_surface_get_array(mesh, idx);
|
|
|
|
d["vertex_count"] = VS::get_singleton()->mesh_surface_get_array_len(mesh, idx);
|
|
|
|
d["array_index_data"] = VS::get_singleton()->mesh_surface_get_index_array(mesh, idx);
|
|
|
|
d["index_count"] = VS::get_singleton()->mesh_surface_get_array_index_len(mesh, idx);
|
|
|
|
d["primitive"] = VS::get_singleton()->mesh_surface_get_primitive_type(mesh, idx);
|
|
|
|
d["format"] = VS::get_singleton()->mesh_surface_get_format(mesh, idx);
|
|
|
|
d["aabb"] = VS::get_singleton()->mesh_surface_get_aabb(mesh, idx);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Vector<Rect3> skel_aabb = VS::get_singleton()->mesh_surface_get_skeleton_aabb(mesh, idx);
|
|
|
|
Array arr;
|
|
|
|
for (int i = 0; i < skel_aabb.size(); i++) {
|
|
|
|
arr[i] = skel_aabb[i];
|
|
|
|
}
|
|
|
|
d["skeleton_aabb"] = arr;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Vector<PoolVector<uint8_t> > blend_shape_data = VS::get_singleton()->mesh_surface_get_blend_shapes(mesh, idx);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Array md;
|
|
|
|
for (int i = 0; i < blend_shape_data.size(); i++) {
|
|
|
|
md.push_back(blend_shape_data[i]);
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
d["blend_shape_data"] = md;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<Material> m = surface_get_material(idx);
|
|
|
|
if (m.is_valid())
|
|
|
|
d["material"] = m;
|
|
|
|
String n = surface_get_name(idx);
|
|
|
|
if (n != "")
|
|
|
|
d["name"] = n;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
r_ret = d;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
void ArrayMesh::_get_property_list(List<PropertyInfo> *p_list) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (_is_generated())
|
|
|
|
return;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (blend_shapes.size()) {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::POOL_STRING_ARRAY, "blend_shape/names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "blend_shape/mode", PROPERTY_HINT_ENUM, "Normalized,Relative"));
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int i = 0; i < surfaces.size(); i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
p_list->push_back(PropertyInfo(Variant::DICTIONARY, "surfaces/" + itos(i), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "surface_" + itos(i + 1) + "/name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
|
2017-06-22 14:17:06 +02:00
|
|
|
if (surfaces[i].is_2d) {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, "surface_" + itos(i + 1) + "/material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,CanvasItemMaterial", PROPERTY_USAGE_EDITOR));
|
|
|
|
} else {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, "surface_" + itos(i + 1) + "/material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,SpatialMaterial", PROPERTY_USAGE_EDITOR));
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-06-07 23:18:55 +02:00
|
|
|
|
|
|
|
p_list->push_back(PropertyInfo(Variant::RECT3, "custom_aabb/custom_aabb"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
void ArrayMesh::_recompute_aabb() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
// regenerate AABB
|
|
|
|
aabb = Rect3();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int i = 0; i < surfaces.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (i == 0)
|
|
|
|
aabb = surfaces[i].aabb;
|
|
|
|
else
|
|
|
|
aabb.merge_with(surfaces[i].aabb);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
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 Rect3 &p_aabb, const Vector<PoolVector<uint8_t> > &p_blend_shapes, const Vector<Rect3> &p_bone_aabbs) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Surface s;
|
|
|
|
s.aabb = p_aabb;
|
2017-06-22 14:17:06 +02:00
|
|
|
s.is_2d = p_format & ARRAY_FLAG_USE_2D_VERTICES;
|
2017-06-07 23:18:55 +02:00
|
|
|
surfaces.push_back(s);
|
2017-06-09 05:23:50 +02:00
|
|
|
_recompute_aabb();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
VisualServer::get_singleton()->mesh_add_surface(mesh, p_format, (VS::PrimitiveType)p_primitive, p_array, p_vertex_count, p_index_array, p_index_count, p_aabb, p_blend_shapes, p_bone_aabbs);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
void ArrayMesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, uint32_t p_flags) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_COND(p_arrays.size() != ARRAY_MAX);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Surface s;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh, (VisualServer::PrimitiveType)p_primitive, p_arrays, p_blend_shapes, p_flags);
|
|
|
|
surfaces.push_back(s);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
/* make aABB? */ {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-22 14:17:06 +02:00
|
|
|
Variant arr = p_arrays[ARRAY_VERTEX];
|
|
|
|
PoolVector<Vector3> vertices = arr;
|
2017-06-07 23:18:55 +02:00
|
|
|
int len = vertices.size();
|
|
|
|
ERR_FAIL_COND(len == 0);
|
|
|
|
PoolVector<Vector3>::Read r = vertices.read();
|
|
|
|
const Vector3 *vtx = r.ptr();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
// check AABB
|
|
|
|
Rect3 aabb;
|
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (i == 0)
|
2017-06-06 20:33:51 +02:00
|
|
|
aabb.position = vtx[i];
|
2017-06-07 23:18:55 +02:00
|
|
|
else
|
|
|
|
aabb.expand_to(vtx[i]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
surfaces[surfaces.size() - 1].aabb = aabb;
|
2017-06-22 14:17:06 +02:00
|
|
|
surfaces[surfaces.size() - 1].is_2d = arr.get_type() == Variant::POOL_VECTOR2_ARRAY;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
_recompute_aabb();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
_clear_triangle_mesh();
|
|
|
|
_change_notify();
|
|
|
|
emit_changed();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Array ArrayMesh::surface_get_arrays(int p_surface) const {
|
2014-10-14 06:01:25 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array());
|
|
|
|
return VisualServer::get_singleton()->mesh_surface_get_arrays(mesh, p_surface);
|
|
|
|
}
|
|
|
|
Array ArrayMesh::surface_get_blend_shape_arrays(int p_surface) const {
|
2014-10-14 06:01:25 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array());
|
|
|
|
return Array();
|
|
|
|
}
|
2014-10-14 06:01:25 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int ArrayMesh::get_surface_count() const {
|
2014-10-14 06:01:25 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
return surfaces.size();
|
|
|
|
}
|
2014-10-14 06:01:25 +02:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
void ArrayMesh::add_blend_shape(const StringName &p_name) {
|
|
|
|
|
|
|
|
if (surfaces.size()) {
|
|
|
|
ERR_EXPLAIN("Can't add a shape key count if surfaces are already created.");
|
|
|
|
ERR_FAIL_COND(surfaces.size());
|
2014-10-14 06:01:25 +02:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
StringName name = p_name;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (blend_shapes.find(name) != -1) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int count = 2;
|
|
|
|
do {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
name = String(p_name) + " " + itos(count);
|
|
|
|
count++;
|
|
|
|
} while (blend_shapes.find(name) != -1);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
blend_shapes.push_back(name);
|
|
|
|
VS::get_singleton()->mesh_set_blend_shape_count(mesh, blend_shapes.size());
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int ArrayMesh::get_blend_shape_count() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
return blend_shapes.size();
|
|
|
|
}
|
|
|
|
StringName ArrayMesh::get_blend_shape_name(int p_index) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_index, blend_shapes.size(), StringName());
|
|
|
|
return blend_shapes[p_index];
|
|
|
|
}
|
|
|
|
void ArrayMesh::clear_blend_shapes() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (surfaces.size()) {
|
|
|
|
ERR_EXPLAIN("Can't set shape key count if surfaces are already created.");
|
|
|
|
ERR_FAIL_COND(surfaces.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
blend_shapes.clear();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
void ArrayMesh::set_blend_shape_mode(BlendShapeMode p_mode) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
blend_shape_mode = p_mode;
|
|
|
|
VS::get_singleton()->mesh_set_blend_shape_mode(mesh, (VS::BlendShapeMode)p_mode);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ArrayMesh::BlendShapeMode ArrayMesh::get_blend_shape_mode() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
return blend_shape_mode;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
void ArrayMesh::surface_remove(int p_idx) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_INDEX(p_idx, surfaces.size());
|
|
|
|
VisualServer::get_singleton()->mesh_remove_surface(mesh, p_idx);
|
|
|
|
surfaces.remove(p_idx);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
_clear_triangle_mesh();
|
|
|
|
_recompute_aabb();
|
|
|
|
_change_notify();
|
|
|
|
emit_changed();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int ArrayMesh::surface_get_array_len(int p_idx) const {
|
|
|
|
|
|
|
|
ERR_FAIL_INDEX_V(p_idx, surfaces.size(), -1);
|
|
|
|
return VisualServer::get_singleton()->mesh_surface_get_array_len(mesh, p_idx);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
int ArrayMesh::surface_get_array_index_len(int p_idx) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, surfaces.size(), -1);
|
|
|
|
return VisualServer::get_singleton()->mesh_surface_get_array_index_len(mesh, p_idx);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
uint32_t ArrayMesh::surface_get_format(int p_idx) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, surfaces.size(), 0);
|
|
|
|
return VisualServer::get_singleton()->mesh_surface_get_format(mesh, p_idx);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ArrayMesh::PrimitiveType ArrayMesh::surface_get_primitive_type(int p_idx) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, surfaces.size(), PRIMITIVE_LINES);
|
|
|
|
return (PrimitiveType)VisualServer::get_singleton()->mesh_surface_get_primitive_type(mesh, p_idx);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
void ArrayMesh::surface_set_material(int p_idx, const Ref<Material> &p_material) {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_INDEX(p_idx, surfaces.size());
|
|
|
|
if (surfaces[p_idx].material == p_material)
|
|
|
|
return;
|
|
|
|
surfaces[p_idx].material = p_material;
|
|
|
|
VisualServer::get_singleton()->mesh_surface_set_material(mesh, p_idx, p_material.is_null() ? RID() : p_material->get_rid());
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
_change_notify("material");
|
|
|
|
}
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
void ArrayMesh::surface_set_name(int p_idx, const String &p_name) {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_INDEX(p_idx, surfaces.size());
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
surfaces[p_idx].name = p_name;
|
|
|
|
}
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
String ArrayMesh::surface_get_name(int p_idx) const {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, surfaces.size(), String());
|
|
|
|
return surfaces[p_idx].name;
|
|
|
|
}
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
void ArrayMesh::surface_set_custom_aabb(int p_idx, const Rect3 &p_aabb) {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_INDEX(p_idx, surfaces.size());
|
|
|
|
surfaces[p_idx].aabb = p_aabb;
|
|
|
|
// set custom aabb too?
|
|
|
|
}
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<Material> ArrayMesh::surface_get_material(int p_idx) const {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, surfaces.size(), Ref<Material>());
|
|
|
|
return surfaces[p_idx].material;
|
|
|
|
}
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
void ArrayMesh::add_surface_from_mesh_data(const Geometry::MeshData &p_mesh_data) {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
VisualServer::get_singleton()->mesh_add_surface_from_mesh_data(mesh, p_mesh_data);
|
|
|
|
Rect3 aabb;
|
|
|
|
for (int i = 0; i < p_mesh_data.vertices.size(); i++) {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
if (i == 0)
|
2017-06-06 20:33:51 +02:00
|
|
|
aabb.position = p_mesh_data.vertices[i];
|
2017-06-07 23:18:55 +02:00
|
|
|
else
|
|
|
|
aabb.expand_to(p_mesh_data.vertices[i]);
|
2014-11-02 15:31:01 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Surface s;
|
|
|
|
s.aabb = aabb;
|
|
|
|
if (surfaces.size() == 0)
|
|
|
|
aabb = s.aabb;
|
|
|
|
else
|
|
|
|
aabb.merge_with(s.aabb);
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
_clear_triangle_mesh();
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
surfaces.push_back(s);
|
|
|
|
_change_notify();
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
emit_changed();
|
|
|
|
}
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
RID ArrayMesh::get_rid() const {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
return mesh;
|
|
|
|
}
|
|
|
|
Rect3 ArrayMesh::get_aabb() const {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
return aabb;
|
|
|
|
}
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
void ArrayMesh::set_custom_aabb(const Rect3 &p_custom) {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
custom_aabb = p_custom;
|
|
|
|
VS::get_singleton()->mesh_set_custom_aabb(mesh, custom_aabb);
|
|
|
|
}
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Rect3 ArrayMesh::get_custom_aabb() const {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
return custom_aabb;
|
|
|
|
}
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
void ArrayMesh::center_geometry() {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
/*
|
|
|
|
Vector3 ofs = aabb.pos+aabb.size*0.5;
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for(int i=0;i<get_surface_count();i++) {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
PoolVector<Vector3> geom = surface_get_array(i,ARRAY_VERTEX);
|
|
|
|
int gc =geom.size();
|
|
|
|
PoolVector<Vector3>::Write w = geom.write();
|
|
|
|
surfaces[i].aabb.pos-=ofs;
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for(int i=0;i<gc;i++) {
|
|
|
|
|
|
|
|
w[i]-=ofs;
|
2014-11-02 15:31:01 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
w = PoolVector<Vector3>::Write();
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
surface_set_array(i,ARRAY_VERTEX,geom);
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
}
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
aabb.pos-=ofs;
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
*/
|
|
|
|
}
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
void ArrayMesh::regen_normalmaps() {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Vector<Ref<SurfaceTool> > surfs;
|
|
|
|
for (int i = 0; i < get_surface_count(); i++) {
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<SurfaceTool> st = memnew(SurfaceTool);
|
|
|
|
st->create_from(Ref<ArrayMesh>(this), i);
|
|
|
|
surfs.push_back(st);
|
|
|
|
}
|
2014-11-02 15:31:01 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
while (get_surface_count()) {
|
|
|
|
surface_remove(0);
|
2014-11-02 15:31:01 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
for (int i = 0; i < surfs.size(); i++) {
|
|
|
|
|
|
|
|
surfs[i]->generate_tangents();
|
|
|
|
surfs[i]->commit(Ref<ArrayMesh>(this));
|
|
|
|
}
|
2014-11-02 15:31:01 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
void ArrayMesh::_bind_methods() {
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("add_blend_shape", "name"), &ArrayMesh::add_blend_shape);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_blend_shape_count"), &ArrayMesh::get_blend_shape_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_blend_shape_name", "index"), &ArrayMesh::get_blend_shape_name);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear_blend_shapes"), &ArrayMesh::clear_blend_shapes);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_blend_shape_mode", "mode"), &ArrayMesh::set_blend_shape_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_blend_shape_mode"), &ArrayMesh::get_blend_shape_mode);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("add_surface_from_arrays", "primitive", "arrays", "blend_shapes", "compress_flags"), &ArrayMesh::add_surface_from_arrays, DEFVAL(Array()), DEFVAL(ARRAY_COMPRESS_DEFAULT));
|
|
|
|
ClassDB::bind_method(D_METHOD("get_surface_count"), &ArrayMesh::get_surface_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("surface_remove", "surf_idx"), &ArrayMesh::surface_remove);
|
|
|
|
ClassDB::bind_method(D_METHOD("surface_get_array_len", "surf_idx"), &ArrayMesh::surface_get_array_len);
|
|
|
|
ClassDB::bind_method(D_METHOD("surface_get_array_index_len", "surf_idx"), &ArrayMesh::surface_get_array_index_len);
|
|
|
|
ClassDB::bind_method(D_METHOD("surface_get_format", "surf_idx"), &ArrayMesh::surface_get_format);
|
|
|
|
ClassDB::bind_method(D_METHOD("surface_get_primitive_type", "surf_idx"), &ArrayMesh::surface_get_primitive_type);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("surface_set_material", "surf_idx", "material"), &ArrayMesh::surface_set_material);
|
|
|
|
ClassDB::bind_method(D_METHOD("surface_get_material", "surf_idx"), &ArrayMesh::surface_get_material);
|
2017-06-07 23:18:55 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("surface_set_name", "surf_idx", "name"), &ArrayMesh::surface_set_name);
|
|
|
|
ClassDB::bind_method(D_METHOD("surface_get_name", "surf_idx"), &ArrayMesh::surface_get_name);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("create_trimesh_shape"), &ArrayMesh::create_trimesh_shape);
|
|
|
|
ClassDB::bind_method(D_METHOD("create_convex_shape"), &ArrayMesh::create_convex_shape);
|
|
|
|
ClassDB::bind_method(D_METHOD("create_outline", "margin"), &ArrayMesh::create_outline);
|
2017-06-07 23:18:55 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("center_geometry"), &ArrayMesh::center_geometry);
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::set_method_flags(get_class_static(), _scs_create("center_geometry"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
|
2017-06-07 23:18:55 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("regen_normalmaps"), &ArrayMesh::regen_normalmaps);
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::set_method_flags(get_class_static(), _scs_create("regen_normalmaps"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
|
2017-06-07 23:18:55 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_faces"), &ArrayMesh::get_faces);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("generate_triangle_mesh"), &ArrayMesh::generate_triangle_mesh);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_custom_aabb", "aabb"), &ArrayMesh::set_custom_aabb);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_custom_aabb"), &ArrayMesh::get_custom_aabb);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
BIND_CONSTANT(NO_INDEX_ARRAY);
|
|
|
|
BIND_CONSTANT(ARRAY_WEIGHTS_SIZE);
|
|
|
|
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(ARRAY_VERTEX);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_NORMAL);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_TANGENT);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_COLOR);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_TEX_UV);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_TEX_UV2);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_BONES);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_WEIGHTS);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_INDEX);
|
2017-08-27 04:18:02 +02:00
|
|
|
BIND_ENUM_CONSTANT(ARRAY_MAX);
|
2017-08-20 17:45:01 +02:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_FORMAT_VERTEX);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_FORMAT_NORMAL);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_FORMAT_TANGENT);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_FORMAT_COLOR);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_FORMAT_TEX_UV);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_FORMAT_TEX_UV2);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_FORMAT_BONES);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_FORMAT_WEIGHTS);
|
|
|
|
BIND_ENUM_CONSTANT(ARRAY_FORMAT_INDEX);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ArrayMesh::ArrayMesh() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
mesh = VisualServer::get_singleton()->mesh_create();
|
|
|
|
blend_shape_mode = BLEND_SHAPE_MODE_RELATIVE;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
ArrayMesh::~ArrayMesh() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
VisualServer::get_singleton()->free(mesh);
|
|
|
|
}
|