2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-12-27 21:50:31 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "bvh/build.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "bvh/bvh.h"
|
|
|
|
|
|
|
|
|
|
#include "device/device.h"
|
2020-02-02 12:04:19 +01:00
|
|
|
|
2025-03-25 23:44:23 +01:00
|
|
|
#include "scene/attribute.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/mesh.h"
|
|
|
|
|
#include "scene/object.h"
|
|
|
|
|
#include "scene/scene.h"
|
|
|
|
|
#include "scene/shader_graph.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "subd/split.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/log.h"
|
|
|
|
|
#include "util/set.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2025-03-25 23:44:23 +01:00
|
|
|
#include "mikktspace.hh"
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2025-03-25 23:44:23 +01:00
|
|
|
/* Tangent Space */
|
|
|
|
|
|
|
|
|
|
struct MikkMeshWrapper {
|
|
|
|
|
MikkMeshWrapper(const Mesh *mesh,
|
|
|
|
|
const float3 *normal,
|
|
|
|
|
const float2 *uv,
|
|
|
|
|
float3 *tangent,
|
|
|
|
|
float *tangent_sign)
|
|
|
|
|
: mesh(mesh), normal(normal), uv(uv), tangent(tangent), tangent_sign(tangent_sign)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GetNumFaces()
|
|
|
|
|
{
|
|
|
|
|
return mesh->num_triangles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GetNumVerticesOfFace(const int /*face_num*/)
|
|
|
|
|
{
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CornerIndex(const int face_num, const int vert_num)
|
|
|
|
|
{
|
|
|
|
|
return face_num * 3 + vert_num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VertexIndex(const int face_num, const int vert_num)
|
|
|
|
|
{
|
|
|
|
|
const int corner = CornerIndex(face_num, vert_num);
|
|
|
|
|
return mesh->get_triangles()[corner];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mikk::float3 GetPosition(const int face_num, const int vert_num)
|
|
|
|
|
{
|
|
|
|
|
const float3 vP = mesh->get_verts()[VertexIndex(face_num, vert_num)];
|
|
|
|
|
return mikk::float3(vP.x, vP.y, vP.z);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mikk::float3 GetTexCoord(const int face_num, const int vert_num)
|
|
|
|
|
{
|
|
|
|
|
/* TODO: Check whether introducing a template boolean in order to
|
|
|
|
|
* turn this into a constexpr is worth it. */
|
|
|
|
|
if (uv != nullptr) {
|
|
|
|
|
const int corner_index = CornerIndex(face_num, vert_num);
|
|
|
|
|
const float2 tfuv = uv[corner_index];
|
|
|
|
|
return mikk::float3(tfuv.x, tfuv.y, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
/* revert to vertex position */
|
|
|
|
|
const float3 vP = mesh->get_verts()[VertexIndex(face_num, vert_num)];
|
|
|
|
|
const float2 uv = map_to_sphere(vP);
|
|
|
|
|
return mikk::float3(uv.x, uv.y, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mikk::float3 GetNormal(const int face_num, const int vert_num)
|
|
|
|
|
{
|
|
|
|
|
float3 vN;
|
|
|
|
|
if (mesh->get_smooth()[face_num]) {
|
|
|
|
|
const int vertex_index = VertexIndex(face_num, vert_num);
|
|
|
|
|
vN = normal[vertex_index];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const Mesh::Triangle tri = mesh->get_triangle(face_num);
|
|
|
|
|
vN = tri.compute_normal(mesh->get_verts().data());
|
|
|
|
|
}
|
|
|
|
|
return mikk::float3(vN.x, vN.y, vN.z);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetTangentSpace(const int face_num, const int vert_num, mikk::float3 T, bool orientation)
|
|
|
|
|
{
|
|
|
|
|
const int corner_index = CornerIndex(face_num, vert_num);
|
|
|
|
|
tangent[corner_index] = make_float3(T.x, T.y, T.z);
|
|
|
|
|
if (tangent_sign != nullptr) {
|
|
|
|
|
tangent_sign[corner_index] = orientation ? 1.0f : -1.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Mesh *mesh;
|
|
|
|
|
|
|
|
|
|
const float3 *normal;
|
|
|
|
|
const float2 *uv;
|
|
|
|
|
|
|
|
|
|
float3 *tangent;
|
|
|
|
|
float *tangent_sign;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void mikk_compute_tangents(Attribute *attr_uv, Mesh *mesh, const bool need_sign)
|
|
|
|
|
{
|
|
|
|
|
/* Create tangent attributes. */
|
|
|
|
|
AttributeSet &attributes = mesh->attributes;
|
|
|
|
|
|
|
|
|
|
Attribute *attr_vN = attributes.find(ATTR_STD_VERTEX_NORMAL);
|
|
|
|
|
if (attr_vN == nullptr) {
|
|
|
|
|
/* no normals */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const float3 *normal = attr_vN->data_float3();
|
|
|
|
|
const float2 *uv = (attr_uv) ? attr_uv->data_float2() : nullptr;
|
|
|
|
|
|
|
|
|
|
const ustring name = ustring((attr_uv) ? attr_uv->name.string() + ".tangent" :
|
|
|
|
|
Attribute::standard_name(ATTR_STD_UV_TANGENT));
|
|
|
|
|
Attribute *attr;
|
|
|
|
|
if (attr_uv == nullptr || attr_uv->std == ATTR_STD_UV) {
|
|
|
|
|
attr = attributes.add(ATTR_STD_UV_TANGENT, name);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
attr = attributes.add(name, TypeVector, ATTR_ELEMENT_CORNER);
|
|
|
|
|
}
|
|
|
|
|
float3 *tangent = attr->data_float3();
|
|
|
|
|
/* Create bitangent sign attribute. */
|
|
|
|
|
float *tangent_sign = nullptr;
|
|
|
|
|
if (need_sign) {
|
|
|
|
|
const ustring name_sign = ustring((attr_uv) ?
|
|
|
|
|
attr_uv->name.string() + ".tangent_sign" :
|
|
|
|
|
Attribute::standard_name(ATTR_STD_UV_TANGENT_SIGN));
|
|
|
|
|
Attribute *attr_sign;
|
|
|
|
|
if (attr_uv == nullptr || attr_uv->std == ATTR_STD_UV) {
|
|
|
|
|
attr_sign = attributes.add(ATTR_STD_UV_TANGENT_SIGN, name_sign);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
attr_sign = attributes.add(name_sign, TypeFloat, ATTR_ELEMENT_CORNER);
|
|
|
|
|
}
|
|
|
|
|
tangent_sign = attr_sign->data_float();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MikkMeshWrapper userdata(mesh, normal, uv, tangent, tangent_sign);
|
|
|
|
|
/* Compute tangents. */
|
|
|
|
|
mikk::Mikktspace(userdata).genTangSpace();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* Triangle */
|
|
|
|
|
|
|
|
|
|
void Mesh::Triangle::bounds_grow(const float3 *verts, BoundBox &bounds) const
|
|
|
|
|
{
|
|
|
|
|
bounds.grow(verts[v[0]]);
|
|
|
|
|
bounds.grow(verts[v[1]]);
|
|
|
|
|
bounds.grow(verts[v[2]]);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-16 19:56:40 +01:00
|
|
|
void Mesh::Triangle::motion_verts(const float3 *verts,
|
|
|
|
|
const float3 *vert_steps,
|
2025-01-01 18:15:54 +01:00
|
|
|
const size_t num_verts,
|
|
|
|
|
const size_t num_steps,
|
|
|
|
|
const float time,
|
2017-01-16 19:56:40 +01:00
|
|
|
float3 r_verts[3]) const
|
|
|
|
|
{
|
|
|
|
|
/* Figure out which steps we need to fetch and their interpolation factor. */
|
|
|
|
|
const size_t max_step = num_steps - 1;
|
2022-02-10 10:37:00 +01:00
|
|
|
const size_t step = min((size_t)(time * max_step), max_step - 1);
|
2017-01-16 19:56:40 +01:00
|
|
|
const float t = time * max_step - step;
|
|
|
|
|
/* Fetch vertex coordinates. */
|
|
|
|
|
float3 curr_verts[3];
|
|
|
|
|
float3 next_verts[3];
|
2017-01-16 20:08:19 +01:00
|
|
|
verts_for_step(verts, vert_steps, num_verts, num_steps, step, curr_verts);
|
|
|
|
|
verts_for_step(verts, vert_steps, num_verts, num_steps, step + 1, next_verts);
|
2017-01-16 19:56:40 +01:00
|
|
|
/* Interpolate between steps. */
|
|
|
|
|
r_verts[0] = (1.0f - t) * curr_verts[0] + t * next_verts[0];
|
|
|
|
|
r_verts[1] = (1.0f - t) * curr_verts[1] + t * next_verts[1];
|
|
|
|
|
r_verts[2] = (1.0f - t) * curr_verts[2] + t * next_verts[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Mesh::Triangle::verts_for_step(const float3 *verts,
|
|
|
|
|
const float3 *vert_steps,
|
2025-01-01 18:15:54 +01:00
|
|
|
const size_t num_verts,
|
|
|
|
|
const size_t num_steps,
|
2017-01-16 19:56:40 +01:00
|
|
|
size_t step,
|
|
|
|
|
float3 r_verts[3]) const
|
|
|
|
|
{
|
|
|
|
|
const size_t center_step = ((num_steps - 1) / 2);
|
|
|
|
|
if (step == center_step) {
|
|
|
|
|
/* Center step: regular vertex location. */
|
|
|
|
|
r_verts[0] = verts[v[0]];
|
|
|
|
|
r_verts[1] = verts[v[1]];
|
|
|
|
|
r_verts[2] = verts[v[2]];
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-03-10 11:32:48 +11:00
|
|
|
/* Center step not stored in the attribute array. */
|
2017-01-16 19:56:40 +01:00
|
|
|
if (step > center_step) {
|
|
|
|
|
step--;
|
|
|
|
|
}
|
2024-12-29 17:32:00 +01:00
|
|
|
const size_t offset = step * num_verts;
|
2017-01-16 19:56:40 +01:00
|
|
|
r_verts[0] = vert_steps[offset + v[0]];
|
|
|
|
|
r_verts[1] = vert_steps[offset + v[1]];
|
|
|
|
|
r_verts[2] = vert_steps[offset + v[2]];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 13:12:06 +05:00
|
|
|
float3 Mesh::Triangle::compute_normal(const float3 *verts) const
|
|
|
|
|
{
|
|
|
|
|
const float3 &v0 = verts[v[0]];
|
|
|
|
|
const float3 &v1 = verts[v[1]];
|
|
|
|
|
const float3 &v2 = verts[v[2]];
|
|
|
|
|
const float3 norm = cross(v1 - v0, v2 - v0);
|
|
|
|
|
const float normlen = len(norm);
|
|
|
|
|
if (normlen == 0.0f) {
|
|
|
|
|
return make_float3(1.0f, 0.0f, 0.0f);
|
|
|
|
|
}
|
|
|
|
|
return norm / normlen;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 12:19:53 +02:00
|
|
|
bool Mesh::Triangle::valid(const float3 *verts) const
|
|
|
|
|
{
|
2022-06-23 14:29:17 +02:00
|
|
|
return isfinite_safe(verts[v[0]]) && isfinite_safe(verts[v[1]]) && isfinite_safe(verts[v[2]]);
|
2017-10-18 12:19:53 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
/* SubdFace */
|
|
|
|
|
|
|
|
|
|
float3 Mesh::SubdFace::normal(const Mesh *mesh) const
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const float3 v0 = mesh->verts[mesh->subd_face_corners[start_corner + 0]];
|
|
|
|
|
const float3 v1 = mesh->verts[mesh->subd_face_corners[start_corner + 1]];
|
|
|
|
|
const float3 v2 = mesh->verts[mesh->subd_face_corners[start_corner + 2]];
|
2016-07-16 19:42:28 -04:00
|
|
|
|
|
|
|
|
return safe_normalize(cross(v1 - v0, v2 - v0));
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Mesh */
|
|
|
|
|
|
2016-05-07 21:44:17 +02:00
|
|
|
NODE_DEFINE(Mesh)
|
|
|
|
|
{
|
2021-03-15 16:11:12 +01:00
|
|
|
NodeType *type = NodeType::add("mesh", create, NodeType::NONE, Geometry::get_node_base_type());
|
2016-05-07 21:44:17 +02:00
|
|
|
|
|
|
|
|
SOCKET_INT_ARRAY(triangles, "Triangles", array<int>());
|
|
|
|
|
SOCKET_POINT_ARRAY(verts, "Vertices", array<float3>());
|
|
|
|
|
SOCKET_INT_ARRAY(shader, "Shader", array<int>());
|
|
|
|
|
SOCKET_BOOLEAN_ARRAY(smooth, "Smooth", array<bool>());
|
|
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
static NodeEnum subdivision_type_enum;
|
|
|
|
|
subdivision_type_enum.insert("none", SUBDIVISION_NONE);
|
|
|
|
|
subdivision_type_enum.insert("linear", SUBDIVISION_LINEAR);
|
|
|
|
|
subdivision_type_enum.insert("catmull_clark", SUBDIVISION_CATMULL_CLARK);
|
|
|
|
|
SOCKET_ENUM(subdivision_type, "Subdivision Type", subdivision_type_enum, SUBDIVISION_NONE);
|
|
|
|
|
|
2025-03-09 04:20:05 +01:00
|
|
|
static NodeEnum subdivision_boundary_interpolation_enum;
|
|
|
|
|
subdivision_boundary_interpolation_enum.insert("none", SUBDIVISION_BOUNDARY_NONE);
|
|
|
|
|
subdivision_boundary_interpolation_enum.insert("edge_only", SUBDIVISION_BOUNDARY_EDGE_ONLY);
|
|
|
|
|
subdivision_boundary_interpolation_enum.insert("edge_and_corner",
|
|
|
|
|
SUBDIVISION_BOUNDARY_EDGE_AND_CORNER);
|
|
|
|
|
SOCKET_ENUM(subdivision_boundary_interpolation,
|
|
|
|
|
"Subdivision Boundary Interpolation",
|
|
|
|
|
subdivision_boundary_interpolation_enum,
|
|
|
|
|
SUBDIVISION_BOUNDARY_EDGE_AND_CORNER);
|
|
|
|
|
|
|
|
|
|
static NodeEnum subdivision_fvar_interpolation_enum;
|
|
|
|
|
subdivision_fvar_interpolation_enum.insert("none", SUBDIVISION_FVAR_LINEAR_NONE);
|
|
|
|
|
subdivision_fvar_interpolation_enum.insert("corners_only", SUBDIVISION_FVAR_LINEAR_CORNERS_ONLY);
|
|
|
|
|
subdivision_fvar_interpolation_enum.insert("corners_plus1",
|
|
|
|
|
SUBDIVISION_FVAR_LINEAR_CORNERS_PLUS1);
|
|
|
|
|
subdivision_fvar_interpolation_enum.insert("corners_plus2",
|
|
|
|
|
SUBDIVISION_FVAR_LINEAR_CORNERS_PLUS2);
|
|
|
|
|
subdivision_fvar_interpolation_enum.insert("boundaries", SUBDIVISION_FVAR_LINEAR_BOUNDARIES);
|
|
|
|
|
subdivision_fvar_interpolation_enum.insert("all", SUBDIVISION_FVAR_LINEAR_ALL);
|
|
|
|
|
SOCKET_ENUM(subdivision_fvar_interpolation,
|
|
|
|
|
"Subdivision Face-Varying Interpolation",
|
|
|
|
|
subdivision_fvar_interpolation_enum,
|
|
|
|
|
SUBDIVISION_FVAR_LINEAR_BOUNDARIES);
|
|
|
|
|
|
Subdivision: add support for vertex creasing
This adds vertex creasing support for OpenSubDiv for modeling, rendering,
Alembic and USD I/O.
For modeling, vertex creasing follows the edge creasing implementation with an
operator accessible through the Vertex menu in Edit Mode, and some parameter in
the properties panel. The option in the Subsurf and Multires to use edge
creasing also affects vertex creasing.
The vertex crease data is stored as a CustomData layer, unlike edge creases
which for now are stored in `MEdge`, but will in the future also be moved to
a `CustomData` layer. See comments for details on the difference in behavior
for the `CD_CREASE` layer between egdes and vertices.
For Cycles this adds sockets on the Mesh node to hold data about which vertices
are creased (one socket for the indices, one for the weigths).
Viewport rendering of vertex creasing reuses the same color scheme as for edges
and creased vertices are drawn bigger than uncreased vertices.
For Alembic and USD, vertex crease support follows the edge crease
implementation, they are always read, but only exported if a `Subsurf` modifier
is present on the Mesh.
Reviewed By: brecht, fclem, sergey, sybren, campbellbarton
Differential Revision: https://developer.blender.org/D10145
2022-01-20 12:20:30 +01:00
|
|
|
SOCKET_INT_ARRAY(subd_vert_creases, "Subdivision Vertex Crease", array<int>());
|
|
|
|
|
SOCKET_FLOAT_ARRAY(
|
|
|
|
|
subd_vert_creases_weight, "Subdivision Vertex Crease Weights", array<float>());
|
2020-11-04 11:17:38 +01:00
|
|
|
SOCKET_INT_ARRAY(subd_creases_edge, "Subdivision Crease Edges", array<int>());
|
|
|
|
|
SOCKET_FLOAT_ARRAY(subd_creases_weight, "Subdivision Crease Weights", array<float>());
|
|
|
|
|
SOCKET_INT_ARRAY(subd_face_corners, "Subdivision Face Corners", array<int>());
|
|
|
|
|
SOCKET_INT_ARRAY(subd_start_corner, "Subdivision Face Start Corner", array<int>());
|
|
|
|
|
SOCKET_INT_ARRAY(subd_num_corners, "Subdivision Face Corner Count", array<int>());
|
|
|
|
|
SOCKET_INT_ARRAY(subd_shader, "Subdivision Face Shader", array<int>());
|
|
|
|
|
SOCKET_BOOLEAN_ARRAY(subd_smooth, "Subdivision Face Smooth", array<bool>());
|
|
|
|
|
SOCKET_INT_ARRAY(subd_ptex_offset, "Subdivision Face PTex Offset", array<int>());
|
|
|
|
|
|
|
|
|
|
/* Subdivisions parameters */
|
2022-03-23 16:07:43 +01:00
|
|
|
SOCKET_FLOAT(subd_dicing_rate, "Subdivision Dicing Rate", 1.0f)
|
|
|
|
|
SOCKET_INT(subd_max_level, "Max Subdivision Level", 1);
|
2020-11-04 11:17:38 +01:00
|
|
|
SOCKET_TRANSFORM(subd_objecttoworld, "Subdivision Object Transform", transform_identity());
|
|
|
|
|
|
2016-05-07 21:44:17 +02:00
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
bool Mesh::need_tesselation()
|
|
|
|
|
{
|
2025-03-09 04:20:05 +01:00
|
|
|
return (subdivision_type != SUBDIVISION_NONE) &&
|
|
|
|
|
(verts_is_modified() || subd_dicing_rate_is_modified() ||
|
|
|
|
|
subd_objecttoworld_is_modified() || subd_max_level_is_modified());
|
2020-11-04 11:17:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Mesh::Mesh(const NodeType *node_type, Type geom_type_)
|
|
|
|
|
: Geometry(node_type, geom_type_), subd_attributes(this, ATTR_PRIM_SUBD)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
|
vert_offset = 0;
|
2012-02-28 16:45:01 +00:00
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
face_offset = 0;
|
|
|
|
|
corner_offset = 0;
|
|
|
|
|
|
2025-03-09 03:07:29 +01:00
|
|
|
num_subd_added_verts = 0;
|
2020-11-04 11:17:38 +01:00
|
|
|
num_subd_faces = 0;
|
2016-07-16 19:42:28 -04:00
|
|
|
|
2016-07-16 19:56:45 -04:00
|
|
|
subdivision_type = SUBDIVISION_NONE;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
Mesh::Mesh() : Mesh(get_node_type(), Geometry::MESH) {}
|
2020-08-19 15:46:50 +02:00
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Mesh::resize_mesh(const int numverts, const int numtris)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
|
verts.resize(numverts);
|
2016-05-08 00:09:08 +02:00
|
|
|
triangles.resize(numtris * 3);
|
2011-04-27 11:58:34 +00:00
|
|
|
shader.resize(numtris);
|
|
|
|
|
smooth.resize(numtris);
|
2016-04-11 23:46:00 +02:00
|
|
|
|
2016-05-08 00:09:08 +02:00
|
|
|
attributes.resize();
|
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Mesh::reserve_mesh(const int numverts, const int numtris)
|
2016-05-08 00:09:08 +02:00
|
|
|
{
|
|
|
|
|
/* reserve space to add verts and triangles later */
|
|
|
|
|
verts.reserve(numverts);
|
|
|
|
|
triangles.reserve(numtris * 3);
|
|
|
|
|
shader.reserve(numtris);
|
|
|
|
|
smooth.reserve(numtris);
|
|
|
|
|
|
|
|
|
|
attributes.resize(true);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-09 03:07:29 +01:00
|
|
|
void Mesh::resize_subd_faces(const int numfaces, const int numcorners)
|
2016-07-16 19:42:28 -04:00
|
|
|
{
|
2020-11-04 11:17:38 +01:00
|
|
|
subd_start_corner.resize(numfaces);
|
|
|
|
|
subd_num_corners.resize(numfaces);
|
|
|
|
|
subd_shader.resize(numfaces);
|
|
|
|
|
subd_smooth.resize(numfaces);
|
|
|
|
|
subd_ptex_offset.resize(numfaces);
|
2016-07-16 19:42:28 -04:00
|
|
|
subd_face_corners.resize(numcorners);
|
2020-11-04 11:17:38 +01:00
|
|
|
num_subd_faces = numfaces;
|
2016-07-16 19:42:28 -04:00
|
|
|
|
|
|
|
|
subd_attributes.resize();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-09 03:07:29 +01:00
|
|
|
void Mesh::reserve_subd_faces(const int numfaces, const int numcorners)
|
2016-07-16 19:42:28 -04:00
|
|
|
{
|
2020-11-04 11:17:38 +01:00
|
|
|
subd_start_corner.reserve(numfaces);
|
|
|
|
|
subd_num_corners.reserve(numfaces);
|
|
|
|
|
subd_shader.reserve(numfaces);
|
|
|
|
|
subd_smooth.reserve(numfaces);
|
|
|
|
|
subd_ptex_offset.reserve(numfaces);
|
2016-07-16 19:42:28 -04:00
|
|
|
subd_face_corners.reserve(numcorners);
|
2020-11-04 11:17:38 +01:00
|
|
|
num_subd_faces = numfaces;
|
2016-07-16 19:42:28 -04:00
|
|
|
|
|
|
|
|
subd_attributes.resize(true);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Mesh::reserve_subd_creases(const size_t num_creases)
|
2020-11-04 11:17:38 +01:00
|
|
|
{
|
|
|
|
|
subd_creases_edge.reserve(num_creases * 2);
|
|
|
|
|
subd_creases_weight.reserve(num_creases);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-10 02:31:25 +01:00
|
|
|
void Mesh::clear_non_sockets()
|
|
|
|
|
{
|
|
|
|
|
Geometry::clear(true);
|
|
|
|
|
|
2025-03-09 03:07:29 +01:00
|
|
|
num_subd_added_verts = 0;
|
2020-12-10 02:31:25 +01:00
|
|
|
num_subd_faces = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-31 19:21:07 +03:00
|
|
|
void Mesh::clear(bool preserve_shaders, bool preserve_voxel_data)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-10-31 19:21:07 +03:00
|
|
|
Geometry::clear(preserve_shaders);
|
2020-02-02 12:04:19 +01:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* clear all verts and triangles */
|
|
|
|
|
verts.clear();
|
|
|
|
|
triangles.clear();
|
|
|
|
|
shader.clear();
|
|
|
|
|
smooth.clear();
|
|
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
subd_start_corner.clear();
|
|
|
|
|
subd_num_corners.clear();
|
|
|
|
|
subd_shader.clear();
|
|
|
|
|
subd_smooth.clear();
|
|
|
|
|
subd_ptex_offset.clear();
|
2016-07-16 19:42:28 -04:00
|
|
|
subd_face_corners.clear();
|
|
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
subd_creases_edge.clear();
|
|
|
|
|
subd_creases_weight.clear();
|
2016-07-16 22:57:06 -04:00
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
subd_attributes.clear();
|
2018-03-01 11:54:01 +01:00
|
|
|
attributes.clear(preserve_voxel_data);
|
|
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
subdivision_type = SubdivisionType::SUBDIVISION_NONE;
|
|
|
|
|
|
2020-12-10 02:31:25 +01:00
|
|
|
clear_non_sockets();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-31 19:21:07 +03:00
|
|
|
void Mesh::clear(bool preserve_shaders)
|
2020-02-02 12:04:19 +01:00
|
|
|
{
|
2020-10-31 19:21:07 +03:00
|
|
|
clear(preserve_shaders, false);
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Mesh::add_vertex(const float3 P)
|
2013-07-14 12:51:41 +00:00
|
|
|
{
|
2016-05-08 00:09:08 +02:00
|
|
|
verts.push_back_reserved(P);
|
2020-11-04 11:17:38 +01:00
|
|
|
tag_verts_modified();
|
2013-07-14 12:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Mesh::add_vertex_slow(const float3 P)
|
2016-05-31 15:32:31 +02:00
|
|
|
{
|
|
|
|
|
verts.push_back_slow(P);
|
2020-11-04 11:17:38 +01:00
|
|
|
tag_verts_modified();
|
2016-05-31 15:32:31 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Mesh::add_triangle(const int v0, const int v1, const int v2, const int shader_, bool smooth_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-05-08 00:09:08 +02:00
|
|
|
triangles.push_back_reserved(v0);
|
|
|
|
|
triangles.push_back_reserved(v1);
|
|
|
|
|
triangles.push_back_reserved(v2);
|
|
|
|
|
shader.push_back_reserved(shader_);
|
|
|
|
|
smooth.push_back_reserved(smooth_);
|
2016-07-16 19:42:28 -04:00
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
tag_triangles_modified();
|
|
|
|
|
tag_shader_modified();
|
|
|
|
|
tag_smooth_modified();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Mesh::add_subd_face(const int *corners,
|
|
|
|
|
const int num_corners,
|
|
|
|
|
const int shader_,
|
|
|
|
|
bool smooth_)
|
2016-07-16 19:42:28 -04:00
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const int start_corner = subd_face_corners.size();
|
2016-07-16 19:42:28 -04:00
|
|
|
|
|
|
|
|
for (int i = 0; i < num_corners; i++) {
|
|
|
|
|
subd_face_corners.push_back_reserved(corners[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ptex_offset = 0;
|
2020-11-04 11:17:38 +01:00
|
|
|
// cannot use get_num_subd_faces here as it holds the total number of subd_faces, but we do not
|
|
|
|
|
// have the total amount of data yet
|
|
|
|
|
if (subd_shader.size()) {
|
2024-12-29 17:32:00 +01:00
|
|
|
const SubdFace s = get_subd_face(subd_shader.size() - 1);
|
2016-07-16 19:42:28 -04:00
|
|
|
ptex_offset = s.ptex_offset + s.num_ptex_faces();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
subd_start_corner.push_back_reserved(start_corner);
|
|
|
|
|
subd_num_corners.push_back_reserved(num_corners);
|
|
|
|
|
subd_shader.push_back_reserved(shader_);
|
|
|
|
|
subd_smooth.push_back_reserved(smooth_);
|
|
|
|
|
subd_ptex_offset.push_back_reserved(ptex_offset);
|
|
|
|
|
|
|
|
|
|
tag_subd_face_corners_modified();
|
|
|
|
|
tag_subd_start_corner_modified();
|
|
|
|
|
tag_subd_num_corners_modified();
|
|
|
|
|
tag_subd_shader_modified();
|
|
|
|
|
tag_subd_smooth_modified();
|
|
|
|
|
tag_subd_ptex_offset_modified();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
Mesh::SubdFace Mesh::get_subd_face(const size_t index) const
|
2020-11-04 11:17:38 +01:00
|
|
|
{
|
|
|
|
|
Mesh::SubdFace s;
|
|
|
|
|
s.shader = subd_shader[index];
|
|
|
|
|
s.num_corners = subd_num_corners[index];
|
|
|
|
|
s.smooth = subd_smooth[index];
|
|
|
|
|
s.ptex_offset = subd_ptex_offset[index];
|
|
|
|
|
s.start_corner = subd_start_corner[index];
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Mesh::add_edge_crease(const int v0, const int v1, const float weight)
|
2020-11-04 11:17:38 +01:00
|
|
|
{
|
|
|
|
|
subd_creases_edge.push_back_slow(v0);
|
|
|
|
|
subd_creases_edge.push_back_slow(v1);
|
|
|
|
|
subd_creases_weight.push_back_slow(weight);
|
|
|
|
|
|
|
|
|
|
tag_subd_creases_edge_modified();
|
|
|
|
|
tag_subd_creases_edge_modified();
|
|
|
|
|
tag_subd_creases_weight_modified();
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
|
|
|
|
|
2025-01-01 18:15:54 +01:00
|
|
|
void Mesh::add_vertex_crease(const int v, const float weight)
|
Subdivision: add support for vertex creasing
This adds vertex creasing support for OpenSubDiv for modeling, rendering,
Alembic and USD I/O.
For modeling, vertex creasing follows the edge creasing implementation with an
operator accessible through the Vertex menu in Edit Mode, and some parameter in
the properties panel. The option in the Subsurf and Multires to use edge
creasing also affects vertex creasing.
The vertex crease data is stored as a CustomData layer, unlike edge creases
which for now are stored in `MEdge`, but will in the future also be moved to
a `CustomData` layer. See comments for details on the difference in behavior
for the `CD_CREASE` layer between egdes and vertices.
For Cycles this adds sockets on the Mesh node to hold data about which vertices
are creased (one socket for the indices, one for the weigths).
Viewport rendering of vertex creasing reuses the same color scheme as for edges
and creased vertices are drawn bigger than uncreased vertices.
For Alembic and USD, vertex crease support follows the edge crease
implementation, they are always read, but only exported if a `Subsurf` modifier
is present on the Mesh.
Reviewed By: brecht, fclem, sergey, sybren, campbellbarton
Differential Revision: https://developer.blender.org/D10145
2022-01-20 12:20:30 +01:00
|
|
|
{
|
|
|
|
|
subd_vert_creases.push_back_slow(v);
|
|
|
|
|
subd_vert_creases_weight.push_back_slow(weight);
|
|
|
|
|
|
|
|
|
|
tag_subd_vert_creases_modified();
|
|
|
|
|
tag_subd_vert_creases_weight_modified();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
void Mesh::copy_center_to_motion_step(const int motion_step)
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
{
|
2020-02-02 12:04:19 +01:00
|
|
|
Attribute *attr_mP = attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
if (attr_mP) {
|
|
|
|
|
Attribute *attr_mN = attributes.find(ATTR_STD_MOTION_VERTEX_NORMAL);
|
|
|
|
|
Attribute *attr_N = attributes.find(ATTR_STD_VERTEX_NORMAL);
|
2024-12-26 17:53:59 +01:00
|
|
|
float3 *P = verts.data();
|
2024-12-26 17:53:55 +01:00
|
|
|
float3 *N = (attr_N) ? attr_N->data_float3() : nullptr;
|
2024-12-29 17:32:00 +01:00
|
|
|
const size_t numverts = verts.size();
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
|
2024-12-27 21:50:31 +01:00
|
|
|
std::copy_n(P, numverts, attr_mP->data_float3() + motion_step * numverts);
|
2023-09-17 09:01:48 +10:00
|
|
|
if (attr_mN) {
|
2024-12-27 21:50:31 +01:00
|
|
|
std::copy_n(N, numverts, attr_mN->data_float3() + motion_step * numverts);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Mesh::get_uv_tiles(ustring map, unordered_set<int> &tiles)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
Attribute *attr;
|
|
|
|
|
Attribute *subd_attr;
|
2020-02-02 12:04:19 +01:00
|
|
|
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
if (map.empty()) {
|
2020-02-02 12:04:19 +01:00
|
|
|
attr = attributes.find(ATTR_STD_UV);
|
|
|
|
|
subd_attr = subd_attributes.find(ATTR_STD_UV);
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2020-02-02 12:04:19 +01:00
|
|
|
attr = attributes.find(map);
|
|
|
|
|
subd_attr = subd_attributes.find(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (attr) {
|
2020-02-03 21:40:58 +01:00
|
|
|
attr->get_uv_tiles(this, ATTR_PRIM_GEOMETRY, tiles);
|
|
|
|
|
}
|
|
|
|
|
if (subd_attr) {
|
2020-02-02 12:04:19 +01:00
|
|
|
subd_attr->get_uv_tiles(this, ATTR_PRIM_SUBD, tiles);
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void Mesh::compute_bounds()
|
|
|
|
|
{
|
Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
and the initial bounding/splitting is still single threaded, but recursive
splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
code from the Embree raytracer from Intel.
http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
2012-04-28 08:53:59 +00:00
|
|
|
BoundBox bnds = BoundBox::empty;
|
2024-12-29 17:32:00 +01:00
|
|
|
const size_t verts_size = verts.size();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
if (verts_size > 0) {
|
2023-09-17 09:01:48 +10:00
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
2013-04-09 20:48:53 +00:00
|
|
|
bnds.grow(verts[i]);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
Attribute *attr = attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
|
2015-03-28 00:15:15 +05:00
|
|
|
if (use_motion_blur && attr) {
|
2024-12-29 17:32:00 +01:00
|
|
|
const size_t steps_size = verts.size() * (motion_steps - 1);
|
2014-03-29 13:03:46 +01:00
|
|
|
float3 *vert_steps = attr->data_float3();
|
2017-01-16 18:59:22 +01:00
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
for (size_t i = 0; i < steps_size; i++) {
|
2014-03-29 13:03:46 +01:00
|
|
|
bnds.grow(vert_steps[i]);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-09 20:48:53 +00:00
|
|
|
if (!bnds.valid()) {
|
|
|
|
|
bnds = BoundBox::empty;
|
|
|
|
|
|
|
|
|
|
/* skip nan or inf coordinates */
|
2023-09-17 09:01:48 +10:00
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
2013-04-09 20:48:53 +00:00
|
|
|
bnds.grow_safe(verts[i]);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2013-04-09 20:48:53 +00:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (use_motion_blur && attr) {
|
2024-12-29 17:32:00 +01:00
|
|
|
const size_t steps_size = verts.size() * (motion_steps - 1);
|
2014-03-29 13:03:46 +01:00
|
|
|
float3 *vert_steps = attr->data_float3();
|
2017-01-16 18:59:22 +01:00
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
for (size_t i = 0; i < steps_size; i++) {
|
2014-03-29 13:03:46 +01:00
|
|
|
bnds.grow_safe(vert_steps[i]);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
}
|
2013-04-09 20:48:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bnds.valid()) {
|
|
|
|
|
/* empty mesh */
|
2021-02-17 01:47:18 +01:00
|
|
|
bnds.grow(zero_float3());
|
2013-04-09 20:48:53 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
bounds = bnds;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
void Mesh::apply_transform(const Transform &tfm, const bool apply_to_motion)
|
|
|
|
|
{
|
|
|
|
|
transform_normal = transform_transposed_inverse(tfm);
|
|
|
|
|
|
|
|
|
|
/* apply to mesh vertices */
|
2025-03-26 18:51:10 +01:00
|
|
|
const size_t num_verts = verts.size();
|
|
|
|
|
for (size_t i = 0; i < num_verts; i++) {
|
2020-02-02 12:04:19 +01:00
|
|
|
verts[i] = transform_point(&tfm, verts[i]);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2020-02-02 12:04:19 +01:00
|
|
|
|
2021-10-08 13:45:34 +02:00
|
|
|
tag_verts_modified();
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
if (apply_to_motion) {
|
|
|
|
|
Attribute *attr = attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
|
|
|
|
|
|
|
|
|
|
if (attr) {
|
2024-12-29 17:32:00 +01:00
|
|
|
const size_t steps_size = verts.size() * (motion_steps - 1);
|
2020-02-02 12:04:19 +01:00
|
|
|
float3 *vert_steps = attr->data_float3();
|
|
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
for (size_t i = 0; i < steps_size; i++) {
|
2020-02-02 12:04:19 +01:00
|
|
|
vert_steps[i] = transform_point(&tfm, vert_steps[i]);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2025-05-19 12:10:18 +02:00
|
|
|
|
|
|
|
|
Attribute *attr_N = attributes.find(ATTR_STD_MOTION_VERTEX_NORMAL);
|
|
|
|
|
|
|
|
|
|
if (attr_N) {
|
|
|
|
|
const Transform ntfm = transform_normal;
|
|
|
|
|
const size_t steps_size = verts.size() * (motion_steps - 1);
|
|
|
|
|
float3 *normal_steps = attr_N->data_float3();
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < steps_size; i++) {
|
|
|
|
|
normal_steps[i] = normalize(transform_direction(&ntfm, normal_steps[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void Mesh::add_vertex_normals()
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const bool flip = transform_negative_scaled;
|
|
|
|
|
const size_t verts_size = verts.size();
|
|
|
|
|
const size_t triangles_size = num_triangles();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* static vertex normals */
|
2016-08-23 13:57:45 -04:00
|
|
|
if (!attributes.find(ATTR_STD_VERTEX_NORMAL) && triangles_size) {
|
2014-03-29 13:03:46 +01:00
|
|
|
/* get attributes */
|
|
|
|
|
Attribute *attr_vN = attributes.add(ATTR_STD_VERTEX_NORMAL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-12 21:20:24 +01:00
|
|
|
float3 *verts_ptr = verts.data();
|
2014-03-29 13:03:46 +01:00
|
|
|
float3 *vN = attr_vN->data_float3();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* compute vertex normals */
|
2024-12-27 21:50:31 +01:00
|
|
|
std::fill_n(vN, verts.size(), zero_float3());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-25 10:45:48 -04:00
|
|
|
for (size_t i = 0; i < triangles_size; i++) {
|
2024-12-12 21:20:24 +01:00
|
|
|
const float3 fN = get_triangle(i).compute_normal(verts_ptr);
|
2016-08-25 10:45:48 -04:00
|
|
|
for (size_t j = 0; j < 3; j++) {
|
2024-12-12 21:20:24 +01:00
|
|
|
vN[get_triangle(i).v[j]] += fN;
|
2016-08-25 10:45:48 -04:00
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-02-27 10:39:19 +01:00
|
|
|
if (flip) {
|
|
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
|
|
|
|
vN[i] = -normalize(vN[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
|
|
|
|
vN[i] = normalize(vN[i]);
|
2016-08-25 10:45:48 -04:00
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
}
|
2011-10-03 15:31:45 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* motion vertex normals */
|
|
|
|
|
Attribute *attr_mP = attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
|
|
|
|
|
Attribute *attr_mN = attributes.find(ATTR_STD_MOTION_VERTEX_NORMAL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-23 13:57:45 -04:00
|
|
|
if (has_motion_blur() && attr_mP && !attr_mN && triangles_size) {
|
2014-03-29 13:03:46 +01:00
|
|
|
/* create attribute */
|
|
|
|
|
attr_mN = attributes.add(ATTR_STD_MOTION_VERTEX_NORMAL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
for (int step = 0; step < motion_steps - 1; step++) {
|
|
|
|
|
float3 *mP = attr_mP->data_float3() + step * verts.size();
|
|
|
|
|
float3 *mN = attr_mN->data_float3() + step * verts.size();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* compute */
|
2024-12-27 21:50:31 +01:00
|
|
|
std::fill_n(mN, verts.size(), zero_float3());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-25 10:45:48 -04:00
|
|
|
for (size_t i = 0; i < triangles_size; i++) {
|
2024-12-29 17:32:00 +01:00
|
|
|
const Triangle tri = get_triangle(i);
|
|
|
|
|
const float3 fN = tri.compute_normal(mP);
|
2016-08-25 10:45:48 -04:00
|
|
|
for (size_t j = 0; j < 3; j++) {
|
2023-02-27 10:39:19 +01:00
|
|
|
mN[tri.v[j]] += fN;
|
2014-03-29 13:03:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-02-27 10:39:19 +01:00
|
|
|
if (flip) {
|
|
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
|
|
|
|
mN[i] = -normalize(mN[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
|
|
|
|
mN[i] = normalize(mN[i]);
|
2016-08-25 10:45:48 -04:00
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
2011-11-12 14:29:52 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-23 13:57:45 -04:00
|
|
|
/* subd vertex normals */
|
2020-11-04 11:17:38 +01:00
|
|
|
if (!subd_attributes.find(ATTR_STD_VERTEX_NORMAL) && get_num_subd_faces()) {
|
2016-08-23 13:57:45 -04:00
|
|
|
/* get attributes */
|
|
|
|
|
Attribute *attr_vN = subd_attributes.add(ATTR_STD_VERTEX_NORMAL);
|
|
|
|
|
float3 *vN = attr_vN->data_float3();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-23 13:57:45 -04:00
|
|
|
/* compute vertex normals */
|
2024-12-27 21:50:31 +01:00
|
|
|
std::fill_n(vN, verts.size(), zero_float3());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
for (size_t i = 0; i < get_num_subd_faces(); i++) {
|
2024-12-29 17:32:00 +01:00
|
|
|
const SubdFace face = get_subd_face(i);
|
|
|
|
|
const float3 fN = face.normal(this);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-23 13:57:45 -04:00
|
|
|
for (size_t j = 0; j < face.num_corners; j++) {
|
2024-12-29 17:32:00 +01:00
|
|
|
const size_t corner = subd_face_corners[face.start_corner + j];
|
2016-08-30 12:22:50 -04:00
|
|
|
vN[corner] += fN;
|
2016-08-23 13:57:45 -04:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-02-27 10:39:19 +01:00
|
|
|
if (flip) {
|
|
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
|
|
|
|
vN[i] = -normalize(vN[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
|
|
|
|
vN[i] = normalize(vN[i]);
|
2016-08-23 13:57:45 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-13 12:27:17 -04:00
|
|
|
void Mesh::add_undisplaced()
|
|
|
|
|
{
|
|
|
|
|
AttributeSet &attrs = (subdivision_type == SUBDIVISION_NONE) ? attributes : subd_attributes;
|
|
|
|
|
|
|
|
|
|
/* don't compute if already there */
|
|
|
|
|
if (attrs.find(ATTR_STD_POSITION_UNDISPLACED)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get attribute */
|
|
|
|
|
Attribute *attr = attrs.add(ATTR_STD_POSITION_UNDISPLACED);
|
|
|
|
|
|
|
|
|
|
float3 *data = attr->data_float3();
|
|
|
|
|
|
|
|
|
|
/* copy verts */
|
2024-12-27 21:50:31 +01:00
|
|
|
size_t size = attr->buffer_size(this, ATTR_PRIM_GEOMETRY) / sizeof(float3);
|
2016-09-22 17:34:14 -04:00
|
|
|
|
2016-08-13 12:27:17 -04:00
|
|
|
if (size) {
|
2024-12-27 21:50:31 +01:00
|
|
|
std::copy_n(verts.data(), size, data);
|
2016-08-13 12:27:17 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-25 23:44:23 +01:00
|
|
|
void Mesh::update_generated(Scene *scene)
|
|
|
|
|
{
|
|
|
|
|
if (!num_triangles()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AttributeSet &attrs = num_subd_faces ? subd_attributes : attributes;
|
|
|
|
|
|
|
|
|
|
/* apply generated attributes if needed or missing */
|
|
|
|
|
if (need_attribute(scene, ATTR_STD_GENERATED) && !attrs.find(ATTR_STD_GENERATED)) {
|
|
|
|
|
const size_t verts_size = verts.size();
|
|
|
|
|
Attribute *attr_generated = attrs.add(ATTR_STD_GENERATED);
|
|
|
|
|
float3 *generated = attr_generated->data_float3();
|
|
|
|
|
for (size_t i = 0; i < verts_size; ++i) {
|
|
|
|
|
generated[i] = verts[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Mesh::update_tangents(Scene *scene)
|
|
|
|
|
{
|
|
|
|
|
if (!num_triangles()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(attributes.find(ATTR_STD_VERTEX_NORMAL));
|
|
|
|
|
|
|
|
|
|
ccl::set<ustring> uv_maps;
|
|
|
|
|
Attribute *attr_std_uv = attributes.find(ATTR_STD_UV);
|
|
|
|
|
|
|
|
|
|
/* standard UVs */
|
|
|
|
|
if (need_attribute(scene, ATTR_STD_UV_TANGENT) && !attributes.find(ATTR_STD_UV_TANGENT)) {
|
|
|
|
|
mikk_compute_tangents(attr_std_uv, this, true); /* sign */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* now generate for any other UVs requested */
|
|
|
|
|
for (Attribute &attr : attributes.attributes) {
|
|
|
|
|
if (!(attr.type == TypeFloat2 && attr.element == ATTR_ELEMENT_CORNER)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ustring tangent_name = ustring(attr.name.string() + ".tangent");
|
|
|
|
|
|
|
|
|
|
if (need_attribute(scene, tangent_name) && !attributes.find(tangent_name)) {
|
|
|
|
|
mikk_compute_tangents(&attr, this, true); /* sign */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-10 06:10:14 +01:00
|
|
|
void Mesh::pack_shaders(Scene *scene, uint *tri_shader)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2014-09-24 13:34:28 +02:00
|
|
|
uint shader_id = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
uint last_shader = -1;
|
|
|
|
|
bool last_smooth = false;
|
|
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const size_t triangles_size = num_triangles();
|
2022-04-11 14:22:13 +02:00
|
|
|
const int *shader_ptr = shader.data();
|
|
|
|
|
const bool *smooth_ptr = smooth.data();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
for (size_t i = 0; i < triangles_size; i++) {
|
2022-04-11 14:22:13 +02:00
|
|
|
const int new_shader = shader_ptr ? shader_ptr[i] : INT_MAX;
|
|
|
|
|
const bool new_smooth = smooth_ptr ? smooth_ptr[i] : false;
|
|
|
|
|
|
|
|
|
|
if (new_shader != last_shader || last_smooth != new_smooth) {
|
|
|
|
|
last_shader = new_shader;
|
|
|
|
|
last_smooth = new_smooth;
|
2020-11-04 11:17:38 +01:00
|
|
|
Shader *shader = (last_shader < used_shaders.size()) ?
|
|
|
|
|
static_cast<Shader *>(used_shaders[last_shader]) :
|
|
|
|
|
scene->default_surface;
|
2016-08-16 19:42:08 -04:00
|
|
|
shader_id = scene->shader_manager->get_shader_id(shader, last_smooth);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-24 13:34:28 +02:00
|
|
|
tri_shader[i] = shader_id;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2018-03-10 06:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-16 14:03:59 +01:00
|
|
|
void Mesh::pack_normals(packed_float3 *vnormal)
|
2018-03-10 06:10:14 +01:00
|
|
|
{
|
|
|
|
|
Attribute *attr_vN = attributes.find(ATTR_STD_VERTEX_NORMAL);
|
2024-12-26 17:53:55 +01:00
|
|
|
if (attr_vN == nullptr) {
|
2018-03-10 06:10:14 +01:00
|
|
|
/* Happens on objects with just hair. */
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const bool do_transform = transform_applied;
|
|
|
|
|
const Transform ntfm = transform_normal;
|
2018-03-10 06:10:14 +01:00
|
|
|
|
|
|
|
|
float3 *vN = attr_vN->data_float3();
|
2024-12-29 17:32:00 +01:00
|
|
|
const size_t verts_size = verts.size();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2023-02-27 10:39:19 +01:00
|
|
|
if (do_transform) {
|
|
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
|
|
|
|
vnormal[i] = safe_normalize(transform_direction(&ntfm, vN[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
|
|
|
|
vnormal[i] = vN[i];
|
|
|
|
|
}
|
2013-01-15 16:35:05 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2025-03-09 03:07:29 +01:00
|
|
|
void Mesh::pack_verts(packed_float3 *tri_verts, packed_uint3 *tri_vindex)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const size_t verts_size = verts.size();
|
|
|
|
|
const size_t triangles_size = num_triangles();
|
2023-02-27 10:39:19 +01:00
|
|
|
const int *p_tris = triangles.data();
|
|
|
|
|
int off = 0;
|
2025-03-09 03:07:29 +01:00
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
|
|
|
|
tri_verts[i] = verts[i];
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
2025-03-09 03:07:29 +01:00
|
|
|
for (size_t i = 0; i < triangles_size; i++) {
|
|
|
|
|
tri_vindex[i] = make_packed_uint3(p_tris[off + 0] + vert_offset,
|
|
|
|
|
p_tris[off + 1] + vert_offset,
|
|
|
|
|
p_tris[off + 2] + vert_offset);
|
|
|
|
|
off += 3;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-09 03:57:39 +01:00
|
|
|
bool Mesh::has_motion_blur() const
|
|
|
|
|
{
|
|
|
|
|
return use_motion_blur && (attributes.find(ATTR_STD_MOTION_VERTEX_POSITION) ||
|
|
|
|
|
(get_subdivision_type() != Mesh::SUBDIVISION_NONE &&
|
|
|
|
|
subd_attributes.find(ATTR_STD_MOTION_VERTEX_POSITION)));
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 23:23:24 +01:00
|
|
|
PrimitiveType Mesh::primitive_type() const
|
2020-12-10 14:18:25 +01:00
|
|
|
{
|
2021-02-28 23:23:24 +01:00
|
|
|
return has_motion_blur() ? PRIMITIVE_MOTION_TRIANGLE : PRIMITIVE_TRIANGLE;
|
2020-12-10 14:18:25 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|