Blender V5.3
geometry_mesh.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "bvh/bvh.h"
6
7#include "device/device.h"
8
9#include "scene/attribute.h"
10#include "scene/camera.h"
11#include "scene/geometry.h"
12#include "scene/hair.h"
13#include "scene/light.h"
14#include "scene/mesh.h"
15#include "scene/object.h"
16#include "scene/osl.h"
17#include "scene/pointcloud.h"
18#include "scene/scene.h"
19#include "scene/shader.h"
20#include "scene/shader_nodes.h"
21
22#include "util/progress.h"
23
25
27 DeviceScene *dscene,
28 Scene *scene,
29 Progress &progress)
30{
31 /* Count. */
32 size_t tri_size = 0;
33
34 size_t curve_size = 0;
35 size_t curve_segment_size = 0;
36
37 size_t point_size = 0;
38
39 for (Geometry *geom : scene->geometry) {
40 if (geom->is_mesh() || geom->is_volume()) {
41 Mesh *mesh = static_cast<Mesh *>(geom);
42
43 tri_size += mesh->num_triangles();
44 }
45 else if (geom->is_hair()) {
46 Hair *hair = static_cast<Hair *>(geom);
47
48 curve_size += hair->num_curves();
49 curve_segment_size += hair->num_segments();
50 }
51 else if (geom->is_pointcloud()) {
52 PointCloud *pointcloud = static_cast<PointCloud *>(geom);
53 point_size += pointcloud->num_points();
54 }
55 }
56
57 /* Fill in all the arrays. */
58 if (tri_size != 0) {
59 progress.set_status("Updating Mesh", "Computing normals");
60
61 uint *tri_shader = dscene->tri_shader.alloc(tri_size);
62 packed_uint3 *tri_vindex = dscene->tri_vindex.alloc(tri_size);
63
64 const bool copy_all_data = dscene->tri_shader.need_realloc() ||
65 dscene->tri_vindex.need_realloc();
66
67 for (Geometry *geom : scene->geometry) {
68 if (geom->is_mesh() || geom->is_volume()) {
69 Mesh *mesh = static_cast<Mesh *>(geom);
70
71 if (mesh->shader_is_modified() || mesh->smooth_is_modified() ||
72 mesh->triangles_is_modified() || copy_all_data)
73 {
74 mesh->pack_shaders(scene, &tri_shader[mesh->prim_offset]);
75 }
76
77 if (mesh->triangles_is_modified() || copy_all_data) {
78 mesh->pack_triangles(&tri_vindex[mesh->prim_offset]);
79 }
80
81 if (progress.get_cancel()) {
82 return;
83 }
84 }
85 }
86
87 /* vertex coordinates */
88 progress.set_status("Updating Mesh", "Copying Mesh to device");
89
92 }
93
94 if (curve_segment_size != 0) {
95 progress.set_status("Updating Mesh", "Copying Curves to device");
96
97 KernelCurve *curves = dscene->curves.alloc(curve_size);
98 KernelCurveSegment *curve_segments = dscene->curve_segments.alloc(curve_segment_size);
99
100 const bool copy_all_data = dscene->curves.need_realloc() ||
102
103 for (Geometry *geom : scene->geometry) {
104 if (geom->is_hair()) {
105 Hair *hair = static_cast<Hair *>(geom);
106
107 const bool curve_data_modified = hair->curve_shader_is_modified() ||
108 hair->curve_first_key_is_modified();
109
110 if (!curve_data_modified && !copy_all_data) {
111 continue;
112 }
113
114 hair->pack_curves(
115 scene, &curves[hair->prim_offset], &curve_segments[hair->curve_segment_offset]);
116 if (progress.get_cancel()) {
117 return;
118 }
119 }
120 }
121
124 }
125
126 if (point_size != 0) {
127 progress.set_status("Updating Mesh", "Copying Point clouds to device");
128
129 uint *points_shader = dscene->points_shader.alloc(point_size);
130
131 for (Geometry *geom : scene->geometry) {
132 if (geom->is_pointcloud()) {
133 PointCloud *pointcloud = static_cast<PointCloud *>(geom);
134 pointcloud->pack(scene, &points_shader[pointcloud->prim_offset]);
135 if (progress.get_cancel()) {
136 return;
137 }
138 }
139 }
140
142 }
143}
144
device_vector< uint > points_shader
Definition devicescene.h:39
device_vector< KernelCurveSegment > curve_segments
Definition devicescene.h:35
device_vector< KernelCurve > curves
Definition devicescene.h:33
device_vector< packed_uint3 > tri_vindex
Definition devicescene.h:30
device_vector< uint > tri_shader
Definition devicescene.h:29
void device_update_mesh(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
bool is_volume() const
bool is_pointcloud() const
bool is_hair() const
size_t prim_offset
bool is_mesh() const
Definition hair.h:13
void pack_curves(Scene *scene, KernelCurve *curve, KernelCurveSegment *curve_segments)
Definition hair.cpp:421
size_t curve_segment_offset
Definition hair.h:76
size_t num_curves() const
Definition hair.h:109
size_t num_segments() const
Definition hair.h:114
void pack_triangles(packed_uint3 *tri_vindex)
size_t num_triangles() const
Definition scene/mesh.h:73
void pack_shaders(Scene *scene, uint *shader)
size_t num_points() const
void pack(Scene *scene, uint *packed_shader)
bool get_cancel() const
Definition progress.h:77
void set_status(const string &status_, const string &substatus_="")
Definition progress.h:248
Definition scene.h:133
unique_ptr_vector< Geometry > geometry
Definition scene.h:161
T * alloc(const size_t width, const size_t height=0)
#define CCL_NAMESPACE_END
#define point_size