LayerParticleEditorNode* ParticlesEditorController::CloneParticleLayerNode(LayerParticleEditorNode* layerToClone) { if (!layerToClone || !layerToClone->GetLayer()) { return NULL; } EmitterParticleEditorNode* emitterNode = layerToClone->GetEmitterEditorNode(); if (!emitterNode) { return NULL; } ParticleEmitter* emitter = emitterNode->GetParticleEmitter(); if (!emitter) { return NULL; } ParticleLayer* clonedLayer = layerToClone->GetLayer()->Clone(); emitter->AddLayer(clonedLayer); LayerParticleEditorNode* clonedEditorNode = new LayerParticleEditorNode(emitterNode, clonedLayer); emitterNode->AddChildNode(clonedEditorNode); return clonedEditorNode; }
bool ParticlesEditorController::PerformMoveBetweenEmitters(EmitterParticleEditorNode* oldEmitterNode, EmitterParticleEditorNode* newEmitterNode, LayerParticleEditorNode* layerNodeToMove, LayerParticleEditorNode* layerNodeToInsertAbove) { ParticleEmitter* oldParentEmitter = oldEmitterNode->GetParticleEmitter(); ParticleEmitter* newParentEmitter = newEmitterNode->GetParticleEmitter(); if (!oldParentEmitter || !newParentEmitter) { return false; } // Move the Editor node. layerNodeToInsertAbove is allowed to be NULL. newEmitterNode->AddChildNodeAbove(layerNodeToMove, layerNodeToInsertAbove); oldEmitterNode->RemoveChildNode(layerNodeToMove, false); // Move the Particle Layers themselves. ParticleLayer* layerToMove = layerNodeToMove->GetLayer(); ParticleLayer* layerToInsertAbove = NULL; if (layerNodeToInsertAbove) { layerToInsertAbove = layerNodeToInsertAbove->GetLayer(); } SafeRetain(layerToMove); oldParentEmitter->RemoveLayer(layerToMove); newParentEmitter->AddLayer(layerToMove, layerToInsertAbove); SafeRelease(layerToMove); // Update the emitter. layerNodeToMove->UpdateEmitterEditorNode(newEmitterNode); return true; }
LayerParticleEditorNode* ParticlesEditorController::AddParticleLayerToNode(EmitterParticleEditorNode* emitterNode) { if (!emitterNode) { return NULL; } ParticleEmitter* emitter = emitterNode->GetParticleEmitter(); if (!emitter) { return NULL; } // Create the new layer. ParticleLayer *layer; if(emitter->GetIs3D()) { layer = new ParticleLayer3D(emitter); } else { layer = new ParticleLayer(); } layer->startTime = 0; layer->endTime = LIFETIME_FOR_NEW_PARTICLE_EMITTER; layer->life = new PropertyLineValue<float32>(emitter->GetLifeTime()); layer->layerName = String("Layer"); emitter->AddLayer(layer); // Create the new node and add it to the tree. LayerParticleEditorNode* layerNode = new LayerParticleEditorNode(emitterNode, layer); emitterNode->AddChildNode(layerNode); SafeRelease(layer); return layerNode; }
RenderObject * ParticleEmitter3D::Clone(RenderObject *newObject) { if(!newObject) { DVASSERT_MSG(IsPointerToExactClass<ParticleEmitter3D>(this), "Can clone only ParticleEmitter3D"); newObject = new ParticleEmitter3D(); } else { CleanupLayers(); ReleaseFromCache(static_cast<ParticleEmitter *>(newObject)->emitterFileName); } ParticleEmitter* clonedEmitter = static_cast<ParticleEmitter*>(newObject); clonedEmitter->SetConfigPath(this->configPath); clonedEmitter->SetPosition(this->position); clonedEmitter->SetAngle(this->angle); clonedEmitter->SetLifeTime(this->lifeTime); clonedEmitter->SetRepeatCount(this->repeatCount); clonedEmitter->SetTime(this->time); clonedEmitter->SetEmitPointsCount(this->emitPointsCount); clonedEmitter->SetPaused(this->isPaused); clonedEmitter->SetAutoRestart(this->isAutorestart); clonedEmitter->SetParticlesFollow(this->particlesFollow); clonedEmitter->Set3D(this->is3D); clonedEmitter->SetPlaybackSpeed(this->playbackSpeed); clonedEmitter->SetInitialTranslationVector(this->initialTranslationVector); if (this->emissionVector) { clonedEmitter->emissionVector = this->emissionVector->Clone(); clonedEmitter->emissionVector->Release(); } if (this->emissionAngle) { clonedEmitter->emissionAngle = this->emissionAngle->Clone(); clonedEmitter->emissionAngle->Release(); } if (this->emissionRange) { clonedEmitter->emissionRange = this->emissionRange->Clone(); clonedEmitter->emissionRange->Release(); } if (this->radius) { clonedEmitter->radius = this->radius->Clone(); clonedEmitter->radius->Release(); } if (this->colorOverLife) { clonedEmitter->colorOverLife = this->colorOverLife->Clone(); clonedEmitter->colorOverLife->Release(); } if (this->size) { clonedEmitter->size = this->size->Clone(); clonedEmitter->size->Release(); } clonedEmitter->emitterType = this->emitterType; clonedEmitter->currentColor = this->currentColor; clonedEmitter->SetShortEffect(shortEffect); // Now can add Layers. Need to update their parents. for (Vector<ParticleLayer*>::iterator iter = this->layers.begin(); iter != this->layers.end(); iter ++) { ParticleLayer* clonedLayer = (*iter)->Clone(NULL); ParticleLayer3D* clonedLayer3D = dynamic_cast<ParticleLayer3D*>(clonedLayer); if (clonedLayer3D) { clonedLayer3D->SetParent(clonedEmitter); } clonedEmitter->AddLayer(clonedLayer); SafeRelease(clonedLayer); } time = 0.0f; repeatCount = 0; lodLevelLocked = false; currentLodLevel = desiredLodLevel; clonedEmitter->emitterFileName = emitterFileName; RetainInCache(emitterFileName); return newObject; }