Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/blender/mesh.cpp
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* STEP 4: Copy attribute to the duplicated vertices. */ | /* STEP 4: Copy attribute to the duplicated vertices. */ | ||||
| for (int vert_index = 0; vert_index < num_verts; ++vert_index) { | for (int vert_index = 0; vert_index < num_verts; ++vert_index) { | ||||
| const int orig_index = vert_orig_index[vert_index]; | const int orig_index = vert_orig_index[vert_index]; | ||||
| data[vert_index] = data[orig_index]; | data[vert_index] = data[orig_index]; | ||||
| } | } | ||||
| } | } | ||||
| static std::optional<BL::IntAttribute> find_corner_vert_attribute(BL::Mesh b_mesh) | |||||
| { | |||||
| for (BL::Attribute &b_attribute : b_mesh.attributes) { | |||||
| if (b_attribute.domain() != BL::Attribute::domain_CORNER) { | |||||
| continue; | |||||
| } | |||||
| if (b_attribute.data_type() != BL::Attribute::data_type_INT) { | |||||
| continue; | |||||
| } | |||||
| if (b_attribute.name() != ".corner_vert") { | |||||
| continue; | |||||
| } | |||||
| return BL::IntAttribute{b_attribute}; | |||||
| } | |||||
| return std::nullopt; | |||||
| } | |||||
| /* The Random Per Island attribute is a random float associated with each | /* The Random Per Island attribute is a random float associated with each | ||||
| * connected component (island) of the mesh. The attribute is computed by | * connected component (island) of the mesh. The attribute is computed by | ||||
| * first classifying the vertices into different sets using a Disjoint Set | * first classifying the vertices into different sets using a Disjoint Set | ||||
| * data structure. Then the index of the root of each vertex (Which is the | * data structure. Then the index of the root of each vertex (Which is the | ||||
| * representative of the set the vertex belongs to) is hashed and stored. | * representative of the set the vertex belongs to) is hashed and stored. | ||||
| * | * | ||||
| * We are using a face attribute to avoid interpolation during rendering, | * We are using a face attribute to avoid interpolation during rendering, | ||||
| * allowing the user to safely hash the output further. Had we used vertex | * allowing the user to safely hash the output further. Had we used vertex | ||||
| Show All 30 Lines | |||||
| if (!subdivision) { | if (!subdivision) { | ||||
| for (BL::MeshLoopTriangle &t : b_mesh.loop_triangles) { | for (BL::MeshLoopTriangle &t : b_mesh.loop_triangles) { | ||||
| data[t.index()] = hash_uint_to_float(vertices_sets.find(t.vertices()[0])); | data[t.index()] = hash_uint_to_float(vertices_sets.find(t.vertices()[0])); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (polys_num != 0) { | if (polys_num != 0) { | ||||
| const MPoly *polys = static_cast<const MPoly *>(b_mesh.polygons[0].ptr.data); | const MPoly *polys = static_cast<const MPoly *>(b_mesh.polygons[0].ptr.data); | ||||
| const MLoop *loops = static_cast<const MLoop *>(b_mesh.loops[0].ptr.data); | BL::IntAttribute corner_verts = *find_corner_vert_attribute(b_mesh); | ||||
| for (int i = 0; i < polys_num; i++) { | for (int i = 0; i < polys_num; i++) { | ||||
| const MPoly &b_poly = polys[i]; | const MPoly &b_poly = polys[i]; | ||||
| const MLoop &b_loop = loops[b_poly.loopstart]; | const int vert = corner_verts.data[b_poly.loopstart].value(); | ||||
| data[i] = hash_uint_to_float(vertices_sets.find(b_loop.v)); | data[i] = hash_uint_to_float(vertices_sets.find(vert)); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Create Mesh */ | /* Create Mesh */ | ||||
| static std::optional<BL::IntAttribute> find_material_index_attribute(BL::Mesh b_mesh) | static std::optional<BL::IntAttribute> find_material_index_attribute(BL::Mesh b_mesh) | ||||
| ▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | |||||
| * NOTE: Autosmooth is already taken care about. | * NOTE: Autosmooth is already taken care about. | ||||
| */ | */ | ||||
| mesh->add_triangle(vi[0], vi[1], vi[2], shader, smooth); | mesh->add_triangle(vi[0], vi[1], vi[2], shader, smooth); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| vector<int> vi; | vector<int> vi; | ||||
| const MLoop *loops = static_cast<const MLoop *>(b_mesh.loops[0].ptr.data); | std::optional<BL::IntAttribute> corner_verts = find_corner_vert_attribute(b_mesh); | ||||
| for (int i = 0; i < numfaces; i++) { | for (int i = 0; i < numfaces; i++) { | ||||
| const MPoly &b_poly = polys[i]; | const MPoly &b_poly = polys[i]; | ||||
| int n = b_poly.totloop; | int n = b_poly.totloop; | ||||
| int shader = get_material_index(i); | int shader = get_material_index(i); | ||||
| bool smooth = (b_poly.flag & ME_SMOOTH) || use_loop_normals; | bool smooth = (b_poly.flag & ME_SMOOTH) || use_loop_normals; | ||||
| vi.resize(n); | vi.resize(n); | ||||
| for (int i = 0; i < n; i++) { | for (int i = 0; i < n; i++) { | ||||
| /* NOTE: Autosmooth is already taken care about. */ | /* NOTE: Autosmooth is already taken care about. */ | ||||
| vi[i] = corner_verts->data[b_poly.loopstart + i].value(); | |||||
| vi[i] = loops[b_poly.loopstart + i].v; | |||||
| } | } | ||||
| /* create subd faces */ | /* create subd faces */ | ||||
| mesh->add_subd_face(&vi[0], n, shader, smooth); | mesh->add_subd_face(&vi[0], n, shader, smooth); | ||||
| } | } | ||||
| } | } | ||||
| /* Create all needed attributes. | /* Create all needed attributes. | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||