Removed bone support.

This commit is contained in:
Relintai 2023-12-15 22:37:50 +01:00
parent d42e99ecde
commit 79aac5f505
12 changed files with 146 additions and 1065 deletions

View File

@ -404,22 +404,6 @@ void RasterizerCanvasBaseGLES2::_draw_polygon(const int *p_indices, int p_index_
glDisableVertexAttribArray(RS::ARRAY_TEX_UV);
}
if (p_weights && p_bones) {
RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(float) * 4 * p_vertex_count, p_weights, buffer_ofs_after));
glEnableVertexAttribArray(RS::ARRAY_WEIGHTS);
glVertexAttribPointer(RS::ARRAY_WEIGHTS, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 4, CAST_INT_TO_UCHAR_PTR(buffer_ofs));
buffer_ofs = buffer_ofs_after;
RAST_FAIL_COND(!storage->safe_buffer_sub_data(data.polygon_buffer_size, GL_ARRAY_BUFFER, buffer_ofs, sizeof(int) * 4 * p_vertex_count, p_bones, buffer_ofs_after));
glEnableVertexAttribArray(RS::ARRAY_BONES);
glVertexAttribPointer(RS::ARRAY_BONES, 4, GL_UNSIGNED_INT, GL_FALSE, sizeof(int) * 4, CAST_INT_TO_UCHAR_PTR(buffer_ofs));
buffer_ofs = buffer_ofs_after;
} else {
glDisableVertexAttribArray(RS::ARRAY_WEIGHTS);
glDisableVertexAttribArray(RS::ARRAY_BONES);
}
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer);
if (storage->config.support_32_bits_indices) { //should check for

View File

@ -222,13 +222,6 @@ void RasterizerCanvasGLES2::_batch_render_generic(const Batch &p_batch, Rasteriz
glVertexAttribPointer(RS::ARRAY_TEX_UV2, 4, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (9 * 4)));
}
if (use_large_verts) {
glEnableVertexAttribArray(RS::ARRAY_BONES);
glVertexAttribPointer(RS::ARRAY_BONES, 2, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (13 * 4)));
glEnableVertexAttribArray(RS::ARRAY_WEIGHTS);
glVertexAttribPointer(RS::ARRAY_WEIGHTS, 4, GL_FLOAT, GL_FALSE, sizeof_vert, CAST_INT_TO_UCHAR_PTR(pointer + (15 * 4)));
}
// We only want to set the GL wrapping mode if the texture is not already tiled (i.e. set in Import).
// This is an optimization left over from the legacy renderer.
// If we DID set tiling in the API, and reverted to clamped, then the next draw using this texture
@ -289,8 +282,6 @@ void RasterizerCanvasGLES2::_batch_render_generic(const Batch &p_batch, Rasteriz
glDisableVertexAttribArray(RS::ARRAY_COLOR);
glDisableVertexAttribArray(RS::ARRAY_TANGENT);
glDisableVertexAttribArray(RS::ARRAY_TEX_UV2);
glDisableVertexAttribArray(RS::ARRAY_BONES);
glDisableVertexAttribArray(RS::ARRAY_WEIGHTS);
// may not be necessary .. state change optimization still TODO
glBindBuffer(GL_ARRAY_BUFFER, 0);

View File

@ -435,7 +435,7 @@ void RasterizerSceneGLES2::_setup_geometry(RenderList::Element *p_element) {
if (s->attribs[i].enabled) {
glEnableVertexAttribArray(i);
if (!s->blend_shape_data.empty() && i != RS::ARRAY_BONES && s->blend_shape_buffer_size > 0) {
if (!s->blend_shape_data.empty() && s->blend_shape_buffer_size > 0) {
glBindBuffer(GL_ARRAY_BUFFER, s->blend_shape_buffer_id);
// When using octahedral compression (2 component normal/tangent)
// decompression changes the component count to 3/4
@ -535,20 +535,6 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) {
glDrawArrays(gl_primitive[s->primitive], 0, s->array_len);
storage->info.render.vertices_count += s->array_len;
}
/*
if (p_element->instance->skeleton.is_valid() && s->attribs[RS::ARRAY_BONES].enabled && s->attribs[RS::ARRAY_WEIGHTS].enabled) {
//clean up after skeleton
glBindBuffer(GL_ARRAY_BUFFER, storage->resources.skeleton_transform_buffer);
glDisableVertexAttribArray(RS::ARRAY_MAX + 0);
glDisableVertexAttribArray(RS::ARRAY_MAX + 1);
glDisableVertexAttribArray(RS::ARRAY_MAX + 2);
glVertexAttrib4f(RS::ARRAY_MAX + 0, 1, 0, 0, 0);
glVertexAttrib4f(RS::ARRAY_MAX + 1, 0, 1, 0, 0);
glVertexAttrib4f(RS::ARRAY_MAX + 2, 0, 0, 1, 0);
}
*/
} break;
case RS::INSTANCE_MULTIMESH: {
@ -633,8 +619,6 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
RasterizerStorageGLES2::Geometry *prev_geometry = nullptr;
RasterizerStorageGLES2::GeometryOwner *prev_owner = nullptr;
bool prev_octahedral_compression = false;
Transform view_transform_inverse = p_view_transform.inverse();
Projection projection_inverse = p_projection.inverse();
@ -776,13 +760,6 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
state.scene_shader.set_conditional(SceneShaderGLES2::USE_PHYSICAL_LIGHT_ATTENUATION, storage->config.use_physical_light_attenuation);
bool octahedral_compression = ((RasterizerStorageGLES2::Surface *)e->geometry)->format & RenderingServer::ArrayFormat::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION &&
(((RasterizerStorageGLES2::Surface *)e->geometry)->blend_shape_data.empty() || ((RasterizerStorageGLES2::Surface *)e->geometry)->blend_shape_buffer_size == 0);
if (octahedral_compression != prev_octahedral_compression) {
state.scene_shader.set_conditional(SceneShaderGLES2::ENABLE_OCTAHEDRAL_COMPRESSION, octahedral_compression);
rebind = true;
}
bool shader_rebind = false;
if (rebind || material != prev_material) {
storage->info.render.material_switch_count++;
@ -827,7 +804,6 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
prev_owner = e->owner;
prev_material = material;
prev_instancing = instancing;
prev_octahedral_compression = octahedral_compression;
}
state.scene_shader.set_conditional(SceneShaderGLES2::ENABLE_OCTAHEDRAL_COMPRESSION, false);

View File

@ -1954,10 +1954,6 @@ static PoolVector<uint8_t> _unpack_half_floats(const PoolVector<uint8_t> &array,
} break;
case RS::ARRAY_NORMAL: {
if (p_format & RS::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
src_size[i] = 4;
dst_size[i] = 4;
} else {
if (p_format & RS::ARRAY_COMPRESS_NORMAL) {
src_size[i] = 4;
dst_size[i] = 4;
@ -1965,23 +1961,9 @@ static PoolVector<uint8_t> _unpack_half_floats(const PoolVector<uint8_t> &array,
src_size[i] = 12;
dst_size[i] = 12;
}
}
} break;
case RS::ARRAY_TANGENT: {
if (p_format & RS::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
if (!(p_format & RS::ARRAY_COMPRESS_TANGENT && p_format & RS::ARRAY_COMPRESS_NORMAL)) {
src_size[RS::ARRAY_NORMAL] = 8;
dst_size[RS::ARRAY_NORMAL] = 8;
// These must be incremented manually,
// as we are modifying a previous attribute size.
src_stride += 4;
dst_stride += 4;
}
src_size[i] = 0;
dst_size[i] = 0;
} else {
if (p_format & RS::ARRAY_COMPRESS_TANGENT) {
src_size[i] = 4;
dst_size[i] = 4;
@ -1989,7 +1971,6 @@ static PoolVector<uint8_t> _unpack_half_floats(const PoolVector<uint8_t> &array,
src_size[i] = 16;
dst_size[i] = 16;
}
}
} break;
case RS::ARRAY_COLOR: {
@ -2025,26 +2006,6 @@ static PoolVector<uint8_t> _unpack_half_floats(const PoolVector<uint8_t> &array,
dst_size[i] = 8;
} break;
case RS::ARRAY_BONES: {
if (p_format & RS::ARRAY_FLAG_USE_16_BIT_BONES) {
src_size[i] = 8;
dst_size[i] = 8;
} else {
src_size[i] = 4;
dst_size[i] = 4;
}
} break;
case RS::ARRAY_WEIGHTS: {
if (p_format & RS::ARRAY_COMPRESS_WEIGHTS) {
src_size[i] = 8;
dst_size[i] = 8;
} else {
src_size[i] = 16;
dst_size[i] = 16;
}
} break;
case RS::ARRAY_INDEX: {
src_size[i] = 0;
@ -2108,12 +2069,6 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, RS:
ERR_FAIL_COND(!(p_format & RS::ARRAY_FORMAT_VERTEX));
//must have index and bones, both.
{
uint32_t bones_weight = RS::ARRAY_FORMAT_BONES | RS::ARRAY_FORMAT_WEIGHTS;
ERR_FAIL_COND_MSG((p_format & bones_weight) && (p_format & bones_weight) != bones_weight, "Array must have both bones and weights in format or none.");
}
//bool has_morph = p_blend_shapes.size();
bool use_split_stream = GLOBAL_GET("rendering/misc/mesh_storage/split_stream") && !(p_format & RS::ARRAY_FLAG_USE_DYNAMIC_UPDATE);
@ -2164,17 +2119,6 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, RS:
} break;
case RS::ARRAY_NORMAL: {
if (p_format & RS::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
// Always pack normal and tangent into vec4
// normal will be xy tangent will be zw
// normal will always be oct32 encoded
// UNLESS tangent exists and is also compressed
// then it will be oct16 encoded along with tangent
attribs[i].normalized = GL_TRUE;
attribs[i].size = 2;
attribs[i].type = GL_SHORT;
attributes_stride += 4;
} else {
attribs[i].size = 3;
if (p_format & RS::ARRAY_COMPRESS_NORMAL) {
@ -2186,23 +2130,9 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, RS:
attributes_stride += 12;
attribs[i].normalized = GL_FALSE;
}
}
} break;
case RS::ARRAY_TANGENT: {
if (p_format & RS::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
attribs[i].enabled = false;
attribs[RS::ARRAY_NORMAL].size = 4;
if (p_format & RS::ARRAY_COMPRESS_TANGENT && p_format & RS::ARRAY_COMPRESS_NORMAL) {
// normal and tangent will each be oct16 (2 bytes each)
// pack into single vec4<GL_BYTE> for memory bandwidth
// savings while keeping 4 byte alignment
attribs[RS::ARRAY_NORMAL].type = GL_BYTE;
} else {
// normal and tangent will each be oct32 (4 bytes each)
attributes_stride += 4;
}
} else {
attribs[i].size = 4;
if (p_format & RS::ARRAY_COMPRESS_TANGENT) {
@ -2214,7 +2144,6 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, RS:
attributes_stride += 16;
attribs[i].normalized = GL_FALSE;
}
}
} break;
case RS::ARRAY_COLOR: {
@ -2259,35 +2188,6 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, RS:
}
attribs[i].normalized = GL_FALSE;
} break;
case RS::ARRAY_BONES: {
attribs[i].size = 4;
if (p_format & RS::ARRAY_FLAG_USE_16_BIT_BONES) {
attribs[i].type = GL_UNSIGNED_SHORT;
attributes_stride += 8;
} else {
attribs[i].type = GL_UNSIGNED_BYTE;
attributes_stride += 4;
}
attribs[i].normalized = GL_FALSE;
attribs[i].integer = true;
} break;
case RS::ARRAY_WEIGHTS: {
attribs[i].size = 4;
if (p_format & RS::ARRAY_COMPRESS_WEIGHTS) {
attribs[i].type = GL_UNSIGNED_SHORT;
attributes_stride += 8;
attribs[i].normalized = GL_TRUE;
} else {
attribs[i].type = GL_FLOAT;
attributes_stride += 16;
attribs[i].normalized = GL_FALSE;
}
} break;
case RS::ARRAY_INDEX: {
attribs[i].size = 1;
@ -3290,21 +3190,6 @@ void RasterizerStorageGLES2::update_dirty_blend_shapes() {
}
} break;
case RS::ARRAY_NORMAL: {
if (s->format & RS::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
if (s->format & RS::ARRAY_COMPRESS_NORMAL && s->format & RS::ARRAY_FORMAT_TANGENT && s->format & RS::ARRAY_COMPRESS_TANGENT) {
Vector2 oct(((int8_t *)rd)[0] / 127.0, ((int8_t *)rd)[1] / 127.0);
Vector3 vec = RS::oct_to_norm(oct);
wr[0] = vec.x * base_weight;
wr[1] = vec.y * base_weight;
wr[2] = vec.z * base_weight;
} else {
Vector2 oct(((int16_t *)rd)[0] / 32767.0, ((int16_t *)rd)[1] / 32767.0);
Vector3 vec = RS::oct_to_norm(oct);
wr[0] = vec.x * base_weight;
wr[1] = vec.y * base_weight;
wr[2] = vec.z * base_weight;
}
} else {
if (s->format & RS::ARRAY_COMPRESS_NORMAL) {
wr[0] = (((int8_t *)rd)[0] / 127.0) * base_weight;
wr[1] = (((int8_t *)rd)[1] / 127.0) * base_weight;
@ -3314,28 +3199,9 @@ void RasterizerStorageGLES2::update_dirty_blend_shapes() {
wr[1] = rd[1] * base_weight;
wr[2] = rd[2] * base_weight;
}
}
} break;
case RS::ARRAY_TANGENT: {
if (s->format & RS::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
if (s->format & RS::ARRAY_COMPRESS_TANGENT && s->format & RS::ARRAY_FORMAT_NORMAL && s->format & RS::ARRAY_COMPRESS_NORMAL) {
Vector2 oct(((int8_t *)rd)[0] / 127.0, ((int8_t *)rd)[1] / 127.0);
float sign;
Vector3 vec = RS::oct_to_tangent(oct, &sign);
wr[0] = vec.x * base_weight;
wr[1] = vec.y * base_weight;
wr[2] = vec.z * base_weight;
wr[3] = sign * base_weight;
} else {
Vector2 oct(((int16_t *)rd)[0] / 32767.0, ((int16_t *)rd)[1] / 32767.0);
float sign;
Vector3 vec = RS::oct_to_tangent(oct, &sign);
wr[0] = vec.x * base_weight;
wr[1] = vec.y * base_weight;
wr[2] = vec.z * base_weight;
wr[3] = sign * base_weight;
}
} else {
if (s->format & RS::ARRAY_COMPRESS_TANGENT) {
wr[0] = (((int8_t *)rd)[0] / 127.0) * base_weight;
wr[1] = (((int8_t *)rd)[1] / 127.0) * base_weight;
@ -3347,7 +3213,7 @@ void RasterizerStorageGLES2::update_dirty_blend_shapes() {
wr[2] = rd[2] * base_weight;
wr[3] = rd[3] * base_weight;
}
}
} break;
case RS::ARRAY_COLOR: {
if (s->format & RS::ARRAY_COMPRESS_COLOR) {
@ -3380,19 +3246,6 @@ void RasterizerStorageGLES2::update_dirty_blend_shapes() {
wr[1] = rd[1] * base_weight;
}
} break;
case RS::ARRAY_WEIGHTS: {
if (s->format & RS::ARRAY_COMPRESS_WEIGHTS) {
wr[0] = (((uint16_t *)rd)[0] / 65535.0) * base_weight;
wr[1] = (((uint16_t *)rd)[1] / 65535.0) * base_weight;
wr[2] = (((uint16_t *)rd)[2] / 65535.0) * base_weight;
wr[3] = (((uint16_t *)rd)[3] / 65535.0) * base_weight;
} else {
wr[0] = rd[0] * base_weight;
wr[1] = rd[1] * base_weight;
wr[2] = rd[2] * base_weight;
wr[3] = rd[3] * base_weight;
}
} break;
}
// Add all blend shapes
@ -3419,21 +3272,6 @@ void RasterizerStorageGLES2::update_dirty_blend_shapes() {
}
} break;
case RS::ARRAY_NORMAL: {
if (s->format & RS::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
if (s->format & RS::ARRAY_COMPRESS_NORMAL && s->format & RS::ARRAY_FORMAT_TANGENT && s->format & RS::ARRAY_COMPRESS_TANGENT) {
Vector2 oct(((int8_t *)br)[0] / 127.0, ((int8_t *)br)[1] / 127.0);
Vector3 vec = RS::oct_to_norm(oct);
wr[0] += vec.x * weight;
wr[1] += vec.y * weight;
wr[2] += vec.z * weight;
} else {
Vector2 oct(((int16_t *)br)[0] / 32767.0, ((int16_t *)br)[1] / 32767.0);
Vector3 vec = RS::oct_to_norm(oct);
wr[0] += vec.x * weight;
wr[1] += vec.y * weight;
wr[2] += vec.z * weight;
}
} else {
if (s->format & RS::ARRAY_COMPRESS_NORMAL) {
wr[0] += (float(((int8_t *)br)[0]) / 127.0) * weight;
wr[1] += (float(((int8_t *)br)[1]) / 127.0) * weight;
@ -3443,28 +3281,9 @@ void RasterizerStorageGLES2::update_dirty_blend_shapes() {
wr[1] += br[1] * weight;
wr[2] += br[2] * weight;
}
}
} break;
case RS::ARRAY_TANGENT: {
if (s->format & RS::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
if (s->format & RS::ARRAY_COMPRESS_TANGENT && s->format & RS::ARRAY_FORMAT_NORMAL && s->format & RS::ARRAY_COMPRESS_NORMAL) {
Vector2 oct(((int8_t *)br)[0] / 127.0, ((int8_t *)br)[1] / 127.0);
float sign;
Vector3 vec = RS::oct_to_tangent(oct, &sign);
wr[0] += vec.x * weight;
wr[1] += vec.y * weight;
wr[2] += vec.z * weight;
wr[3] = sign * weight;
} else {
Vector2 oct(((int16_t *)rd)[0] / 32767.0, ((int16_t *)rd)[1] / 32767.0);
float sign;
Vector3 vec = RS::oct_to_tangent(oct, &sign);
wr[0] += vec.x * weight;
wr[1] += vec.y * weight;
wr[2] += vec.z * weight;
wr[3] = sign * weight;
}
} else {
if (s->format & RS::ARRAY_COMPRESS_TANGENT) {
wr[0] += (float(((int8_t *)br)[0]) / 127.0) * weight;
wr[1] += (float(((int8_t *)br)[1]) / 127.0) * weight;
@ -3476,7 +3295,7 @@ void RasterizerStorageGLES2::update_dirty_blend_shapes() {
wr[2] += br[2] * weight;
wr[3] = br[3];
}
}
} break;
case RS::ARRAY_COLOR: {
if (s->format & RS::ARRAY_COMPRESS_COLOR) {
@ -3509,19 +3328,6 @@ void RasterizerStorageGLES2::update_dirty_blend_shapes() {
wr[1] += br[1] * weight;
}
} break;
case RS::ARRAY_WEIGHTS: {
if (s->format & RS::ARRAY_COMPRESS_WEIGHTS) {
wr[0] += (((uint16_t *)br)[0] / 65535.0) * weight;
wr[1] += (((uint16_t *)br)[1] / 65535.0) * weight;
wr[2] += (((uint16_t *)br)[2] / 65535.0) * weight;
wr[3] += (((uint16_t *)br)[3] / 65535.0) * weight;
} else {
wr[0] += br[0] * weight;
wr[1] += br[1] * weight;
wr[2] += br[2] * weight;
wr[3] += br[3] * weight;
}
} break;
}
}
}

View File

@ -237,9 +237,7 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
dst.append_array(src);
arrays[j] = dst;
} break;
case ARRAY_TANGENT:
case ARRAY_BONES:
case ARRAY_WEIGHTS: {
case ARRAY_TANGENT:{
PoolVector<real_t> dst = arrays[j];
PoolVector<real_t> src = a[j];
if (dst.size() == 0 || src.size() == 0) {
@ -423,8 +421,6 @@ void Mesh::_bind_methods() {
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);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_BASE);
@ -434,13 +430,9 @@ void Mesh::_bind_methods() {
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_COLOR);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TEX_UV);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TEX_UV2);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_BONES);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_WEIGHTS);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_INDEX);
BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_2D_VERTICES);
BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_16_BIT_BONES);
BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_DEFAULT);
@ -450,8 +442,6 @@ void Mesh::_bind_methods() {
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);
BIND_ENUM_CONSTANT(ARRAY_MAX);
}
@ -990,8 +980,6 @@ void ArrayMesh::_bind_methods() {
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);
BIND_ENUM_CONSTANT(ARRAY_MAX);
@ -1001,8 +989,6 @@ void ArrayMesh::_bind_methods() {
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);
}

