Problem: the Blender synchronization process creates and tags nodes for usage. It does this by directly adding and removing nodes from the scene data. If some node is not tagged as used at the end of a synchronization, it then deletes the node from the scene. This poses a problem when it comes to supporting procedural nodes who can create other nodes not known by the Blender synchonization system, which will remove them. Nodes now have a NodeOwner, which is set after creation. Those owners for now are the Scene for scene level nodes and ShaderGraph for shader nodes. Instead of creating and deleting nodes using `new` and `delete` explicitely, we now use `create_node` and `delete_node` methods found on the owners. `delete_node` will assert that the owner is the right one. Whenever a scene level node is created or deleted, the appropriate node manager is tagged for an update, freeing this responsability from BlenderSync or other software exporters. Concerning BlenderSync, the `id_maps` do not explicitely manipulate scene data anymore, they only keep track of which nodes are used, employing the scene to create and delete them. To achieve this, the ParticleSystem is now a Node, although it does not have any sockets. This is part of T79131. Reviewed By: #cycles, brecht Maniphest Tasks: T79131 Differential Revision: https://developer.blender.org/D8540
138 lines
3.6 KiB
C++
138 lines
3.6 KiB
C++
/*
|
|
* Copyright 2011-2013 Blender Foundation
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include "render/particles.h"
|
|
#include "device/device.h"
|
|
#include "render/scene.h"
|
|
|
|
#include "util/util_foreach.h"
|
|
#include "util/util_hash.h"
|
|
#include "util/util_logging.h"
|
|
#include "util/util_map.h"
|
|
#include "util/util_progress.h"
|
|
#include "util/util_vector.h"
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
/* Particle System */
|
|
|
|
NODE_DEFINE(ParticleSystem)
|
|
{
|
|
NodeType *type = NodeType::add("particle_system", create);
|
|
return type;
|
|
}
|
|
|
|
ParticleSystem::ParticleSystem() : Node(node_type)
|
|
{
|
|
}
|
|
|
|
ParticleSystem::~ParticleSystem()
|
|
{
|
|
}
|
|
|
|
void ParticleSystem::tag_update(Scene *scene)
|
|
{
|
|
scene->particle_system_manager->need_update = true;
|
|
}
|
|
|
|
/* Particle System Manager */
|
|
|
|
ParticleSystemManager::ParticleSystemManager()
|
|
{
|
|
need_update = true;
|
|
}
|
|
|
|
ParticleSystemManager::~ParticleSystemManager()
|
|
{
|
|
}
|
|
|
|
void ParticleSystemManager::device_update_particles(Device *,
|
|
DeviceScene *dscene,
|
|
Scene *scene,
|
|
Progress &progress)
|
|
{
|
|
/* count particles.
|
|
* adds one dummy particle at the beginning to avoid invalid lookups,
|
|
* in case a shader uses particle info without actual particle data. */
|
|
int num_particles = 1;
|
|
for (size_t j = 0; j < scene->particle_systems.size(); j++)
|
|
num_particles += scene->particle_systems[j]->particles.size();
|
|
|
|
KernelParticle *kparticles = dscene->particles.alloc(num_particles);
|
|
|
|
/* dummy particle */
|
|
memset(kparticles, 0, sizeof(KernelParticle));
|
|
|
|
int i = 1;
|
|
for (size_t j = 0; j < scene->particle_systems.size(); j++) {
|
|
ParticleSystem *psys = scene->particle_systems[j];
|
|
|
|
for (size_t k = 0; k < psys->particles.size(); k++) {
|
|
/* pack in texture */
|
|
Particle &pa = psys->particles[k];
|
|
|
|
kparticles[i].index = pa.index;
|
|
kparticles[i].age = pa.age;
|
|
kparticles[i].lifetime = pa.lifetime;
|
|
kparticles[i].size = pa.size;
|
|
kparticles[i].rotation = pa.rotation;
|
|
kparticles[i].location = float3_to_float4(pa.location);
|
|
kparticles[i].velocity = float3_to_float4(pa.velocity);
|
|
kparticles[i].angular_velocity = float3_to_float4(pa.angular_velocity);
|
|
|
|
i++;
|
|
|
|
if (progress.get_cancel())
|
|
return;
|
|
}
|
|
}
|
|
|
|
dscene->particles.copy_to_device();
|
|
}
|
|
|
|
void ParticleSystemManager::device_update(Device *device,
|
|
DeviceScene *dscene,
|
|
Scene *scene,
|
|
Progress &progress)
|
|
{
|
|
if (!need_update)
|
|
return;
|
|
|
|
VLOG(1) << "Total " << scene->particle_systems.size() << " particle systems.";
|
|
|
|
device_free(device, dscene);
|
|
|
|
progress.set_status("Updating Particle Systems", "Copying Particles to device");
|
|
device_update_particles(device, dscene, scene, progress);
|
|
|
|
if (progress.get_cancel())
|
|
return;
|
|
|
|
need_update = false;
|
|
}
|
|
|
|
void ParticleSystemManager::device_free(Device *, DeviceScene *dscene)
|
|
{
|
|
dscene->particles.free();
|
|
}
|
|
|
|
void ParticleSystemManager::tag_update(Scene * /*scene*/)
|
|
{
|
|
need_update = true;
|
|
}
|
|
|
|
CCL_NAMESPACE_END
|