2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* visual_server.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
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 "visual_server.h"
|
2017-06-23 17:03:41 +02:00
|
|
|
#include "method_bind_ext.gen.inc"
|
2017-07-19 22:00:46 +02:00
|
|
|
#include "project_settings.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer *VisualServer::singleton = NULL;
|
|
|
|
VisualServer *(*VisualServer::create_func)() = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
VisualServer *VisualServer::get_singleton() {
|
|
|
|
|
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<String> VisualServer::_shader_get_param_list(RID p_shader) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
//remove at some point
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<String> pl;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
List<StringName> params;
|
|
|
|
shader_get_param_list(p_shader,¶ms);
|
|
|
|
|
|
|
|
|
|
|
|
for(List<StringName>::Element *E=params.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
pl.push_back(E->get());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return pl;
|
|
|
|
}
|
|
|
|
|
|
|
|
VisualServer *VisualServer::create() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(singleton, NULL);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (create_func)
|
|
|
|
return create_func();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
|
|
|
return NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 12:36:47 +02:00
|
|
|
RID VisualServer::texture_create_from_image(const Ref<Image> &p_image, uint32_t p_flags) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-05-17 12:36:47 +02:00
|
|
|
ERR_FAIL_COND_V(!p_image.is_valid(), RID());
|
2014-02-10 02:10:30 +01:00
|
|
|
RID texture = texture_create();
|
2017-05-17 12:36:47 +02:00
|
|
|
texture_allocate(texture, p_image->get_width(), p_image->get_height(), p_image->get_format(), p_flags); //if it has mipmaps, use, else generate
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!texture.is_valid(), texture);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
texture_set_data(texture, p_image);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
RID VisualServer::get_test_texture() {
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (test_texture.is_valid()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return test_texture;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TEST_TEXTURE_SIZE 256
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> test_data;
|
2017-03-05 16:44:50 +01:00
|
|
|
test_data.resize(TEST_TEXTURE_SIZE * TEST_TEXTURE_SIZE * 3);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
{
|
2017-03-05 16:44:50 +01:00
|
|
|
PoolVector<uint8_t>::Write w = test_data.write();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int x = 0; x < TEST_TEXTURE_SIZE; x++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int y = 0; y < TEST_TEXTURE_SIZE; y++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
Color c;
|
2017-03-05 16:44:50 +01:00
|
|
|
int r = 255 - (x + y) / 2;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if ((x % (TEST_TEXTURE_SIZE / 8)) < 2 || (y % (TEST_TEXTURE_SIZE / 8)) < 2) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
c.r = y;
|
|
|
|
c.g = r;
|
|
|
|
c.b = x;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
c.r = r;
|
|
|
|
c.g = x;
|
|
|
|
c.b = y;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
w[(y * TEST_TEXTURE_SIZE + x) * 3 + 0] = uint8_t(CLAMP(c.r * 255, 0, 255));
|
|
|
|
w[(y * TEST_TEXTURE_SIZE + x) * 3 + 1] = uint8_t(CLAMP(c.g * 255, 0, 255));
|
|
|
|
w[(y * TEST_TEXTURE_SIZE + x) * 3 + 2] = uint8_t(CLAMP(c.b * 255, 0, 255));
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 12:36:47 +02:00
|
|
|
Ref<Image> data = memnew(Image(TEST_TEXTURE_SIZE, TEST_TEXTURE_SIZE, false, Image::FORMAT_RGB8, test_data));
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
test_texture = texture_create_from_image(data);
|
|
|
|
|
|
|
|
return test_texture;
|
2017-05-17 12:36:47 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-04-21 00:38:02 +02:00
|
|
|
void VisualServer::_free_internal_rids() {
|
|
|
|
|
|
|
|
if (test_texture.is_valid())
|
|
|
|
free(test_texture);
|
|
|
|
if (white_texture.is_valid())
|
|
|
|
free(white_texture);
|
|
|
|
if (test_material.is_valid())
|
|
|
|
free(test_material);
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
RID VisualServer::_make_test_cube() {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> vertices;
|
|
|
|
PoolVector<Vector3> normals;
|
|
|
|
PoolVector<float> tangents;
|
|
|
|
PoolVector<Vector3> uvs;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int vtx_idx = 0;
|
|
|
|
#define ADD_VTX(m_idx) \
|
|
|
|
vertices.push_back(face_points[m_idx]); \
|
|
|
|
normals.push_back(normal_points[m_idx]); \
|
|
|
|
tangents.push_back(normal_points[m_idx][1]); \
|
|
|
|
tangents.push_back(normal_points[m_idx][2]); \
|
|
|
|
tangents.push_back(normal_points[m_idx][0]); \
|
|
|
|
tangents.push_back(1.0); \
|
|
|
|
uvs.push_back(Vector3(uv_points[m_idx * 2 + 0], uv_points[m_idx * 2 + 1], 0)); \
|
|
|
|
vtx_idx++;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 6; i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Vector3 face_points[4];
|
|
|
|
Vector3 normal_points[4];
|
2017-03-05 16:44:50 +01:00
|
|
|
float uv_points[8] = { 0, 0, 0, 1, 1, 1, 1, 0 };
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < 4; j++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
float v[3];
|
2017-03-05 16:44:50 +01:00
|
|
|
v[0] = 1.0;
|
|
|
|
v[1] = 1 - 2 * ((j >> 1) & 1);
|
|
|
|
v[2] = v[1] * (1 - 2 * (j & 1));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int k = 0; k < 3; k++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i < 3)
|
|
|
|
face_points[j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1);
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
face_points[3 - j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
normal_points[j] = Vector3();
|
|
|
|
normal_points[j][i % 3] = (i >= 3 ? -1 : 1);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
//tri 1
|
2014-02-10 02:10:30 +01:00
|
|
|
ADD_VTX(0);
|
|
|
|
ADD_VTX(1);
|
|
|
|
ADD_VTX(2);
|
2017-03-05 16:44:50 +01:00
|
|
|
//tri 2
|
2014-02-10 02:10:30 +01:00
|
|
|
ADD_VTX(2);
|
|
|
|
ADD_VTX(3);
|
|
|
|
ADD_VTX(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
RID test_cube = mesh_create();
|
|
|
|
|
|
|
|
Array d;
|
|
|
|
d.resize(VS::ARRAY_MAX);
|
2017-03-05 16:44:50 +01:00
|
|
|
d[VisualServer::ARRAY_NORMAL] = normals;
|
|
|
|
d[VisualServer::ARRAY_TANGENT] = tangents;
|
|
|
|
d[VisualServer::ARRAY_TEX_UV] = uvs;
|
|
|
|
d[VisualServer::ARRAY_VERTEX] = vertices;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int> indices;
|
2014-02-10 02:10:30 +01:00
|
|
|
indices.resize(vertices.size());
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < vertices.size(); i++)
|
|
|
|
indices.set(i, i);
|
|
|
|
d[VisualServer::ARRAY_INDEX] = indices;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
mesh_add_surface_from_arrays(test_cube, PRIMITIVE_TRIANGLES, d);
|
2015-04-21 00:38:02 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
/*
|
2015-04-21 00:38:02 +02:00
|
|
|
test_material = fixed_material_create();
|
2014-02-10 02:10:30 +01:00
|
|
|
//material_set_flag(material, MATERIAL_FLAG_BILLBOARD_TOGGLE,true);
|
2015-04-21 00:38:02 +02:00
|
|
|
fixed_material_set_texture( test_material, FIXED_MATERIAL_PARAM_DIFFUSE, get_test_texture() );
|
|
|
|
fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_SPECULAR_EXP, 70 );
|
|
|
|
fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_EMISSION, Color(0.2,0.2,0.2) );
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-04-21 00:38:02 +02:00
|
|
|
fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_DIFFUSE, Color(1, 1, 1) );
|
|
|
|
fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_SPECULAR, Color(1,1,1) );
|
2016-10-03 21:33:42 +02:00
|
|
|
*/
|
2017-03-05 16:44:50 +01:00
|
|
|
mesh_surface_set_material(test_cube, 0, test_material);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return test_cube;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
RID VisualServer::make_sphere_mesh(int p_lats, int p_lons, float p_radius) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> vertices;
|
|
|
|
PoolVector<Vector3> normals;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 1; i <= p_lats; i++) {
|
|
|
|
double lat0 = Math_PI * (-0.5 + (double)(i - 1) / p_lats);
|
|
|
|
double z0 = Math::sin(lat0);
|
|
|
|
double zr0 = Math::cos(lat0);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
double lat1 = Math_PI * (-0.5 + (double)i / p_lats);
|
2014-02-10 02:10:30 +01:00
|
|
|
double z1 = Math::sin(lat1);
|
|
|
|
double zr1 = Math::cos(lat1);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = p_lons; j >= 1; j--) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
double lng0 = 2 * Math_PI * (double)(j - 1) / p_lons;
|
2014-02-10 02:10:30 +01:00
|
|
|
double x0 = Math::cos(lng0);
|
|
|
|
double y0 = Math::sin(lng0);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
double lng1 = 2 * Math_PI * (double)(j) / p_lons;
|
2016-03-09 00:00:52 +01:00
|
|
|
double x1 = Math::cos(lng1);
|
2014-02-10 02:10:30 +01:00
|
|
|
double y1 = Math::sin(lng1);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 v[4] = {
|
|
|
|
Vector3(x1 * zr0, z0, y1 * zr0),
|
|
|
|
Vector3(x1 * zr1, z1, y1 * zr1),
|
|
|
|
Vector3(x0 * zr1, z1, y0 * zr1),
|
|
|
|
Vector3(x0 * zr0, z0, y0 * zr0)
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#define ADD_POINT(m_idx) \
|
|
|
|
normals.push_back(v[m_idx]); \
|
|
|
|
vertices.push_back(v[m_idx] * p_radius);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ADD_POINT(0);
|
|
|
|
ADD_POINT(1);
|
|
|
|
ADD_POINT(2);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ADD_POINT(2);
|
|
|
|
ADD_POINT(3);
|
|
|
|
ADD_POINT(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RID mesh = mesh_create();
|
|
|
|
Array d;
|
|
|
|
d.resize(VS::ARRAY_MAX);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
d[ARRAY_VERTEX] = vertices;
|
|
|
|
d[ARRAY_NORMAL] = normals;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
mesh_add_surface_from_arrays(mesh, PRIMITIVE_TRIANGLES, d);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return mesh;
|
|
|
|
}
|
|
|
|
|
2014-05-29 15:56:39 +02:00
|
|
|
RID VisualServer::get_white_texture() {
|
|
|
|
|
|
|
|
if (white_texture.is_valid())
|
|
|
|
return white_texture;
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> wt;
|
2017-03-05 16:44:50 +01:00
|
|
|
wt.resize(16 * 3);
|
2014-05-29 15:56:39 +02:00
|
|
|
{
|
2017-03-05 16:44:50 +01:00
|
|
|
PoolVector<uint8_t>::Write w = wt.write();
|
|
|
|
for (int i = 0; i < 16 * 3; i++)
|
|
|
|
w[i] = 255;
|
2014-05-29 15:56:39 +02:00
|
|
|
}
|
2017-05-17 12:36:47 +02:00
|
|
|
Ref<Image> white = memnew(Image(4, 4, 0, Image::FORMAT_RGB8, wt));
|
2017-03-05 16:44:50 +01:00
|
|
|
white_texture = texture_create();
|
|
|
|
texture_allocate(white_texture, 4, 4, Image::FORMAT_RGB8);
|
|
|
|
texture_set_data(white_texture, white);
|
2014-05-29 15:56:39 +02:00
|
|
|
return white_texture;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error VisualServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint32_t *p_offsets, uint32_t p_stride, PoolVector<uint8_t> &r_vertex_array, int p_vertex_array_len, PoolVector<uint8_t> &r_index_array, int p_index_array_len, Rect3 &r_aabb, Vector<Rect3> r_bone_aabb) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Write vw = r_vertex_array.write();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Write iw;
|
2016-10-19 16:14:41 +02:00
|
|
|
if (r_index_array.size()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
iw = r_index_array.write();
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int max_bone = 0;
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int ai = 0; ai < VS::ARRAY_MAX; ai++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!(p_format & (1 << ai))) // no array
|
2016-10-19 16:14:41 +02:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (ai) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
case VS::ARRAY_VERTEX: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & VS::ARRAY_FLAG_USE_2D_VERTICES) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2> array = p_arrays[ai];
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2>::Read read = array.read();
|
2017-03-05 16:44:50 +01:00
|
|
|
const Vector2 *src = read.ptr();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
// setting vertices means regenerating the AABB
|
|
|
|
Rect2 aabb;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_VERTEX) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint16_t vector[2] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y) };
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], vector, sizeof(uint16_t) * 2);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == 0) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
aabb = Rect2(src[i], Vector2());
|
2016-10-19 16:14:41 +02:00
|
|
|
} else {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
aabb.expand_to(src[i]);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float vector[2] = { src[i].x, src[i].y };
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], vector, sizeof(float) * 2);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == 0) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
aabb = Rect2(src[i], Vector2());
|
2016-10-19 16:14:41 +02:00
|
|
|
} else {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
aabb.expand_to(src[i]);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-04 00:25:13 +02:00
|
|
|
r_aabb = Rect3(Vector3(aabb.position.x, aabb.position.y, 0), Vector3(aabb.size.x, aabb.size.y, 0));
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
} else {
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> array = p_arrays[ai];
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3>::Read read = array.read();
|
2017-03-05 16:44:50 +01:00
|
|
|
const Vector3 *src = read.ptr();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
// setting vertices means regenerating the AABB
|
2017-01-11 04:52:51 +01:00
|
|
|
Rect3 aabb;
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_VERTEX) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint16_t vector[4] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y), Math::make_half_float(src[i].z), Math::make_half_float(1.0) };
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], vector, sizeof(uint16_t) * 4);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == 0) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
aabb = Rect3(src[i], Vector3());
|
2016-10-19 16:14:41 +02:00
|
|
|
} else {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
aabb.expand_to(src[i]);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float vector[3] = { src[i].x, src[i].y, src[i].z };
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], vector, sizeof(float) * 3);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == 0) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
aabb = Rect3(src[i], Vector3());
|
2016-10-19 16:14:41 +02:00
|
|
|
} else {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
aabb.expand_to(src[i]);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_aabb = aabb;
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_NORMAL: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_VECTOR3_ARRAY, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> array = p_arrays[ai];
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3>::Read read = array.read();
|
2017-03-05 16:44:50 +01:00
|
|
|
const Vector3 *src = read.ptr();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
// setting vertices means regenerating the AABB
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_NORMAL) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-06-17 02:13:13 +02:00
|
|
|
int8_t vector[4] = {
|
2017-03-05 16:44:50 +01:00
|
|
|
CLAMP(src[i].x * 127, -128, 127),
|
|
|
|
CLAMP(src[i].y * 127, -128, 127),
|
|
|
|
CLAMP(src[i].z * 127, -128, 127),
|
2016-10-19 16:14:41 +02:00
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], vector, 4);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float vector[3] = { src[i].x, src[i].y, src[i].z };
|
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], vector, 3 * 4);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case VS::ARRAY_TANGENT: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_REAL_ARRAY, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<real_t> array = p_arrays[ai];
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(array.size() != p_vertex_array_len * 4, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<real_t>::Read read = array.read();
|
2017-03-05 16:44:50 +01:00
|
|
|
const real_t *src = read.ptr();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_TANGENT) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint8_t xyzw[4] = {
|
|
|
|
CLAMP(src[i * 4 + 0] * 127, -128, 127),
|
|
|
|
CLAMP(src[i * 4 + 1] * 127, -128, 127),
|
|
|
|
CLAMP(src[i * 4 + 2] * 127, -128, 127),
|
|
|
|
CLAMP(src[i * 4 + 3] * 127, -128, 127)
|
2016-10-19 16:14:41 +02:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], xyzw, 4);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float xyzw[4] = {
|
|
|
|
src[i * 4 + 0],
|
|
|
|
src[i * 4 + 1],
|
|
|
|
src[i * 4 + 2],
|
|
|
|
src[i * 4 + 3]
|
2016-10-19 16:14:41 +02:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], xyzw, 4 * 4);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_COLOR: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_COLOR_ARRAY, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Color> array = p_arrays[ai];
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Color>::Read read = array.read();
|
2017-03-05 16:44:50 +01:00
|
|
|
const Color *src = read.ptr();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_COLOR) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
uint8_t colors[4];
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < 4; j++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
colors[j] = CLAMP(int((src[i][j]) * 255.0), 0, 255);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], colors, 4);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], &src[i], 4 * 4);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_TEX_UV: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_VECTOR3_ARRAY && p_arrays[ai].get_type() != Variant::POOL_VECTOR2_ARRAY, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2> array = p_arrays[ai];
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2>::Read read = array.read();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Vector2 *src = read.ptr();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_TEX_UV) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint16_t uv[2] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y) };
|
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], uv, 2 * 2);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float uv[2] = { src[i].x, src[i].y };
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], uv, 2 * 4);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case VS::ARRAY_TEX_UV2: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_VECTOR3_ARRAY && p_arrays[ai].get_type() != Variant::POOL_VECTOR2_ARRAY, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2> array = p_arrays[ai];
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2>::Read read = array.read();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Vector2 *src = read.ptr();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_TEX_UV2) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint16_t uv[2] = { Math::make_half_float(src[i].x), Math::make_half_float(src[i].y) };
|
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], uv, 2 * 2);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float uv[2] = { src[i].x, src[i].y };
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], uv, 2 * 4);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_WEIGHTS: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_REAL_ARRAY, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<real_t> array = p_arrays[ai];
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(array.size() != p_vertex_array_len * VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<real_t>::Read read = array.read();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const real_t *src = read.ptr();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_WEIGHTS) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
uint16_t data[VS::ARRAY_WEIGHTS_SIZE];
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
|
|
|
|
data[j] = CLAMP(src[i * VS::ARRAY_WEIGHTS_SIZE + j] * 65535, 0, 65535);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], data, 2 * 4);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
float data[VS::ARRAY_WEIGHTS_SIZE];
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
|
|
|
|
data[j] = src[i * VS::ARRAY_WEIGHTS_SIZE + j];
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], data, 4 * 4);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_BONES: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_INT_ARRAY && p_arrays[ai].get_type() != Variant::POOL_REAL_ARRAY, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int> array = p_arrays[ai];
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(array.size() != p_vertex_array_len * VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int>::Read read = array.read();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const int *src = read.ptr();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!(p_format & ARRAY_FLAG_USE_16_BIT_BONES)) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
uint8_t data[VS::ARRAY_WEIGHTS_SIZE];
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
|
|
|
|
data[j] = CLAMP(src[i * VS::ARRAY_WEIGHTS_SIZE + j], 0, 255);
|
|
|
|
max_bone = MAX(data[j], max_bone);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], data, 4);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_vertex_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
uint16_t data[VS::ARRAY_WEIGHTS_SIZE];
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) {
|
|
|
|
data[j] = src[i * VS::ARRAY_WEIGHTS_SIZE + j];
|
|
|
|
max_bone = MAX(data[j], max_bone);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&vw[p_offsets[ai] + i * p_stride], data, 2 * 4);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_INDEX: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(p_index_array_len <= 0, ERR_INVALID_DATA);
|
|
|
|
ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_INT_ARRAY, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int> indices = p_arrays[ai];
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(indices.size() == 0, ERR_INVALID_PARAMETER);
|
|
|
|
ERR_FAIL_COND_V(indices.size() != p_index_array_len, ERR_INVALID_PARAMETER);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
/* determine wether using 16 or 32 bits indices */
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int>::Read read = indices.read();
|
2017-03-05 16:44:50 +01:00
|
|
|
const int *src = read.ptr();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_index_array_len; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_vertex_array_len < (1 << 16)) {
|
|
|
|
uint16_t v = src[i];
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&iw[i * 2], &v, 2);
|
2016-10-19 16:14:41 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t v = src[i];
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
copymem(&iw[i * 4], &v, 4);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default: {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_V(ERR_INVALID_DATA);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & VS::ARRAY_FORMAT_BONES) {
|
2016-10-19 16:14:41 +02:00
|
|
|
//create AABBs for each detected bone
|
2017-03-05 16:44:50 +01:00
|
|
|
int total_bones = max_bone + 1;
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool first = r_bone_aabb.size() == 0;
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
r_bone_aabb.resize(total_bones);
|
|
|
|
|
|
|
|
if (first) {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < total_bones; i++) {
|
|
|
|
r_bone_aabb[i].size == Vector3(-1, -1, -1); //negative means unused
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> vertices = p_arrays[VS::ARRAY_VERTEX];
|
|
|
|
PoolVector<int> bones = p_arrays[VS::ARRAY_BONES];
|
|
|
|
PoolVector<float> weights = p_arrays[VS::ARRAY_WEIGHTS];
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool any_valid = false;
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (vertices.size() && bones.size() == vertices.size() * 4 && weights.size() == bones.size()) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
int vs = vertices.size();
|
2017-03-05 16:44:50 +01:00
|
|
|
PoolVector<Vector3>::Read rv = vertices.read();
|
|
|
|
PoolVector<int>::Read rb = bones.read();
|
|
|
|
PoolVector<float>::Read rw = weights.read();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Rect3 *bptr = r_bone_aabb.ptr();
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < vs; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
Vector3 v = rv[i];
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < 4; j++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = rb[i * 4 + j];
|
|
|
|
float w = rw[i * 4 + j];
|
|
|
|
if (w == 0)
|
|
|
|
continue; //break;
|
|
|
|
ERR_FAIL_INDEX_V(idx, total_bones, ERR_INVALID_DATA);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (bptr->size.x < 0) {
|
2016-10-19 16:14:41 +02:00
|
|
|
//first
|
2017-03-05 16:44:50 +01:00
|
|
|
bptr[idx] = Rect3();
|
2017-06-06 20:33:51 +02:00
|
|
|
bptr[idx].position = v;
|
2017-03-05 16:44:50 +01:00
|
|
|
any_valid = true;
|
2016-10-19 16:14:41 +02:00
|
|
|
} else {
|
|
|
|
bptr[idx].expand_to(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!any_valid && first) {
|
|
|
|
|
|
|
|
r_bone_aabb.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualServer::mesh_add_surface_from_arrays(RID p_mesh, PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, uint32_t p_compress_format) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX(p_primitive, VS::PRIMITIVE_MAX);
|
|
|
|
ERR_FAIL_COND(p_arrays.size() != VS::ARRAY_MAX);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t format = 0;
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
// validation
|
2017-03-05 16:44:50 +01:00
|
|
|
int index_array_len = 0;
|
|
|
|
int array_len = 0;
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_arrays.size(); i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_arrays[i].get_type() == Variant::NIL)
|
2016-10-19 16:14:41 +02:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
format |= (1 << i);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == VS::ARRAY_VERTEX) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
Variant var = p_arrays[i];
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (var.get_type()) {
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_VECTOR2_ARRAY: {
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2> v2 = var;
|
2017-03-05 16:44:50 +01:00
|
|
|
array_len = v2.size();
|
2016-10-19 16:14:41 +02:00
|
|
|
} break;
|
2017-01-11 04:52:51 +01:00
|
|
|
case Variant::POOL_VECTOR3_ARRAY: {
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> v3 = var;
|
2017-03-05 16:44:50 +01:00
|
|
|
array_len = v3.size();
|
2016-10-19 16:14:41 +02:00
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
Array v = var;
|
2017-03-05 16:44:50 +01:00
|
|
|
array_len = v.size();
|
2016-10-19 16:14:41 +02:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
array_len = PoolVector3Array(p_arrays[i]).size();
|
|
|
|
ERR_FAIL_COND(array_len == 0);
|
|
|
|
} else if (i == VS::ARRAY_INDEX) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
index_array_len = PoolIntArray(p_arrays[i]).size();
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND((format & VS::ARRAY_FORMAT_VERTEX) == 0); // mandatory
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
if (p_blend_shapes.size()) {
|
|
|
|
//validate format for morphs
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_blend_shapes.size(); i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t bsformat = 0;
|
2016-10-19 16:14:41 +02:00
|
|
|
Array arr = p_blend_shapes[i];
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < arr.size(); j++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (arr[j].get_type() != Variant::NIL)
|
|
|
|
bsformat |= (1 << j);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND((bsformat) != (format & (VS::ARRAY_FORMAT_INDEX - 1)));
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t offsets[VS::ARRAY_MAX];
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int total_elem_size = 0;
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < VS::ARRAY_MAX; i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
offsets[i] = 0; //reset
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!(format & (1 << i))) // no array
|
2016-10-19 16:14:41 +02:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int elem_size = 0;
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (i) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
case VS::ARRAY_VERTEX: {
|
|
|
|
|
|
|
|
Variant arr = p_arrays[0];
|
2017-03-05 16:44:50 +01:00
|
|
|
if (arr.get_type() == Variant::POOL_VECTOR2_ARRAY) {
|
|
|
|
elem_size = 2;
|
|
|
|
p_compress_format |= ARRAY_FLAG_USE_2D_VERTICES;
|
|
|
|
} else if (arr.get_type() == Variant::POOL_VECTOR3_ARRAY) {
|
|
|
|
p_compress_format &= ~ARRAY_FLAG_USE_2D_VERTICES;
|
|
|
|
elem_size = 3;
|
2016-10-19 16:14:41 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = (p_compress_format & ARRAY_FLAG_USE_2D_VERTICES) ? 2 : 3;
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_compress_format & ARRAY_COMPRESS_VERTEX) {
|
|
|
|
elem_size *= sizeof(int16_t);
|
2016-10-19 16:14:41 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size *= sizeof(float);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (elem_size == 6) {
|
2016-12-24 20:23:30 +01:00
|
|
|
//had to pad
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = 8;
|
2016-12-24 20:23:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-19 16:14:41 +02:00
|
|
|
} break;
|
|
|
|
case VS::ARRAY_NORMAL: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_compress_format & ARRAY_COMPRESS_NORMAL) {
|
|
|
|
elem_size = sizeof(uint32_t);
|
2016-10-19 16:14:41 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = sizeof(float) * 3;
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case VS::ARRAY_TANGENT: {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_compress_format & ARRAY_COMPRESS_TANGENT) {
|
|
|
|
elem_size = sizeof(uint32_t);
|
2016-10-19 16:14:41 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = sizeof(float) * 4;
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_COLOR: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_compress_format & ARRAY_COMPRESS_COLOR) {
|
|
|
|
elem_size = sizeof(uint32_t);
|
2016-10-19 16:14:41 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = sizeof(float) * 4;
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_TEX_UV: {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_compress_format & ARRAY_COMPRESS_TEX_UV) {
|
|
|
|
elem_size = sizeof(uint32_t);
|
2016-10-19 16:14:41 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = sizeof(float) * 2;
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case VS::ARRAY_TEX_UV2: {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_compress_format & ARRAY_COMPRESS_TEX_UV2) {
|
|
|
|
elem_size = sizeof(uint32_t);
|
2016-10-19 16:14:41 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = sizeof(float) * 2;
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_WEIGHTS: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_compress_format & ARRAY_COMPRESS_WEIGHTS) {
|
|
|
|
elem_size = sizeof(uint16_t) * 4;
|
2016-10-19 16:14:41 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = sizeof(float) * 4;
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_BONES: {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int> bones = p_arrays[VS::ARRAY_BONES];
|
2017-03-05 16:44:50 +01:00
|
|
|
int max_bone = 0;
|
2016-11-21 23:03:39 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
int bc = bones.size();
|
2017-03-05 16:44:50 +01:00
|
|
|
PoolVector<int>::Read r = bones.read();
|
|
|
|
for (int j = 0; j < bc; j++) {
|
|
|
|
max_bone = MAX(r[j], max_bone);
|
2016-11-21 23:03:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_bone > 255) {
|
2017-03-05 16:44:50 +01:00
|
|
|
p_compress_format |= ARRAY_FLAG_USE_16_BIT_BONES;
|
|
|
|
elem_size = sizeof(uint16_t) * 4;
|
2016-11-21 23:03:39 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
p_compress_format &= ~ARRAY_FLAG_USE_16_BIT_BONES;
|
|
|
|
elem_size = sizeof(uint32_t);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_INDEX: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (index_array_len <= 0) {
|
2016-10-19 16:14:41 +02:00
|
|
|
ERR_PRINT("index_array_len==NO_INDEX_ARRAY");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* determine wether using 16 or 32 bits indices */
|
2017-03-05 16:44:50 +01:00
|
|
|
if (array_len >= (1 << 16)) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = 4;
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = 2;
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
offsets[i] = elem_size;
|
2016-10-19 16:14:41 +02:00
|
|
|
continue;
|
|
|
|
} break;
|
|
|
|
default: {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL();
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
offsets[i] = total_elem_size;
|
|
|
|
total_elem_size += elem_size;
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t mask = (1 << ARRAY_MAX) - 1;
|
|
|
|
format |= (~mask) & p_compress_format; //make the full format
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
int array_size = total_elem_size * array_len;
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> vertex_array;
|
2016-10-19 16:14:41 +02:00
|
|
|
vertex_array.resize(array_size);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int index_array_size = offsets[VS::ARRAY_INDEX] * index_array_len;
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> index_array;
|
2016-10-19 16:14:41 +02:00
|
|
|
index_array.resize(index_array_size);
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Rect3 aabb;
|
|
|
|
Vector<Rect3> bone_aabb;
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error err = _surface_set_data(p_arrays, format, offsets, total_elem_size, vertex_array, array_len, index_array, index_array_len, aabb, bone_aabb);
|
2016-10-19 16:14:41 +02:00
|
|
|
|
|
|
|
if (err) {
|
|
|
|
ERR_EXPLAIN("Invalid array format for surface");
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(err != OK);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
Vector<PoolVector<uint8_t> > blend_shape_data;
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_blend_shapes.size(); i++) {
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> vertex_array_shape;
|
2016-10-19 16:14:41 +02:00
|
|
|
vertex_array_shape.resize(array_size);
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t> noindex;
|
2016-10-19 16:14:41 +02:00
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Rect3 laabb;
|
2017-03-05 16:44:50 +01:00
|
|
|
Error err = _surface_set_data(p_blend_shapes[i], format & ~ARRAY_FORMAT_INDEX, offsets, total_elem_size, vertex_array_shape, array_len, noindex, 0, laabb, bone_aabb);
|
2016-10-19 16:14:41 +02:00
|
|
|
aabb.merge_with(laabb);
|
|
|
|
if (err) {
|
|
|
|
ERR_EXPLAIN("Invalid blend shape array format for surface");
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(err != OK);
|
2016-10-19 16:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
blend_shape_data.push_back(vertex_array_shape);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
mesh_add_surface(p_mesh, format, p_primitive, vertex_array, array_len, index_array, index_array_len, aabb, blend_shape_data, bone_aabb);
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Array VisualServer::_get_array_from_surface(uint32_t p_format, PoolVector<uint8_t> p_vertex_data, int p_vertex_len, PoolVector<uint8_t> p_index_data, int p_index_len) const {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
|
|
|
uint32_t offsets[ARRAY_MAX];
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int total_elem_size = 0;
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < VS::ARRAY_MAX; i++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
offsets[i] = 0; //reset
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!(p_format & (1 << i))) // no array
|
2016-11-10 03:55:06 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int elem_size = 0;
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (i) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
|
|
|
case VS::ARRAY_VERTEX: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_FLAG_USE_2D_VERTICES) {
|
|
|
|
elem_size = 2;
|
2016-11-10 03:55:06 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = 3;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_VERTEX) {
|
|
|
|
elem_size *= sizeof(int16_t);
|
2016-11-10 03:55:06 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size *= sizeof(float);
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (elem_size == 6) {
|
|
|
|
elem_size = 8;
|
2016-12-24 20:23:30 +01:00
|
|
|
}
|
|
|
|
|
2016-11-10 03:55:06 +01:00
|
|
|
} break;
|
|
|
|
case VS::ARRAY_NORMAL: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_NORMAL) {
|
|
|
|
elem_size = sizeof(uint32_t);
|
2016-11-10 03:55:06 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = sizeof(float) * 3;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case VS::ARRAY_TANGENT: {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_TANGENT) {
|
|
|
|
elem_size = sizeof(uint32_t);
|
2016-11-10 03:55:06 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = sizeof(float) * 4;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_COLOR: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_COLOR) {
|
|
|
|
elem_size = sizeof(uint32_t);
|
2016-11-10 03:55:06 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = sizeof(float) * 4;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_TEX_UV: {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_TEX_UV) {
|
|
|
|
elem_size = sizeof(uint32_t);
|
2016-11-10 03:55:06 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = sizeof(float) * 2;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case VS::ARRAY_TEX_UV2: {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_TEX_UV2) {
|
|
|
|
elem_size = sizeof(uint32_t);
|
2016-11-10 03:55:06 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = sizeof(float) * 2;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_WEIGHTS: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_WEIGHTS) {
|
|
|
|
elem_size = sizeof(uint16_t) * 4;
|
2016-11-10 03:55:06 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = sizeof(float) * 4;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_BONES: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_FLAG_USE_16_BIT_BONES) {
|
|
|
|
elem_size = sizeof(uint16_t) * 4;
|
2016-11-25 00:46:55 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = sizeof(uint32_t);
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_INDEX: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_index_len <= 0) {
|
2016-11-10 03:55:06 +01:00
|
|
|
ERR_PRINT("index_array_len==NO_INDEX_ARRAY");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* determine wether using 16 or 32 bits indices */
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_vertex_len >= (1 << 16)) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = 4;
|
2016-11-10 03:55:06 +01:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
elem_size = 2;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
offsets[i] = elem_size;
|
2016-11-10 03:55:06 +01:00
|
|
|
continue;
|
|
|
|
} break;
|
|
|
|
default: {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_V(Array());
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
offsets[i] = total_elem_size;
|
|
|
|
total_elem_size += elem_size;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Array ret;
|
|
|
|
ret.resize(VS::ARRAY_MAX);
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Read r = p_vertex_data.read();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < VS::ARRAY_MAX; i++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!(p_format & (1 << i)))
|
2016-11-10 03:55:06 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (i) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
|
|
|
case VS::ARRAY_VERTEX: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_FLAG_USE_2D_VERTICES) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2> arr_2d;
|
2016-11-10 03:55:06 +01:00
|
|
|
arr_2d.resize(p_vertex_len);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_VERTEX) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2>::Write w = arr_2d.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
w[j] = Vector2(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]));
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2>::Write w = arr_2d.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
w[j] = Vector2(v[0], v[1]);
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ret[i] = arr_2d;
|
2016-11-10 03:55:06 +01:00
|
|
|
} else {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> arr_3d;
|
2016-11-10 03:55:06 +01:00
|
|
|
arr_3d.resize(p_vertex_len);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_VERTEX) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3>::Write w = arr_3d.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
w[j] = Vector3(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]), Math::halfptr_to_float(&v[2]));
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3>::Write w = arr_3d.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
w[j] = Vector3(v[0], v[1], v[2]);
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ret[i] = arr_3d;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_NORMAL: {
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> arr;
|
2016-11-10 03:55:06 +01:00
|
|
|
arr.resize(p_vertex_len);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_NORMAL) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3>::Write w = arr.write();
|
2017-06-17 02:13:13 +02:00
|
|
|
const float multiplier = 1.f / 127.f;
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-06-17 02:13:13 +02:00
|
|
|
const int8_t *v = (const int8_t *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
w[j] = Vector3(float(v[0]) * multiplier, float(v[1]) * multiplier, float(v[2]) * multiplier);
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
w[j] = Vector3(v[0], v[1], v[2]);
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ret[i] = arr;
|
2016-11-10 03:55:06 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case VS::ARRAY_TANGENT: {
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<float> arr;
|
2017-03-05 16:44:50 +01:00
|
|
|
arr.resize(p_vertex_len * 4);
|
|
|
|
if (p_format & ARRAY_COMPRESS_TANGENT) {
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<float>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-07-03 15:44:45 +02:00
|
|
|
const int8_t *v = (const int8_t *)&r[j * total_elem_size + offsets[i]];
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int k = 0; k < 4; k++) {
|
2017-07-03 15:44:45 +02:00
|
|
|
w[j * 4 + k] = float(v[k] / 127.0);
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<float>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
|
|
|
const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
for (int k = 0; k < 4; k++) {
|
|
|
|
w[j * 4 + k] = v[k];
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ret[i] = arr;
|
2016-11-10 03:55:06 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_COLOR: {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Color> arr;
|
2016-11-10 03:55:06 +01:00
|
|
|
arr.resize(p_vertex_len);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_COLOR) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Color>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const uint8_t *v = (const uint8_t *)&r[j * total_elem_size + offsets[i]];
|
2017-06-17 03:17:25 +02:00
|
|
|
w[j] = Color(float(v[0] / 255.0), float(v[1] / 255.0), float(v[2] / 255.0), float(v[3] / 255.0));
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Color>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
w[j] = Color(v[0], v[1], v[2], v[3]);
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ret[i] = arr;
|
2016-11-10 03:55:06 +01:00
|
|
|
} break;
|
|
|
|
case VS::ARRAY_TEX_UV: {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2> arr;
|
2016-11-10 03:55:06 +01:00
|
|
|
arr.resize(p_vertex_len);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_TEX_UV) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
w[j] = Vector2(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]));
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
w[j] = Vector2(v[0], v[1]);
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ret[i] = arr;
|
2016-11-10 03:55:06 +01:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case VS::ARRAY_TEX_UV2: {
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2> arr;
|
2016-11-10 03:55:06 +01:00
|
|
|
arr.resize(p_vertex_len);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_format & ARRAY_COMPRESS_TEX_UV2) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
w[j] = Vector2(Math::halfptr_to_float(&v[0]), Math::halfptr_to_float(&v[1]));
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
w[j] = Vector2(v[0], v[1]);
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ret[i] = arr;
|
2016-11-10 03:55:06 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_WEIGHTS: {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<float> arr;
|
2017-03-05 16:44:50 +01:00
|
|
|
arr.resize(p_vertex_len * 4);
|
|
|
|
if (p_format & ARRAY_COMPRESS_WEIGHTS) {
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<float>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
for (int k = 0; k < 4; k++) {
|
|
|
|
w[j * 4 + k] = float(v[k] / 65535.0) * 2.0 - 1.0;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<float>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
|
|
|
const float *v = (const float *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
for (int k = 0; k < 4; k++) {
|
|
|
|
w[j * 4 + k] = v[k];
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ret[i] = arr;
|
2016-11-10 03:55:06 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_BONES: {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int> arr;
|
2017-03-05 16:44:50 +01:00
|
|
|
arr.resize(p_vertex_len * 4);
|
|
|
|
if (p_format & ARRAY_FLAG_USE_16_BIT_BONES) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const uint16_t *v = (const uint16_t *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
for (int k = 0; k < 4; k++) {
|
|
|
|
w[j * 4 + k] = v[k];
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_vertex_len; j++) {
|
|
|
|
const uint8_t *v = (const uint8_t *)&r[j * total_elem_size + offsets[i]];
|
|
|
|
for (int k = 0; k < 4; k++) {
|
|
|
|
w[j * 4 + k] = v[k];
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ret[i] = arr;
|
2016-11-10 03:55:06 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case VS::ARRAY_INDEX: {
|
|
|
|
/* determine wether using 16 or 32 bits indices */
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<uint8_t>::Read ir = p_index_data.read();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int> arr;
|
2016-11-10 03:55:06 +01:00
|
|
|
arr.resize(p_index_len);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_vertex_len < (1 << 16)) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_index_len; j++) {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const uint16_t *v = (const uint16_t *)&ir[j * 2];
|
|
|
|
w[j] = *v;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int>::Write w = arr.write();
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < p_index_len; j++) {
|
|
|
|
const int *v = (const int *)&ir[j * 4];
|
|
|
|
w[j] = *v;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
ret[i] = arr;
|
2016-11-10 03:55:06 +01:00
|
|
|
} break;
|
|
|
|
default: {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_V(ret);
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Array VisualServer::mesh_surface_get_arrays(RID p_mesh, int p_surface) const {
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PoolVector<uint8_t> vertex_data = mesh_surface_get_array(p_mesh, p_surface);
|
|
|
|
ERR_FAIL_COND_V(vertex_data.size() == 0, Array());
|
|
|
|
int vertex_len = mesh_surface_get_array_len(p_mesh, p_surface);
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PoolVector<uint8_t> index_data = mesh_surface_get_index_array(p_mesh, p_surface);
|
|
|
|
int index_len = mesh_surface_get_array_index_len(p_mesh, p_surface);
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t format = mesh_surface_get_format(p_mesh, p_surface);
|
2016-11-10 03:55:06 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return _get_array_from_surface(format, vertex_data, vertex_len, index_data, index_len);
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void VisualServer::_bind_methods() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("texture_create"), &VisualServer::texture_create);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("texture_create_from_image", "image", "flags"), &VisualServer::texture_create_from_image, DEFVAL(TEXTURE_FLAGS_DEFAULT));
|
2017-02-13 12:47:24 +01:00
|
|
|
//ClassDB::bind_method(D_METHOD("texture_allocate"),&VisualServer::texture_allocate,DEFVAL( TEXTURE_FLAGS_DEFAULT ) );
|
|
|
|
//ClassDB::bind_method(D_METHOD("texture_set_data"),&VisualServer::texture_blit_rect,DEFVAL( CUBEMAP_LEFT ) );
|
|
|
|
//ClassDB::bind_method(D_METHOD("texture_get_rect"),&VisualServer::texture_get_rect );
|
2017-08-09 13:54:55 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("texture_set_flags", "texture", "flags"), &VisualServer::texture_set_flags);
|
|
|
|
ClassDB::bind_method(D_METHOD("texture_get_flags", "texture"), &VisualServer::texture_get_flags);
|
2017-07-22 12:11:42 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("texture_get_width", "texture"), &VisualServer::texture_get_width);
|
|
|
|
ClassDB::bind_method(D_METHOD("texture_get_height", "texture"), &VisualServer::texture_get_height);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("texture_set_shrink_all_x2_on_set_data", "shrink"), &VisualServer::texture_set_shrink_all_x2_on_set_data);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualServer::_canvas_item_add_style_box(RID p_item, const Rect2 &p_rect, const Rect2 &p_source, RID p_texture, const Vector<float> &p_margins, const Color &p_modulate) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(p_margins.size() != 4);
|
2016-10-03 21:33:42 +02:00
|
|
|
//canvas_item_add_style_box(p_item,p_rect,p_source,p_texture,Vector2(p_margins[0],p_margins[1]),Vector2(p_margins[2],p_margins[3]),true,p_modulate);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualServer::_camera_set_orthogonal(RID p_camera, float p_size, float p_z_near, float p_z_far) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
camera_set_orthogonal(p_camera, p_size, p_z_near, p_z_far);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualServer::mesh_add_surface_from_mesh_data(RID p_mesh, const Geometry::MeshData &p_mesh_data) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
#if 1
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> vertices;
|
|
|
|
PoolVector<Vector3> normals;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_mesh_data.faces.size(); i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Geometry::MeshData::Face &f = p_mesh_data.faces[i];
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 2; j < f.indices.size(); j++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#define _ADD_VERTEX(m_idx) \
|
|
|
|
vertices.push_back(p_mesh_data.vertices[f.indices[m_idx]]); \
|
|
|
|
normals.push_back(f.plane.normal);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_ADD_VERTEX(0);
|
|
|
|
_ADD_VERTEX(j - 1);
|
|
|
|
_ADD_VERTEX(j);
|
2016-03-09 00:00:52 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Array d;
|
|
|
|
d.resize(VS::ARRAY_MAX);
|
2017-03-05 16:44:50 +01:00
|
|
|
d[ARRAY_VERTEX] = vertices;
|
|
|
|
d[ARRAY_NORMAL] = normals;
|
|
|
|
mesh_add_surface_from_arrays(p_mesh, PRIMITIVE_TRIANGLES, d);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector3> vertices;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_mesh_data.edges.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Geometry::MeshData::Edge &f = p_mesh_data.edges[i];
|
|
|
|
vertices.push_back(p_mesh_data.vertices[f.a]);
|
|
|
|
vertices.push_back(p_mesh_data.vertices[f.b]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Array d;
|
|
|
|
d.resize(VS::ARRAY_MAX);
|
2017-03-05 16:44:50 +01:00
|
|
|
d[ARRAY_VERTEX] = vertices;
|
|
|
|
mesh_add_surface(p_mesh, PRIMITIVE_LINES, d);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualServer::mesh_add_surface_from_planes(RID p_mesh, const PoolVector<Plane> &p_planes) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Geometry::MeshData mdata = Geometry::build_convex_mesh(p_planes);
|
2017-03-05 16:44:50 +01:00
|
|
|
mesh_add_surface_from_mesh_data(p_mesh, mdata);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualServer::immediate_vertex_2d(RID p_immediate, const Vector2 &p_vertex) {
|
|
|
|
immediate_vertex(p_immediate, Vector3(p_vertex.x, p_vertex.y, 0));
|
2016-11-23 11:04:55 +01:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
RID VisualServer::instance_create2(RID p_base, RID p_scenario) {
|
|
|
|
|
|
|
|
RID instance = instance_create();
|
2017-03-05 16:44:50 +01:00
|
|
|
instance_set_base(instance, p_base);
|
|
|
|
instance_set_scenario(instance, p_scenario);
|
2014-02-10 02:10:30 +01:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
VisualServer::VisualServer() {
|
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
//ERR_FAIL_COND(singleton);
|
2017-03-05 16:44:50 +01:00
|
|
|
singleton = this;
|
2017-07-18 02:05:38 +02:00
|
|
|
GLOBAL_DEF("rendering/vram_compression/import_s3tc", true);
|
|
|
|
GLOBAL_DEF("rendering/vram_compression/import_etc", false);
|
|
|
|
GLOBAL_DEF("rendering/vram_compression/import_etc2", true);
|
|
|
|
GLOBAL_DEF("rendering/vram_compression/import_pvrtc", false);
|
|
|
|
|
|
|
|
GLOBAL_DEF("rendering/quality/directional_shadow/size", 4096);
|
2017-07-19 22:00:46 +02:00
|
|
|
GLOBAL_DEF("rendering/quality/directional_shadow/size.mobile", 2048);
|
2017-07-18 02:05:38 +02:00
|
|
|
GLOBAL_DEF("rendering/quality/shadow_atlas/size", 4096);
|
2017-07-19 22:00:46 +02:00
|
|
|
GLOBAL_DEF("rendering/quality/shadow_atlas/size.mobile", 2048);
|
2017-07-26 15:03:13 +02:00
|
|
|
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/size", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/size", PROPERTY_HINT_RANGE, "256,16384"));
|
2017-07-18 02:05:38 +02:00
|
|
|
GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_0_subdiv", 1);
|
|
|
|
GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_1_subdiv", 2);
|
|
|
|
GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_2_subdiv", 3);
|
|
|
|
GLOBAL_DEF("rendering/quality/shadow_atlas/quadrant_3_subdiv", 4);
|
2017-07-19 22:00:46 +02:00
|
|
|
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/quadrant_0_subdiv", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/quadrant_0_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"));
|
|
|
|
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/quadrant_1_subdiv", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/quadrant_1_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"));
|
|
|
|
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/quadrant_2_subdiv", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/quadrant_2_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"));
|
|
|
|
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadow_atlas/quadrant_3_subdiv", PropertyInfo(Variant::INT, "rendering/quality/shadow_atlas/quadrant_3_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"));
|
|
|
|
|
|
|
|
GLOBAL_DEF("rendering/quality/shadows/filter_mode", 1);
|
|
|
|
GLOBAL_DEF("rendering/quality/shadows/filter_mode.mobile", 0);
|
|
|
|
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/shadows/filter_mode", PropertyInfo(Variant::INT, "rendering/quality/shadows/filter_mode", PROPERTY_HINT_ENUM, "Disabled,PCF5,PCF13"));
|
|
|
|
|
|
|
|
GLOBAL_DEF("rendering/quality/reflections/texture_array_reflections", true);
|
|
|
|
GLOBAL_DEF("rendering/quality/reflections/texture_array_reflections.mobile", false);
|
2017-07-22 19:07:38 +02:00
|
|
|
GLOBAL_DEF("rendering/quality/reflections/high_quality_ggx", true);
|
|
|
|
GLOBAL_DEF("rendering/quality/reflections/high_quality_ggx.mobile", false);
|
|
|
|
|
|
|
|
GLOBAL_DEF("rendering/quality/shading/force_vertex_shading", false);
|
|
|
|
GLOBAL_DEF("rendering/quality/shading/force_vertex_shading.mobile", true);
|
|
|
|
|
|
|
|
GLOBAL_DEF("rendering/quality/depth_prepass/enable", true);
|
|
|
|
GLOBAL_DEF("rendering/quality/depth_prepass/disable_for_vendors", "PowerVR,Mali,Adreno");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualServer::~VisualServer() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
singleton = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|