View File

@ -61,8 +61,6 @@ public:
ARRAY_COLOR = RenderingServer::ARRAY_COLOR,
ARRAY_TEX_UV = RenderingServer::ARRAY_TEX_UV,
ARRAY_TEX_UV2 = RenderingServer::ARRAY_TEX_UV2,
ARRAY_BONES = RenderingServer::ARRAY_BONES,
ARRAY_WEIGHTS = RenderingServer::ARRAY_WEIGHTS,
ARRAY_INDEX = RenderingServer::ARRAY_INDEX,
ARRAY_MAX = RenderingServer::ARRAY_MAX
@ -76,8 +74,6 @@ public:
ARRAY_FORMAT_COLOR = 1 << ARRAY_COLOR,
ARRAY_FORMAT_TEX_UV = 1 << ARRAY_TEX_UV,
ARRAY_FORMAT_TEX_UV2 = 1 << ARRAY_TEX_UV2,
ARRAY_FORMAT_BONES = 1 << ARRAY_BONES,
ARRAY_FORMAT_WEIGHTS = 1 << ARRAY_WEIGHTS,
ARRAY_FORMAT_INDEX = 1 << ARRAY_INDEX,
ARRAY_COMPRESS_BASE = (ARRAY_INDEX + 1),
@ -87,16 +83,12 @@ public:
ARRAY_COMPRESS_COLOR = 1 << (ARRAY_COLOR + ARRAY_COMPRESS_BASE),
ARRAY_COMPRESS_TEX_UV = 1 << (ARRAY_TEX_UV + ARRAY_COMPRESS_BASE),
ARRAY_COMPRESS_TEX_UV2 = 1 << (ARRAY_TEX_UV2 + ARRAY_COMPRESS_BASE),
ARRAY_COMPRESS_BONES = 1 << (ARRAY_BONES + ARRAY_COMPRESS_BASE),
ARRAY_COMPRESS_WEIGHTS = 1 << (ARRAY_WEIGHTS + ARRAY_COMPRESS_BASE),
ARRAY_COMPRESS_INDEX = 1 << (ARRAY_INDEX + ARRAY_COMPRESS_BASE),
ARRAY_FLAG_USE_2D_VERTICES = ARRAY_COMPRESS_INDEX << 1,
ARRAY_FLAG_USE_16_BIT_BONES = ARRAY_COMPRESS_INDEX << 2,
ARRAY_FLAG_USE_DYNAMIC_UPDATE = ARRAY_COMPRESS_INDEX << 3,
ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION = ARRAY_COMPRESS_INDEX << 4,
ARRAY_FLAG_USE_DYNAMIC_UPDATE = ARRAY_COMPRESS_INDEX << 2,
ARRAY_COMPRESS_DEFAULT = ARRAY_COMPRESS_NORMAL | ARRAY_COMPRESS_TANGENT | ARRAY_COMPRESS_COLOR | ARRAY_COMPRESS_TEX_UV | ARRAY_COMPRESS_TEX_UV2 | ARRAY_COMPRESS_WEIGHTS | ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION
ARRAY_COMPRESS_DEFAULT = ARRAY_COMPRESS_NORMAL | ARRAY_COMPRESS_TANGENT | ARRAY_COMPRESS_COLOR | ARRAY_COMPRESS_TEX_UV | ARRAY_COMPRESS_TEX_UV2
};

