Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/blender/mesh.cpp
| Show First 20 Lines • Show All 1,080 Lines • ▼ Show 20 Lines | static void create_subd_mesh(Scene *scene, | ||||
| mesh->set_subd_dicing_rate(subd_dicing_rate); | mesh->set_subd_dicing_rate(subd_dicing_rate); | ||||
| mesh->set_subd_max_level(max_subdivisions); | mesh->set_subd_max_level(max_subdivisions); | ||||
| mesh->set_subd_objecttoworld(get_transform(b_ob.matrix_world())); | mesh->set_subd_objecttoworld(get_transform(b_ob.matrix_world())); | ||||
| } | } | ||||
| /* Sync */ | /* Sync */ | ||||
| /* Check whether some of "built-in" motion-related attributes are needed to be exported (includes | |||||
| * things like velocity from cache modifier, fluid simulation). | |||||
| * | |||||
| * NOTE: This code is run prior to object motion blur initialization. so can not access properties | |||||
| * set by `sync_object_motion_init()`. */ | |||||
| static bool mesh_need_motion_attribute(BObjectInfo &b_ob_info, Scene *scene) | |||||
| { | |||||
| const Scene::MotionType need_motion = scene->need_motion(); | |||||
| if (need_motion == Scene::MOTION_NONE) { | |||||
| /* Simple case: neither motion pass nor motion blur is needed, no need in the motion related | |||||
| * attributes. */ | |||||
| return false; | |||||
| } | |||||
| if (need_motion == Scene::MOTION_BLUR) { | |||||
| /* A bit tricky and implicit case: | |||||
| * - Motion blur is enabled in the scene, which implies specific number of time steps for | |||||
| * objects. | |||||
| * - If the object has motion blur disabled on it, it will have 0 time steps. | |||||
| * - Motion attribute expects non-zero time steps. | |||||
| * | |||||
| * Avoid adding motion attributes if the motion blur will enforce 0 motion steps. */ | |||||
| PointerRNA cobject = RNA_pointer_get(&b_ob_info.real_object.ptr, "cycles"); | |||||
| const bool use_motion = get_boolean(cobject, "use_motion_blur"); | |||||
| if (!use_motion) { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| /* Motion pass which implies 3 motion steps, or motion blur which is not disabled on object | |||||
| * level. */ | |||||
| return true; | |||||
| } | |||||
| void BlenderSync::sync_mesh(BL::Depsgraph b_depsgraph, BObjectInfo &b_ob_info, Mesh *mesh) | void BlenderSync::sync_mesh(BL::Depsgraph b_depsgraph, BObjectInfo &b_ob_info, Mesh *mesh) | ||||
| { | { | ||||
| /* make a copy of the shaders as the caller in the main thread still need them for syncing the | /* make a copy of the shaders as the caller in the main thread still need them for syncing the | ||||
| * attributes */ | * attributes */ | ||||
| array<Node *> used_shaders = mesh->get_used_shaders(); | array<Node *> used_shaders = mesh->get_used_shaders(); | ||||
| Mesh new_mesh; | Mesh new_mesh; | ||||
| new_mesh.set_used_shaders(used_shaders); | new_mesh.set_used_shaders(used_shaders); | ||||
| if (view_layer.use_surfaces) { | if (view_layer.use_surfaces) { | ||||
| /* Adaptive subdivision setup. Not for baking since that requires | /* Adaptive subdivision setup. Not for baking since that requires | ||||
| * exact mapping to the Blender mesh. */ | * exact mapping to the Blender mesh. */ | ||||
| if (!scene->bake_manager->get_baking()) { | if (!scene->bake_manager->get_baking()) { | ||||
| new_mesh.set_subdivision_type( | new_mesh.set_subdivision_type( | ||||
| object_subdivision_type(b_ob_info.real_object, preview, experimental)); | object_subdivision_type(b_ob_info.real_object, preview, experimental)); | ||||
| } | } | ||||
| /* For some reason, meshes do not need this... */ | /* For some reason, meshes do not need this... */ | ||||
| bool need_undeformed = new_mesh.need_attribute(scene, ATTR_STD_GENERATED); | bool need_undeformed = new_mesh.need_attribute(scene, ATTR_STD_GENERATED); | ||||
| BL::Mesh b_mesh = object_to_mesh( | BL::Mesh b_mesh = object_to_mesh( | ||||
| b_data, b_ob_info, b_depsgraph, need_undeformed, new_mesh.get_subdivision_type()); | b_data, b_ob_info, b_depsgraph, need_undeformed, new_mesh.get_subdivision_type()); | ||||
| if (b_mesh) { | if (b_mesh) { | ||||
| /* Motion blur attribute is relative to seconds, we need it relative to frames. */ | /* Motion blur attribute is relative to seconds, we need it relative to frames. */ | ||||
| const bool need_motion = mesh_need_motion_attribute(b_ob_info, scene); | const bool need_motion = object_need_motion_attribute(b_ob_info, scene); | ||||
| const float motion_scale = (need_motion) ? | const float motion_scale = (need_motion) ? | ||||
| scene->motion_shutter_time() / | scene->motion_shutter_time() / | ||||
| (b_scene.render().fps() / b_scene.render().fps_base()) : | (b_scene.render().fps() / b_scene.render().fps_base()) : | ||||
| 0.0f; | 0.0f; | ||||
| /* Sync mesh itself. */ | /* Sync mesh itself. */ | ||||
| if (new_mesh.get_subdivision_type() != Mesh::SUBDIVISION_NONE) | if (new_mesh.get_subdivision_type() != Mesh::SUBDIVISION_NONE) | ||||
| create_subd_mesh(scene, | create_subd_mesh(scene, | ||||
| ▲ Show 20 Lines • Show All 147 Lines • Show Last 20 Lines | |||||