Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/volume.cpp
| Show First 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | static int add_vertex(int3 v, | ||||
| } | } | ||||
| int vertex_offset = vertices.size(); | int vertex_offset = vertices.size(); | ||||
| used_verts[vert_key] = vertex_offset; | used_verts[vert_key] = vertex_offset; | ||||
| vertices.push_back(v); | vertices.push_back(v); | ||||
| return vertex_offset; | return vertex_offset; | ||||
| } | } | ||||
| static void create_quad(int3 corners[8], | static void create_quad(const std::array<int3, 8> &corners, | ||||
| vector<int3> &vertices, | vector<int3> &vertices, | ||||
| vector<QuadData> &quads, | vector<QuadData> &quads, | ||||
| int3 res, | int3 res, | ||||
| unordered_map<size_t, int> &used_verts, | unordered_map<size_t, int> &used_verts, | ||||
| int face_index) | int face_index) | ||||
| { | { | ||||
| QuadData quad; | QuadData quad; | ||||
| quad.v0 = add_vertex(corners[quads_indices[face_index][0]], vertices, res, used_verts); | quad.v0 = add_vertex(corners[quads_indices[face_index][0]], vertices, res, used_verts); | ||||
| ▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | void VolumeMeshBuilder::create_mesh(vector<float3> &vertices, | ||||
| generate_vertices_and_quads(vertices_is, quads); | generate_vertices_and_quads(vertices_is, quads); | ||||
| convert_object_space(vertices_is, vertices, face_overlap_avoidance); | convert_object_space(vertices_is, vertices, face_overlap_avoidance); | ||||
| convert_quads_to_tris(quads, indices, face_normals); | convert_quads_to_tris(quads, indices, face_normals); | ||||
| } | } | ||||
| #ifdef WITH_OPENVDB | |||||
| static std::array<int3, 8> prepare_box_corners(const openvdb::CoordBBox &bbox) | |||||
| { | |||||
| int3 min = make_int3(bbox.min().x(), bbox.min().y(), bbox.min().z()); | |||||
| int3 max = make_int3(bbox.max().x(), bbox.max().y(), bbox.max().z()); | |||||
| return { | |||||
| make_int3(min[0], min[1], min[2]), | |||||
| make_int3(max[0], min[1], min[2]), | |||||
| make_int3(max[0], max[1], min[2]), | |||||
| make_int3(min[0], max[1], min[2]), | |||||
| make_int3(min[0], min[1], max[2]), | |||||
| make_int3(max[0], min[1], max[2]), | |||||
| make_int3(max[0], max[1], max[2]), | |||||
| make_int3(min[0], max[1], max[2]), | |||||
| }; | |||||
| } | |||||
| #endif | |||||
| void VolumeMeshBuilder::generate_vertices_and_quads(vector<ccl::int3> &vertices_is, | void VolumeMeshBuilder::generate_vertices_and_quads(vector<ccl::int3> &vertices_is, | ||||
| vector<QuadData> &quads) | vector<QuadData> &quads) | ||||
| { | { | ||||
| #ifdef WITH_OPENVDB | #ifdef WITH_OPENVDB | ||||
| const openvdb::MaskGrid::TreeType &tree = topology_grid->tree(); | const openvdb::MaskGrid::TreeType &tree = topology_grid->tree(); | ||||
| tree.evalLeafBoundingBox(bbox); | tree.evalLeafBoundingBox(bbox); | ||||
| const int3 resolution = make_int3(bbox.dim().x(), bbox.dim().y(), bbox.dim().z()); | const int3 resolution = make_int3(bbox.dim().x(), bbox.dim().y(), bbox.dim().z()); | ||||
JacquesLucke: Are copying the tree on purpose? | |||||
Not Done Inline Actions"A function defined entirely inside a class/struct/union definition, whether it's a member function or a non-member friend function, is implicitly an inline function." JacquesLucke: "A function defined entirely inside a class/struct/union definition, whether it's a member… | |||||
Not Done Inline ActionsThis function does not seem to be used. JacquesLucke: This function does not seem to be used. | |||||
| unordered_map<size_t, int> used_verts; | unordered_map<size_t, int> used_verts; | ||||
| /* If the tree has any tiles, a more complex algorithm is necessary to generate a tight mesh | |||||
| * around the volume. For now just bail out and accept slightly worse performance in this case. | |||||
| * Most real world volume grids don't contain tiles anyway. */ | |||||
| if (tree.hasActiveTiles()) { | |||||
| openvdb::CoordBBox bbox; | |||||
| tree.evalLeafBoundingBox(bbox); | |||||
| /* +1 to convert from exclusive to inclusive bounds. */ | |||||
| bbox.max() = bbox.max().offsetBy(1); | |||||
| const std::array<int3, 8> corners = prepare_box_corners(bbox); | |||||
| create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_X_MIN); | |||||
| create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_X_MAX); | |||||
| create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_Y_MIN); | |||||
| create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_Y_MAX); | |||||
| create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_Z_MIN); | |||||
| create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_Z_MAX); | |||||
| return; | |||||
| } | |||||
| for (auto iter = tree.cbeginLeaf(); iter; ++iter) { | for (auto iter = tree.cbeginLeaf(); iter; ++iter) { | ||||
| openvdb::CoordBBox leaf_bbox = iter->getNodeBoundingBox(); | openvdb::CoordBBox leaf_bbox = iter->getNodeBoundingBox(); | ||||
| /* +1 to convert from exclusive to include bounds. */ | /* +1 to convert from exclusive to inclusive bounds. */ | ||||
| leaf_bbox.max() = leaf_bbox.max().offsetBy(1); | leaf_bbox.max() = leaf_bbox.max().offsetBy(1); | ||||
| int3 min = make_int3(leaf_bbox.min().x(), leaf_bbox.min().y(), leaf_bbox.min().z()); | const std::array<int3, 8> corners = prepare_box_corners(leaf_bbox); | ||||
| int3 max = make_int3(leaf_bbox.max().x(), leaf_bbox.max().y(), leaf_bbox.max().z()); | |||||
| int3 corners[8] = { | |||||
| make_int3(min[0], min[1], min[2]), | |||||
| make_int3(max[0], min[1], min[2]), | |||||
| make_int3(max[0], max[1], min[2]), | |||||
| make_int3(min[0], max[1], min[2]), | |||||
| make_int3(min[0], min[1], max[2]), | |||||
| make_int3(max[0], min[1], max[2]), | |||||
| make_int3(max[0], max[1], max[2]), | |||||
| make_int3(min[0], max[1], max[2]), | |||||
| }; | |||||
| /* Only create a quad if on the border between an active and an inactive leaf. | /* Only create a quad if on the border between an active and an inactive leaf. | ||||
| * | * | ||||
| * We verify that a leaf exists by probing a coordinate that is at its center, | * We verify that a leaf exists by probing a coordinate that is at its center, | ||||
| * to do so we compute the center of the current leaf and offset this coordinate | * to do so we compute the center of the current leaf and offset this coordinate | ||||
| * by the size of a leaf in each direction. | * by the size of a leaf in each direction. | ||||
| */ | */ | ||||
| static const int LEAF_DIM = openvdb::MaskGrid::TreeType::LeafNodeType::DIM; | static const int LEAF_DIM = openvdb::MaskGrid::TreeType::LeafNodeType::DIM; | ||||
| ▲ Show 20 Lines • Show All 286 Lines • Show Last 20 Lines | |||||
Are copying the tree on purpose?