View File

@ -102,16 +102,6 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf
col = arrays[Mesh::ARRAY_COLOR].operator PoolVector<Color>().read();
}
PoolVector<int>::Read bo;
if (arrays[Mesh::ARRAY_BONES].get_type() != Variant::NIL) {
bo = arrays[Mesh::ARRAY_BONES].operator PoolVector<int>().read();
}
PoolVector<real_t>::Read we;
if (arrays[Mesh::ARRAY_WEIGHTS].get_type() != Variant::NIL) {
we = arrays[Mesh::ARRAY_WEIGHTS].operator PoolVector<real_t>().read();
}
vertices.resize(vcount);
for (int i = 0; i < vcount; i++) {
@ -133,20 +123,6 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf
v.color = col[i];
}
if (we.ptr()) {
v.weights.push_back(we[i * 4 + 0]);
v.weights.push_back(we[i * 4 + 1]);
v.weights.push_back(we[i * 4 + 2]);
v.weights.push_back(we[i * 4 + 3]);
}
if (bo.ptr()) {
v.bones.push_back(bo[i * 4 + 0]);
v.bones.push_back(bo[i * 4 + 1]);
v.bones.push_back(bo[i * 4 + 2]);
v.bones.push_back(bo[i * 4 + 3]);
}
vertices.write[i] = v;
}
@ -241,18 +217,6 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) {
col = c.write();
}
PoolVector<int>::Write bo;
if (format & Mesh::ARRAY_FORMAT_BONES) {
b.resize(vcount * 4);
bo = b.write();
}
PoolVector<real_t>::Write we;
if (format & Mesh::ARRAY_FORMAT_WEIGHTS) {
w.resize(vcount * 4);
we = w.write();
}
for (int i = 0; i < vcount; i++) {
const Vertex &vtx = vertices[i];
@ -275,20 +239,6 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) {
if (col.ptr()) {
col[i] = vtx.color;
}
if (we.ptr()) {
we[i * 4 + 0] = vtx.weights[0];
we[i * 4 + 1] = vtx.weights[1];
we[i * 4 + 2] = vtx.weights[2];
we[i * 4 + 3] = vtx.weights[3];
}
if (bo.ptr()) {
bo[i * 4 + 0] = vtx.bones[0];
bo[i * 4 + 1] = vtx.bones[1];
bo[i * 4 + 2] = vtx.bones[2];
bo[i * 4 + 3] = vtx.bones[3];
}
}
int fc = faces.size();
@ -318,12 +268,6 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) {
if (t.size()) {
arr[Mesh::ARRAY_TANGENT] = t;
}
if (b.size()) {
arr[Mesh::ARRAY_BONES] = b;
}
if (w.size()) {
arr[Mesh::ARRAY_WEIGHTS] = w;
}
Ref<ArrayMesh> ncmesh = p_mesh;
int sc = ncmesh->get_surface_count();
@ -406,28 +350,6 @@ void MeshDataTool::set_vertex_color(int p_idx, const Color &p_color) {
format |= Mesh::ARRAY_FORMAT_COLOR;
}
Vector<int> MeshDataTool::get_vertex_bones(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, vertices.size(), Vector<int>());
return vertices[p_idx].bones;
}
void MeshDataTool::set_vertex_bones(int p_idx, const Vector<int> &p_bones) {
ERR_FAIL_INDEX(p_idx, vertices.size());
ERR_FAIL_COND(p_bones.size() != 4);
vertices.write[p_idx].bones = p_bones;
format |= Mesh::ARRAY_FORMAT_BONES;
}
Vector<float> MeshDataTool::get_vertex_weights(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, vertices.size(), Vector<float>());
return vertices[p_idx].weights;
}
void MeshDataTool::set_vertex_weights(int p_idx, const Vector<float> &p_weights) {
ERR_FAIL_INDEX(p_idx, vertices.size());
ERR_FAIL_COND(p_weights.size() != 4);
vertices.write[p_idx].weights = p_weights;
format |= Mesh::ARRAY_FORMAT_WEIGHTS;
}
Variant MeshDataTool::get_vertex_meta(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, vertices.size(), Variant());
return vertices[p_idx].meta;
@ -530,12 +452,6 @@ void MeshDataTool::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_vertex_color", "idx", "color"), &MeshDataTool::set_vertex_color);
ClassDB::bind_method(D_METHOD("get_vertex_color", "idx"), &MeshDataTool::get_vertex_color);
ClassDB::bind_method(D_METHOD("set_vertex_bones", "idx", "bones"), &MeshDataTool::set_vertex_bones);
ClassDB::bind_method(D_METHOD("get_vertex_bones", "idx"), &MeshDataTool::get_vertex_bones);
ClassDB::bind_method(D_METHOD("set_vertex_weights", "idx", "weights"), &MeshDataTool::set_vertex_weights);
ClassDB::bind_method(D_METHOD("get_vertex_weights", "idx"), &MeshDataTool::get_vertex_weights);
ClassDB::bind_method(D_METHOD("set_vertex_meta", "idx", "meta"), &MeshDataTool::set_vertex_meta);
ClassDB::bind_method(D_METHOD("get_vertex_meta", "idx"), &MeshDataTool::get_vertex_meta);

