Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/blender/blender_mesh.cpp
| Show First 20 Lines • Show All 1,017 Lines • ▼ Show 20 Lines | for (int step = 0; step < 2; step++) { | ||||
| for (b_fluid_domain.mesh_vertices.begin(svi); svi != b_fluid_domain.mesh_vertices.end(); | for (b_fluid_domain.mesh_vertices.begin(svi); svi != b_fluid_domain.mesh_vertices.end(); | ||||
| ++svi, ++i) { | ++svi, ++i) { | ||||
| mP[i] = P[i] + get_float3(svi->velocity()) * relative_time; | mP[i] = P[i] + get_float3(svi->velocity()) * relative_time; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static bool sync_mesh_precalculated_motion( | |||||
| BL::Mesh &b_mesh, BL::Object &b_ob, BL::Scene &b_scene, Scene *scene, Mesh *mesh) | |||||
| { | |||||
| if (scene->need_motion() == Scene::MOTION_NONE) | |||||
| return false; | |||||
| BL::VoxelMesherModifier b_voxelmesher = object_metaball_voxel_voxelmesher_find(b_ob); | |||||
| if (!(b_voxelmesher)) | |||||
| return false; | |||||
| /* Find or add attribute */ | |||||
| float3 *P = &mesh->verts[0]; | |||||
| Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); | |||||
| if (!attr_mP) { | |||||
| attr_mP = mesh->attributes.add(ATTR_STD_MOTION_VERTEX_POSITION); | |||||
| } | |||||
| /* Only export previous and next frame, we don't have any in between data. */ | |||||
| float motion_times[2] = {-1.0f, 1.0f}; | |||||
| for (int step = 0; step < 2; step++) { | |||||
| /* those are TIMES, but treated like Frames ? makes too high values, so take fps into account*/ | |||||
| float relative_time = motion_times[step] * scene->motion_shutter_time() * 0.5f / | |||||
| b_scene.render().fps(); | |||||
| float3 *mP = attr_mP->data_float3() + step * mesh->verts.size(); | |||||
| int i = 0; | |||||
| { | |||||
| BL::MeshVertexFloatPropertyLayer vlX = b_mesh.vertex_layers_float[std::string("velX")]; | |||||
| BL::MeshVertexFloatPropertyLayer vlY = b_mesh.vertex_layers_float[std::string("velY")]; | |||||
| BL::MeshVertexFloatPropertyLayer vlZ = b_mesh.vertex_layers_float[std::string("velZ")]; | |||||
| BL::Pointer ptrX = (BL::Pointer)vlX; | |||||
| BL::Pointer ptrY = (BL::Pointer)vlY; | |||||
| BL::Pointer ptrZ = (BL::Pointer)vlZ; | |||||
| if (!ptrX || !ptrY || !ptrZ || vlX.data.length() != mesh->verts.size()) { | |||||
| return false; | |||||
| } | |||||
| for (i = 0; i < mesh->verts.size(); i++) { | |||||
| float x = vlX.data[i].value(); | |||||
| float y = vlY.data[i].value(); | |||||
| float z = vlZ.data[i].value(); | |||||
| ccl::float3 p = make_float3(x, y, z); | |||||
| mP[i] = P[i] + p * relative_time; | |||||
| } | |||||
| } | |||||
| } | |||||
| return true; | |||||
| } | |||||
| void BlenderSync::sync_mesh(BL::Depsgraph b_depsgraph, | void BlenderSync::sync_mesh(BL::Depsgraph b_depsgraph, | ||||
| BL::Object b_ob, | BL::Object b_ob, | ||||
| Mesh *mesh, | Mesh *mesh, | ||||
| const vector<Shader *> &used_shaders) | const vector<Shader *> &used_shaders) | ||||
| { | { | ||||
| array<int> oldtriangles; | array<int> oldtriangles; | ||||
| array<Mesh::SubdFace> oldsubd_faces; | array<Mesh::SubdFace> oldsubd_faces; | ||||
| array<int> oldsubd_face_corners; | array<int> oldsubd_face_corners; | ||||
| Show All 21 Lines | if (view_layer.use_surfaces) { | ||||
| if (b_mesh) { | if (b_mesh) { | ||||
| /* Sync mesh itself. */ | /* Sync mesh itself. */ | ||||
| if (mesh->subdivision_type != Mesh::SUBDIVISION_NONE) | if (mesh->subdivision_type != Mesh::SUBDIVISION_NONE) | ||||
| create_subd_mesh( | create_subd_mesh( | ||||
| scene, mesh, b_ob, b_mesh, mesh->used_shaders, dicing_rate, max_subdivisions); | scene, mesh, b_ob, b_mesh, mesh->used_shaders, dicing_rate, max_subdivisions); | ||||
| else | else | ||||
| create_mesh(scene, mesh, b_mesh, mesh->used_shaders, false); | create_mesh(scene, mesh, b_mesh, mesh->used_shaders, false); | ||||
| /*sync other precalculated motion if any*/ | |||||
campbellbarton: *picky* spaces around comments, use sentences. | |||||
| sync_mesh_precalculated_motion(b_mesh, b_ob, b_scene, scene, mesh); | |||||
| free_object_to_mesh(b_data, b_ob, b_mesh); | free_object_to_mesh(b_data, b_ob, b_mesh); | ||||
| } | } | ||||
| } | } | ||||
| /* cached velocities (e.g. from alembic archive) */ | /* cached velocities (e.g. from alembic archive) */ | ||||
| sync_mesh_cached_velocities(b_ob, scene, mesh); | sync_mesh_cached_velocities(b_ob, scene, mesh); | ||||
| /* mesh fluid motion mantaflow */ | /* mesh fluid motion mantaflow */ | ||||
| Show All 27 Lines | void BlenderSync::sync_mesh_motion(BL::Depsgraph b_depsgraph, | ||||
| size_t numverts = mesh->verts.size(); | size_t numverts = mesh->verts.size(); | ||||
| if (numverts == 0) { | if (numverts == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Skip objects without deforming modifiers. this is not totally reliable, | /* Skip objects without deforming modifiers. this is not totally reliable, | ||||
| * would need a more extensive check to see which objects are animated. */ | * would need a more extensive check to see which objects are animated. */ | ||||
| BL::Mesh b_mesh(PointerRNA_NULL); | BL::Mesh b_mesh(PointerRNA_NULL); | ||||
| /* other precalculated motion (metaball voxelmesher for now only) */ | |||||
| BL::VoxelMesherModifier b_voxelmesher = object_metaball_voxel_voxelmesher_find(b_ob); | |||||
| if (b_voxelmesher) | |||||
| return; | |||||
| if (ccl::BKE_object_is_deform_modified(b_ob, b_scene, preview)) { | if (ccl::BKE_object_is_deform_modified(b_ob, b_scene, preview)) { | ||||
| /* get derived mesh */ | /* get derived mesh */ | ||||
| b_mesh = object_to_mesh(b_data, b_ob, b_depsgraph, false, Mesh::SUBDIVISION_NONE); | b_mesh = object_to_mesh(b_data, b_ob, b_depsgraph, false, Mesh::SUBDIVISION_NONE); | ||||
| } | } | ||||
| /* TODO(sergey): Perform preliminary check for number of vertices. */ | /* TODO(sergey): Perform preliminary check for number of vertices. */ | ||||
| if (b_mesh) { | if (b_mesh) { | ||||
| /* Export deformed coordinates. */ | /* Export deformed coordinates. */ | ||||
| ▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines | |||||
*picky* spaces around comments, use sentences.