View File

@ -43,8 +43,6 @@ class MeshDataTool : public Reference {
Plane tangent;
Vector2 uv;
Vector2 uv2;
Vector<int> bones;
Vector<float> weights;
Vector<int> edges;
Vector<int> faces;
Variant meta;
@ -102,12 +100,6 @@ public:
Color get_vertex_color(int p_idx) const;
void set_vertex_color(int p_idx, const Color &p_color);
Vector<int> get_vertex_bones(int p_idx) const;
void set_vertex_bones(int p_idx, const Vector<int> &p_bones);
Vector<float> get_vertex_weights(int p_idx) const;
void set_vertex_weights(int p_idx, const Vector<float> &p_weights);
Variant get_vertex_meta(int p_idx) const;
void set_vertex_meta(int p_idx, const Variant &p_meta);

View File

@ -60,22 +60,6 @@ bool SurfaceTool::Vertex::operator==(const Vertex &p_vertex) const {
return false;
}
if (num_bones != p_vertex.num_bones) {
return false;
}
for (int i = 0; i < num_bones; i++) {
if (bones[i] != p_vertex.bones[i]) {
return false;
}
}
for (int i = 0; i < num_bones; i++) {
if (weights[i] != p_vertex.weights[i]) {
return false;
}
}
return true;
}
@ -87,8 +71,6 @@ uint32_t SurfaceTool::VertexHasher::hash(const Vertex &p_vtx) {
h = hash_djb2_buffer((const uint8_t *)&p_vtx.uv, sizeof(real_t) * 2, h);
h = hash_djb2_buffer((const uint8_t *)&p_vtx.uv2, sizeof(real_t) * 2, h);
h = hash_djb2_buffer((const uint8_t *)&p_vtx.color, sizeof(real_t) * 4, h);
h = hash_djb2_buffer((const uint8_t *)p_vtx.bones, p_vtx.num_bones * sizeof(int16_t), h);
h = hash_djb2_buffer((const uint8_t *)p_vtx.weights, p_vtx.num_bones * sizeof(float), h);
return h;
}
@ -165,16 +147,6 @@ void SurfaceTool::add_vertex(const Vector3 &p_vertex) {
vtx.tangent = last_tangent.normal;
vtx.binormal = last_normal.cross(last_tangent.normal).normalized() * last_tangent.d;
if (format & Mesh::ARRAY_FORMAT_WEIGHTS || format & Mesh::ARRAY_FORMAT_BONES) {
ERR_FAIL_COND(!_sanitize_last_bones_and_weights());
vtx.num_bones = last_bones.size();
for (int n = 0; n < last_bones.size(); n++) {
vtx.bones[n] = last_bones[n];
vtx.weights[n] = last_weights[n];
}
}
vertex_array.push_back(vtx);
first = false;
@ -221,22 +193,6 @@ void SurfaceTool::add_uv2(const Vector2 &p_uv2) {
last_uv2 = p_uv2;
}
void SurfaceTool::add_bones(const Vector<int> &p_bones) {
ERR_FAIL_COND(!begun);
ERR_FAIL_COND(!first && !(format & Mesh::ARRAY_FORMAT_BONES));
format |= Mesh::ARRAY_FORMAT_BONES;
last_bones = p_bones;
}
void SurfaceTool::add_weights(const Vector<float> &p_weights) {
ERR_FAIL_COND(!begun);
ERR_FAIL_COND(!first && !(format & Mesh::ARRAY_FORMAT_WEIGHTS));
format |= Mesh::ARRAY_FORMAT_WEIGHTS;
last_weights = p_weights;
}
void SurfaceTool::add_smooth_group(bool p_smooth) {
ERR_FAIL_COND(!begun);
@ -375,45 +331,6 @@ Array SurfaceTool::commit_to_arrays() {
w.release();
a[i] = array;
} break;
case Mesh::ARRAY_BONES: {
PoolVector<int> array;
array.resize(varr_len * Vertex::MAX_BONES);
PoolVector<int>::Write w = array.write();
int idx = 0;
for (uint32_t n = 0; n < vertex_array.size(); n++, idx += Vertex::MAX_BONES) {
const Vertex &v = vertex_array[n];
ERR_CONTINUE(v.num_bones != Vertex::MAX_BONES);
for (int j = 0; j < Vertex::MAX_BONES; j++) {
w[idx + j] = v.bones[j];
}
}
w.release();
a[i] = array;
} break;
case Mesh::ARRAY_WEIGHTS: {
PoolVector<float> array;
array.resize(varr_len * Vertex::MAX_BONES);
PoolVector<float>::Write w = array.write();
int idx = 0;
for (uint32_t n = 0; n < vertex_array.size(); n++, idx += Vertex::MAX_BONES) {
const Vertex &v = vertex_array[n];
ERR_CONTINUE(v.num_bones != Vertex::MAX_BONES);
for (int j = 0; j < Vertex::MAX_BONES; j++) {
w[idx + j] = v.weights[j];
}
}
w.release();
a[i] = array;
} break;
case Mesh::ARRAY_INDEX: {
ERR_CONTINUE(index_array.size() == 0);
@ -536,8 +453,6 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array
PoolVector<Color> carr = p_arrays[RS::ARRAY_COLOR];
PoolVector<Vector2> uvarr = p_arrays[RS::ARRAY_TEX_UV];
PoolVector<Vector2> uv2arr = p_arrays[RS::ARRAY_TEX_UV2];
PoolVector<int> barr = p_arrays[RS::ARRAY_BONES];
PoolVector<float> warr = p_arrays[RS::ARRAY_WEIGHTS];
int vc = varr.size();
@ -579,18 +494,6 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array
ruv2 = uv2arr.read();
}
PoolVector<int>::Read rb;
if (barr.size()) {
lformat |= RS::ARRAY_FORMAT_BONES;
rb = barr.read();
}
PoolVector<float>::Read rw;
if (warr.size()) {
lformat |= RS::ARRAY_FORMAT_WEIGHTS;
rw = warr.read();
}
ret.resize(vc);
Vertex *ret_dest = ret.ptrw();
@ -617,18 +520,6 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array
if (lformat & RS::ARRAY_FORMAT_TEX_UV2) {
v.uv2 = uv2arr[i];
}
if (lformat & RS::ARRAY_FORMAT_BONES) {
v.num_bones = Vertex::MAX_BONES;
for (int b = 0; b < Vertex::MAX_BONES; b++) {
v.bones[b] = barr[i * Vertex::MAX_BONES + b];
}
}
if (lformat & RS::ARRAY_FORMAT_WEIGHTS) {
v.num_bones = Vertex::MAX_BONES;
for (int b = 0; b < Vertex::MAX_BONES; b++) {
v.weights[b] = warr[i * Vertex::MAX_BONES + b];
}
}
}
return ret;
@ -641,8 +532,6 @@ void SurfaceTool::_create_list_from_arrays(Array arr, LocalVector<Vertex> *r_ver
PoolVector<Color> carr = arr[RS::ARRAY_COLOR];
PoolVector<Vector2> uvarr = arr[RS::ARRAY_TEX_UV];
PoolVector<Vector2> uv2arr = arr[RS::ARRAY_TEX_UV2];
PoolVector<int> barr = arr[RS::ARRAY_BONES];
PoolVector<float> warr = arr[RS::ARRAY_WEIGHTS];
int vc = varr.size();
@ -684,18 +573,6 @@ void SurfaceTool::_create_list_from_arrays(Array arr, LocalVector<Vertex> *r_ver
ruv2 = uv2arr.read();
}
PoolVector<int>::Read rb;
if (barr.size()) {
lformat |= RS::ARRAY_FORMAT_BONES;
rb = barr.read();
}
PoolVector<float>::Read rw;
if (warr.size()) {
lformat |= RS::ARRAY_FORMAT_WEIGHTS;
rw = warr.read();
}
DEV_ASSERT(vc);
uint32_t start = r_vertex->size();
r_vertex->resize(start + vc);
@ -724,18 +601,6 @@ void SurfaceTool::_create_list_from_arrays(Array arr, LocalVector<Vertex> *r_ver
if (lformat & RS::ARRAY_FORMAT_TEX_UV2) {
v.uv2 = uv2arr[i];
}
if (lformat & RS::ARRAY_FORMAT_BONES) {
v.num_bones = Vertex::MAX_BONES;
for (int b = 0; b < Vertex::MAX_BONES; b++) {
v.bones[b] = barr[i * Vertex::MAX_BONES + b];
}
}
if (lformat & RS::ARRAY_FORMAT_WEIGHTS) {
v.num_bones = Vertex::MAX_BONES;
for (int b = 0; b < Vertex::MAX_BONES; b++) {
v.weights[b] = warr[i * Vertex::MAX_BONES + b];
}
}
}
//indices
@ -1073,8 +938,6 @@ void SurfaceTool::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_tangent", "tangent"), &SurfaceTool::add_tangent);
ClassDB::bind_method(D_METHOD("add_uv", "uv"), &SurfaceTool::add_uv);
ClassDB::bind_method(D_METHOD("add_uv2", "uv2"), &SurfaceTool::add_uv2);
ClassDB::bind_method(D_METHOD("add_bones", "bones"), &SurfaceTool::add_bones);
ClassDB::bind_method(D_METHOD("add_weights", "weights"), &SurfaceTool::add_weights);
ClassDB::bind_method(D_METHOD("add_smooth_group", "smooth"), &SurfaceTool::add_smooth_group);
ClassDB::bind_method(D_METHOD("add_triangle_fan", "vertices", "uvs", "colors", "uv2s", "normals", "tangents"), &SurfaceTool::add_triangle_fan, DEFVAL(Vector<Vector2>()), DEFVAL(Vector<Color>()), DEFVAL(Vector<Vector2>()), DEFVAL(Vector<Vector3>()), DEFVAL(Vector<Plane>()));

View File

@ -49,10 +49,6 @@ public:
Vector2 uv;
Vector2 uv2;
int16_t bones[MAX_BONES];
float weights[MAX_BONES];
int32_t num_bones = 0;
bool operator==(const Vertex &p_vertex) const;
Vertex() {}
@ -121,8 +117,6 @@ public:
void add_tangent(const Plane &p_tangent);
void add_uv(const Vector2 &p_uv);
void add_uv2(const Vector2 &p_uv2);
void add_bones(const Vector<int> &p_bones);
void add_weights(const Vector<float> &p_weights);
void add_smooth_group(bool p_smooth);
void add_triangle_fan(const Vector<Vector3> &p_vertices, const Vector<Vector2> &p_uvs = Vector<Vector2>(), const Vector<Color> &p_colors = Vector<Color>(), const Vector<Vector2> &p_uv2s = Vector<Vector2>(), const Vector<Vector3> &p_normals = Vector<Vector3>(), const Vector<Plane> &p_tangents = Vector<Plane>());

View File

@ -368,8 +368,6 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint
iw = r_index_array.write();
}
int max_bone = 0;
for (int ai = 0; ai < RS::ARRAY_MAX; ai++) {
if (!(p_format & (1 << ai))) { // no array
continue;
@ -468,30 +466,6 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint
// setting vertices means regenerating the AABB
if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
if ((p_format & ARRAY_COMPRESS_NORMAL) && (p_format & ARRAY_FORMAT_TANGENT) && (p_format & ARRAY_COMPRESS_TANGENT)) {
for (int i = 0; i < p_vertex_array_len; i++) {
Vector2 res = norm_to_oct(src[i]);
int8_t vector[2] = {
(int8_t)CLAMP(res.x * 127, -128, 127),
(int8_t)CLAMP(res.y * 127, -128, 127),
};
memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 2);
}
} else {
for (int i = 0; i < p_vertex_array_len; i++) {
Vector2 res = norm_to_oct(src[i]);
int16_t vector[2] = {
(int16_t)CLAMP(res.x * 32767, -32768, 32767),
(int16_t)CLAMP(res.y * 32767, -32768, 32767),
};
memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 4);
}
}
} else {
if (p_format & ARRAY_COMPRESS_NORMAL) {
for (int i = 0; i < p_vertex_array_len; i++) {
int8_t vector[4] = {
@ -510,7 +484,6 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint
memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 3 * 4);
}
}
}
} break;
@ -524,34 +497,6 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint
PoolVector<real_t>::Read read = array.read();
const real_t *src = read.ptr();
if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
if (p_format & ARRAY_COMPRESS_TANGENT) {
for (int i = 0; i < p_vertex_array_len; i++) {
Vector3 source(src[i * 4 + 0], src[i * 4 + 1], src[i * 4 + 2]);
Vector2 res = tangent_to_oct(source, src[i * 4 + 3], false);
int8_t vector[2] = {
(int8_t)CLAMP(res.x * 127, -128, 127),
(int8_t)CLAMP(res.y * 127, -128, 127)
};
memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 2);
}
} else {
for (int i = 0; i < p_vertex_array_len; i++) {
Vector3 source(src[i * 4 + 0], src[i * 4 + 1], src[i * 4 + 2]);
Vector2 res = tangent_to_oct(source, src[i * 4 + 3], true);
int16_t vector[2] = {
(int16_t)CLAMP(res.x * 32767, -32768, 32767),
(int16_t)CLAMP(res.y * 32767, -32768, 32767)
};
memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], vector, 4);
}
}
} else {
if (p_format & ARRAY_COMPRESS_TANGENT) {
for (int i = 0; i < p_vertex_array_len; i++) {
int8_t xyzw[4] = {
@ -576,7 +521,6 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint
memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], xyzw, 4 * 4);
}
}
}
} break;
case RS::ARRAY_COLOR: {
@ -658,73 +602,6 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint
}
}
} break;
case RS::ARRAY_WEIGHTS: {
ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::POOL_REAL_ARRAY, ERR_INVALID_PARAMETER);
PoolVector<real_t> array = p_arrays[ai];
ERR_FAIL_COND_V(array.size() != p_vertex_array_len * RS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER);
PoolVector<real_t>::Read read = array.read();
const real_t *src = read.ptr();
if (p_format & ARRAY_COMPRESS_WEIGHTS) {
for (int i = 0; i < p_vertex_array_len; i++) {
uint16_t data[RS::ARRAY_WEIGHTS_SIZE];
for (int j = 0; j < RS::ARRAY_WEIGHTS_SIZE; j++) {
data[j] = CLAMP(src[i * RS::ARRAY_WEIGHTS_SIZE + j] * 65535, 0, 65535);
}
memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], data, 2 * 4);
}
} else {
for (int i = 0; i < p_vertex_array_len; i++) {
float data[RS::ARRAY_WEIGHTS_SIZE];
for (int j = 0; j < RS::ARRAY_WEIGHTS_SIZE; j++) {
data[j] = src[i * RS::ARRAY_WEIGHTS_SIZE + j];
}
memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], data, 4 * 4);
}
}
} break;
case RS::ARRAY_BONES: {
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);
PoolVector<int> array = p_arrays[ai];
ERR_FAIL_COND_V(array.size() != p_vertex_array_len * RS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER);
PoolVector<int>::Read read = array.read();
const int *src = read.ptr();
if (!(p_format & ARRAY_FLAG_USE_16_BIT_BONES)) {
for (int i = 0; i < p_vertex_array_len; i++) {
uint8_t data[RS::ARRAY_WEIGHTS_SIZE];
for (int j = 0; j < RS::ARRAY_WEIGHTS_SIZE; j++) {
data[j] = CLAMP(src[i * RS::ARRAY_WEIGHTS_SIZE + j], 0, 255);
max_bone = MAX(data[j], max_bone);
}
memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], data, 4);
}
} else {
for (int i = 0; i < p_vertex_array_len; i++) {
uint16_t data[RS::ARRAY_WEIGHTS_SIZE];
for (int j = 0; j < RS::ARRAY_WEIGHTS_SIZE; j++) {
data[j] = src[i * RS::ARRAY_WEIGHTS_SIZE + j];
max_bone = MAX(data[j], max_bone);
}
memcpy(&vw[p_offsets[ai] + i * p_stride[ai]], data, 2 * 4);
}
}
} break;
case RS::ARRAY_INDEX: {
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);
@ -756,59 +633,6 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint
}
}
if (p_format & RS::ARRAY_FORMAT_BONES) {
//create AABBs for each detected bone
int total_bones = max_bone + 1;
bool first = r_bone_aabb.size() == 0;
r_bone_aabb.resize(total_bones);
if (first) {
for (int i = 0; i < total_bones; i++) {
r_bone_aabb.write[i].size = Vector3(-1, -1, -1); //negative means unused
}
}
PoolVector<Vector3> vertices = p_arrays[RS::ARRAY_VERTEX];
PoolVector<int> bones = p_arrays[RS::ARRAY_BONES];
PoolVector<float> weights = p_arrays[RS::ARRAY_WEIGHTS];
bool any_valid = false;
if (vertices.size() && bones.size() == vertices.size() * 4 && weights.size() == bones.size()) {
int vs = vertices.size();
PoolVector<Vector3>::Read rv = vertices.read();
PoolVector<int>::Read rb = bones.read();
PoolVector<float>::Read rw = weights.read();
AABB *bptr = r_bone_aabb.ptrw();
for (int i = 0; i < vs; i++) {
Vector3 v = rv[i];
for (int j = 0; j < 4; j++) {
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);
if (bptr[idx].size.x < 0) {
//first
bptr[idx] = AABB(v, SMALL_VEC3);
any_valid = true;
} else {
bptr[idx].expand_to(v);
}
}
}
}
if (!any_valid && first) {
r_bone_aabb.clear();
}
}
return OK;
}
@ -872,41 +696,24 @@ void RenderingServer::mesh_surface_make_offsets_from_format(uint32_t p_format, i
} break;
case RS::ARRAY_NORMAL: {
if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
// normal will always be oct32 (4 byte) encoded
// UNLESS tangent exists and is also compressed
// then it will be oct16 encoded along with tangent
if ((p_format & ARRAY_COMPRESS_NORMAL) && (p_format & ARRAY_FORMAT_TANGENT) && (p_format & ARRAY_COMPRESS_TANGENT)) {
elem_size = sizeof(uint8_t) * 2;
} else {
elem_size = sizeof(uint16_t) * 2;
}
} else {
if (p_format & ARRAY_COMPRESS_NORMAL) {
elem_size = sizeof(uint32_t);
} else {
elem_size = sizeof(float) * 3;
}
}
r_offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
} break;
case RS::ARRAY_TANGENT: {
if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
if (p_format & ARRAY_COMPRESS_TANGENT && (p_format & ARRAY_FORMAT_NORMAL) && (p_format & ARRAY_COMPRESS_NORMAL)) {
elem_size = sizeof(uint8_t) * 2;
} else {
elem_size = sizeof(uint16_t) * 2;
}
} else {
if (p_format & ARRAY_COMPRESS_TANGENT) {
elem_size = sizeof(uint32_t);
} else {
elem_size = sizeof(float) * 4;
}
}
r_offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
@ -941,26 +748,6 @@ void RenderingServer::mesh_surface_make_offsets_from_format(uint32_t p_format, i
r_offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
} break;
case RS::ARRAY_WEIGHTS: {
if (p_format & ARRAY_COMPRESS_WEIGHTS) {
elem_size = sizeof(uint16_t) * 4;
} else {
elem_size = sizeof(float) * 4;
}
r_offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
} break;
case RS::ARRAY_BONES: {
if (p_format & ARRAY_FLAG_USE_16_BIT_BONES) {
elem_size = sizeof(uint16_t) * 4;
} else {
elem_size = sizeof(uint32_t);
}
r_offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
} break;
case RS::ARRAY_INDEX: {
if (p_index_len <= 0) {
@ -1102,41 +889,24 @@ void RenderingServer::mesh_add_surface_from_arrays(RID p_mesh, PrimitiveType p_p
} break;
case RS::ARRAY_NORMAL: {
if (p_compress_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
// normal will always be oct32 (4 byte) encoded
// UNLESS tangent exists and is also compressed
// then it will be oct16 encoded along with tangent
if ((p_compress_format & ARRAY_COMPRESS_NORMAL) && (format & ARRAY_FORMAT_TANGENT) && (p_compress_format & ARRAY_COMPRESS_TANGENT)) {
elem_size = sizeof(uint8_t) * 2;
} else {
elem_size = sizeof(uint16_t) * 2;
}
} else {
if (p_compress_format & ARRAY_COMPRESS_NORMAL) {
elem_size = sizeof(uint32_t);
} else {
elem_size = sizeof(float) * 3;
}
}
offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
} break;
case RS::ARRAY_TANGENT: {
if (p_compress_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
if (p_compress_format & ARRAY_COMPRESS_TANGENT && (format & ARRAY_FORMAT_NORMAL) && (p_compress_format & ARRAY_COMPRESS_NORMAL)) {
elem_size = sizeof(uint8_t) * 2;
} else {
elem_size = sizeof(uint16_t) * 2;
}
} else {
if (p_compress_format & ARRAY_COMPRESS_TANGENT) {
elem_size = sizeof(uint32_t);
} else {
elem_size = sizeof(float) * 4;
}
}
offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
@ -1171,39 +941,6 @@ void RenderingServer::mesh_add_surface_from_arrays(RID p_mesh, PrimitiveType p_p
offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
} break;
case RS::ARRAY_WEIGHTS: {
if (p_compress_format & ARRAY_COMPRESS_WEIGHTS) {
elem_size = sizeof(uint16_t) * 4;
} else {
elem_size = sizeof(float) * 4;
}
offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
} break;
case RS::ARRAY_BONES: {
PoolVector<int> bones = p_arrays[RS::ARRAY_BONES];
int max_bone = 0;
{
int bc = bones.size();
PoolVector<int>::Read r = bones.read();
for (int j = 0; j < bc; j++) {
max_bone = MAX(r[j], max_bone);
}
}
if (max_bone > 255) {
p_compress_format |= ARRAY_FLAG_USE_16_BIT_BONES;
elem_size = sizeof(uint16_t) * 4;
} else {
p_compress_format &= ~ARRAY_FLAG_USE_16_BIT_BONES;
elem_size = sizeof(uint32_t);
}
offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
} break;
case RS::ARRAY_INDEX: {
if (index_array_len <= 0) {
@ -1320,41 +1057,24 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, PoolVector<uin
} break;
case RS::ARRAY_NORMAL: {
if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
// normal will always be oct32 (4 byte) encoded
// UNLESS tangent exists and is also compressed
// then it will be oct16 encoded along with tangent
if ((p_format & ARRAY_COMPRESS_NORMAL) && (p_format & ARRAY_FORMAT_TANGENT) && (p_format & ARRAY_COMPRESS_TANGENT)) {
elem_size = sizeof(uint8_t) * 2;
} else {
elem_size = sizeof(uint16_t) * 2;
}
} else {
if (p_format & ARRAY_COMPRESS_NORMAL) {
elem_size = sizeof(uint32_t);
} else {
elem_size = sizeof(float) * 3;
}
}
offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
} break;
case RS::ARRAY_TANGENT: {
if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
if (p_format & ARRAY_COMPRESS_TANGENT && (p_format & ARRAY_FORMAT_NORMAL) && (p_format & ARRAY_COMPRESS_NORMAL)) {
elem_size = sizeof(uint8_t) * 2;
} else {
elem_size = sizeof(uint16_t) * 2;
}
} else {
if (p_format & ARRAY_COMPRESS_TANGENT) {
elem_size = sizeof(uint32_t);
} else {
elem_size = sizeof(float) * 4;
}
}
offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
@ -1389,26 +1109,6 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, PoolVector<uin
offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
} break;
case RS::ARRAY_WEIGHTS: {
if (p_format & ARRAY_COMPRESS_WEIGHTS) {
elem_size = sizeof(uint16_t) * 4;
} else {
elem_size = sizeof(float) * 4;
}
offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
} break;
case RS::ARRAY_BONES: {
if (p_format & ARRAY_FLAG_USE_16_BIT_BONES) {
elem_size = sizeof(uint16_t) * 4;
} else {
elem_size = sizeof(uint32_t);
}
offsets[i] = attributes_base_offset + attributes_stride;
attributes_stride += elem_size;
} break;
case RS::ARRAY_INDEX: {
if (p_index_len <= 0) {
@ -1503,27 +1203,6 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, PoolVector<uin
PoolVector<Vector3> arr;
arr.resize(p_vertex_len);
if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
if (p_format & ARRAY_COMPRESS_NORMAL && (p_format & ARRAY_FORMAT_TANGENT) && (p_format & ARRAY_COMPRESS_TANGENT)) {
PoolVector<Vector3>::Write w = arr.write();
for (int j = 0; j < p_vertex_len; j++) {
const int8_t *n = (const int8_t *)&r[j * strides[i] + offsets[i]];
Vector2 enc(n[0] / 127.0f, n[1] / 127.0f);
w[j] = oct_to_norm(enc);
}
} else {
PoolVector<Vector3>::Write w = arr.write();
for (int j = 0; j < p_vertex_len; j++) {
const int16_t *n = (const int16_t *)&r[j * strides[i] + offsets[i]];
Vector2 enc(n[0] / 32767.0f, n[1] / 32767.0f);
w[j] = oct_to_norm(enc);
}
}
} else {
if (p_format & ARRAY_COMPRESS_NORMAL) {
PoolVector<Vector3>::Write w = arr.write();
const float multiplier = 1.f / 127.f;
@ -1540,7 +1219,6 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, PoolVector<uin
w[j] = Vector3(v[0], v[1], v[2]);
}
}
}
ret[i] = arr;
@ -1550,33 +1228,6 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, PoolVector<uin
PoolVector<float> arr;
arr.resize(p_vertex_len * 4);
if (p_format & ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
if (p_format & ARRAY_COMPRESS_TANGENT) {
PoolVector<float>::Write w = arr.write();
for (int j = 0; j < p_vertex_len; j++) {
const int8_t *t = (const int8_t *)&r[j * strides[i] + offsets[i]];
Vector2 enc(t[0] / 127.0f, t[1] / 127.0f);
Vector3 dec = oct_to_tangent(enc, &w[j * 4 + 3]);
w[j * 4 + 0] = dec.x;
w[j * 4 + 1] = dec.y;
w[j * 4 + 2] = dec.z;
}
} else {
PoolVector<float>::Write w = arr.write();
for (int j = 0; j < p_vertex_len; j++) {
const int16_t *t = (const int16_t *)&r[j * strides[i] + offsets[i]];
Vector2 enc(t[0] / 32767.0f, t[1] / 32767.0f);
Vector3 dec = oct_to_tangent(enc, &w[j * 4 + 3]);
w[j * 4 + 0] = dec.x;
w[j * 4 + 1] = dec.y;
w[j * 4 + 2] = dec.z;
}
}
} else {
if (p_format & ARRAY_COMPRESS_TANGENT) {
PoolVector<float>::Write w = arr.write();
@ -1596,7 +1247,6 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, PoolVector<uin
}
}
}
}
ret[i] = arr;
@ -1668,58 +1318,6 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, PoolVector<uin
ret[i] = arr;
} break;
case RS::ARRAY_WEIGHTS: {
PoolVector<float> arr;
arr.resize(p_vertex_len * 4);
if (p_format & ARRAY_COMPRESS_WEIGHTS) {
PoolVector<float>::Write w = arr.write();
for (int j = 0; j < p_vertex_len; j++) {
const uint16_t *v = (const uint16_t *)&r[j * strides[i] + offsets[i]];
for (int k = 0; k < 4; k++) {
w[j * 4 + k] = float(v[k] / 65535.0);
}
}
} else {
PoolVector<float>::Write w = arr.write();
for (int j = 0; j < p_vertex_len; j++) {
const float *v = (const float *)&r[j * strides[i] + offsets[i]];
for (int k = 0; k < 4; k++) {
w[j * 4 + k] = v[k];
}
}
}
ret[i] = arr;
} break;
case RS::ARRAY_BONES: {
PoolVector<int> arr;
arr.resize(p_vertex_len * 4);
if (p_format & ARRAY_FLAG_USE_16_BIT_BONES) {
PoolVector<int>::Write w = arr.write();
for (int j = 0; j < p_vertex_len; j++) {
const uint16_t *v = (const uint16_t *)&r[j * strides[i] + offsets[i]];
for (int k = 0; k < 4; k++) {
w[j * 4 + k] = v[k];
}
}
} else {
PoolVector<int>::Write w = arr.write();
for (int j = 0; j < p_vertex_len; j++) {
const uint8_t *v = (const uint8_t *)&r[j * strides[i] + offsets[i]];
for (int k = 0; k < 4; k++) {
w[j * 4 + k] = v[k];
}
}
}
ret[i] = arr;
} break;
case RS::ARRAY_INDEX: {
/* determine whether using 16 or 32 bits indices */
@ -2030,8 +1628,6 @@ void RenderingServer::_bind_methods() {
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);
BIND_ENUM_CONSTANT(ARRAY_MAX);
@ -2041,8 +1637,6 @@ void RenderingServer::_bind_methods() {
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);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_VERTEX);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_NORMAL);
@ -2050,12 +1644,8 @@ void RenderingServer::_bind_methods() {
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_COLOR);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TEX_UV);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TEX_UV2);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_BONES);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_WEIGHTS);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_INDEX);
BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_2D_VERTICES);
BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_16_BIT_BONES);
BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION);
BIND_ENUM_CONSTANT(ARRAY_COMPRESS_DEFAULT);
BIND_ENUM_CONSTANT(PRIMITIVE_POINTS);

View File

@ -226,17 +226,14 @@ public:
/* MESH API */
enum ArrayType {
ARRAY_VERTEX = 0,
ARRAY_NORMAL = 1,
ARRAY_TANGENT = 2,
ARRAY_COLOR = 3,
ARRAY_TEX_UV = 4,
ARRAY_TEX_UV2 = 5,
ARRAY_BONES = 6,
ARRAY_WEIGHTS = 7,
ARRAY_INDEX = 8,
ARRAY_MAX = 9
ARRAY_INDEX = 6,
ARRAY_MAX = 7
};
enum ArrayFormat {
@ -247,8 +244,6 @@ public:
ARRAY_FORMAT_COLOR = 1 << ARRAY_COLOR,
ARRAY_FORMAT_TEX_UV = 1 << ARRAY_TEX_UV,
ARRAY_FORMAT_TEX_UV2 = 1 << ARRAY_TEX_UV2,
ARRAY_FORMAT_BONES = 1 << ARRAY_BONES,
ARRAY_FORMAT_WEIGHTS = 1 << ARRAY_WEIGHTS,
ARRAY_FORMAT_INDEX = 1 << ARRAY_INDEX,
ARRAY_COMPRESS_BASE = (ARRAY_INDEX + 1),
@ -258,16 +253,12 @@ public:
ARRAY_COMPRESS_COLOR = 1 << (ARRAY_COLOR + ARRAY_COMPRESS_BASE),
ARRAY_COMPRESS_TEX_UV = 1 << (ARRAY_TEX_UV + ARRAY_COMPRESS_BASE),
ARRAY_COMPRESS_TEX_UV2 = 1 << (ARRAY_TEX_UV2 + ARRAY_COMPRESS_BASE),
ARRAY_COMPRESS_BONES = 1 << (ARRAY_BONES + ARRAY_COMPRESS_BASE),
ARRAY_COMPRESS_WEIGHTS = 1 << (ARRAY_WEIGHTS + ARRAY_COMPRESS_BASE),
ARRAY_COMPRESS_INDEX = 1 << (ARRAY_INDEX + ARRAY_COMPRESS_BASE),
ARRAY_FLAG_USE_2D_VERTICES = ARRAY_COMPRESS_INDEX << 1,
ARRAY_FLAG_USE_16_BIT_BONES = ARRAY_COMPRESS_INDEX << 2,
ARRAY_FLAG_USE_DYNAMIC_UPDATE = ARRAY_COMPRESS_INDEX << 3,
ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION = ARRAY_COMPRESS_INDEX << 4,
ARRAY_FLAG_USE_DYNAMIC_UPDATE = ARRAY_COMPRESS_INDEX << 2,
ARRAY_COMPRESS_DEFAULT = ARRAY_COMPRESS_NORMAL | ARRAY_COMPRESS_TANGENT | ARRAY_COMPRESS_COLOR | ARRAY_COMPRESS_TEX_UV | ARRAY_COMPRESS_TEX_UV2 | ARRAY_COMPRESS_WEIGHTS | ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION
ARRAY_COMPRESS_DEFAULT = ARRAY_COMPRESS_NORMAL | ARRAY_COMPRESS_TANGENT | ARRAY_COMPRESS_COLOR | ARRAY_COMPRESS_TEX_UV | ARRAY_COMPRESS_TEX_UV2
};