axmol/extensions/Particle3D/PU/CCPUEmitterTranslator.cpp

648 lines
29 KiB
C++
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (C) 2013 Henry van Merode. All rights reserved.
Copyright (c) 2015-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2021-12-25 10:04:45 +08:00
2022-02-24 18:51:36 +08:00
https://adxeproject.github.io/
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCPUEmitterTranslator.h"
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
#include "extensions/Particle3D/PU/CCPUEmitterManager.h"
NS_CC_BEGIN
2021-12-25 10:04:45 +08:00
PUEmitterTranslator::PUEmitterTranslator() : _emitter(nullptr) {}
2019-11-23 20:27:39 +08:00
//-------------------------------------------------------------------------
2021-12-25 10:04:45 +08:00
void PUEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode* node)
2019-11-23 20:27:39 +08:00
{
2021-12-25 10:04:45 +08:00
PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node);
2019-11-23 20:27:39 +08:00
PUObjectAbstractNode* parent = obj->parent ? reinterpret_cast<PUObjectAbstractNode*>(obj->parent) : 0;
// The name of the obj is the type of the emitter
2021-12-25 10:04:45 +08:00
// Remark: This can be solved by using a listener, so that obj->values is filled with type + name. Something for
// later
2019-11-23 20:27:39 +08:00
std::string type;
2021-12-25 10:04:45 +08:00
if (!obj->name.empty())
2019-11-23 20:27:39 +08:00
{
type = obj->name;
}
//// Get the factory
2021-12-25 10:04:45 +08:00
// ParticleEmitterFactory* particleEmitterFactory =
// ParticleSystemManager::getSingletonPtr()->getEmitterFactory(type); if (!particleEmitterFactory)
2019-11-23 20:27:39 +08:00
//{
// compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
// return;
2021-12-25 10:04:45 +08:00
// }
PUScriptTranslator* particleEmitterTranlator = PUEmitterManager::Instance()->getTranslator(type);
if (!particleEmitterTranlator)
return;
2019-11-23 20:27:39 +08:00
//// Create the emitter
2021-12-25 10:04:45 +08:00
// mEmitter = ParticleSystemManager::getSingletonPtr()->createEmitter(type);
// if (!mEmitter)
2019-11-23 20:27:39 +08:00
//{
// compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
// return;
2021-12-25 10:04:45 +08:00
// }
2019-11-23 20:27:39 +08:00
_emitter = PUEmitterManager::Instance()->createEmitter(type);
2021-12-25 10:04:45 +08:00
if (!_emitter)
return;
_emitter->setEmitterType(type);
2019-11-23 20:27:39 +08:00
if (parent && parent->context)
{
PUParticleSystem3D* system = static_cast<PUParticleSystem3D*>(parent->context);
system->addEmitter(_emitter);
}
// The first value is the (optional) name
std::string name;
2021-12-25 10:04:45 +08:00
if (!obj->values.empty())
2019-11-23 20:27:39 +08:00
{
getString(*obj->values.front(), &name);
_emitter->setName(name);
}
// Set it in the context
obj->context = _emitter;
// Run through properties
2021-12-25 10:04:45 +08:00
for (PUAbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
2019-11-23 20:27:39 +08:00
{
2021-12-25 10:04:45 +08:00
if ((*i)->type == ANT_PROPERTY)
2019-11-23 20:27:39 +08:00
{
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>((*i));
if (prop->name == token[TOKEN_ENABLED])
{
// Property: enabled
if (passValidateProperty(compiler, prop, token[TOKEN_ENABLED], VAL_BOOL))
{
bool val;
2021-12-25 10:04:45 +08:00
if (getBoolean(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setEnabled(val);
}
}
}
else if (prop->name == token[TOKEN_POSITION])
{
// Property: position
if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3))
{
Vec3 val;
2021-12-25 10:04:45 +08:00
if (getVector3(prop->values.begin(), prop->values.end(), &val))
2019-11-23 20:27:39 +08:00
{
2021-12-25 10:04:45 +08:00
// mEmitter->position = val;
// mEmitter->originalPosition = val;
2019-11-23 20:27:39 +08:00
_emitter->setLocalPosition(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_DIRECTION])
{
// Property: direction
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_DIRECTION], VAL_VECTOR3))
{
Vec3 val;
2021-12-25 10:04:45 +08:00
if (getVector3(prop->values.begin(), prop->values.end(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setParticleDirection(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_ORIENTATION])
{
// Property: orientation
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_ORIENTATION], VAL_QUATERNION))
{
Quaternion val;
2021-12-25 10:04:45 +08:00
if (getQuaternion(prop->values.begin(), prop->values.end(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setParticleOrientation(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_START_ORIENTATION_RANGE])
{
// Property: start_orientation_range
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_START_ORIENTATION_RANGE], VAL_QUATERNION))
{
Quaternion val;
2021-12-25 10:04:45 +08:00
if (getQuaternion(prop->values.begin(), prop->values.end(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setParticleOrientationRangeStart(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_ORIENTATION_RANGE_START])
{
// Property: range_start_orientation (deprecated and replaced by start_orientation_range)
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_ORIENTATION_RANGE_START], VAL_QUATERNION))
{
Quaternion val;
2021-12-25 10:04:45 +08:00
if (getQuaternion(prop->values.begin(), prop->values.end(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setParticleOrientationRangeStart(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_END_ORIENTATION_RANGE])
{
// Property: end_orientation_range
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_END_ORIENTATION_RANGE], VAL_QUATERNION))
{
Quaternion val;
2021-12-25 10:04:45 +08:00
if (getQuaternion(prop->values.begin(), prop->values.end(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setParticleOrientationRangeEnd(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_ORIENTATION_RANGE_END])
{
// Property: range_end_orientation (deprecated and replaced by end_orientation_range)
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_ORIENTATION_RANGE_END], VAL_QUATERNION))
{
Quaternion val;
2021-12-25 10:04:45 +08:00
if (getQuaternion(prop->values.begin(), prop->values.end(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setParticleOrientationRangeEnd(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_EMISSION_RATE])
{
// Property: emission_rate
// If it is a property, it is a fixed value
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_EMISSION_RATE], VAL_REAL))
{
float val = 0.0f;
2021-12-25 10:04:45 +08:00
if (getFloat(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
2021-12-08 00:11:53 +08:00
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
2019-11-23 20:27:39 +08:00
dynamicAttributeFixed->setValue(val);
_emitter->setDynEmissionRate(dynamicAttributeFixed);
}
}
}
else if (prop->name == token[TOKEN_TIME_TO_LIVE])
{
// Property: time_to_live
// If it is a property, it is a fixed value
if (passValidateProperty(compiler, prop, token[TOKEN_TIME_TO_LIVE], VAL_REAL))
{
float val = 0.0f;
2021-12-25 10:04:45 +08:00
if (getFloat(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
2021-12-08 00:11:53 +08:00
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
2019-11-23 20:27:39 +08:00
dynamicAttributeFixed->setValue(val);
_emitter->setDynTotalTimeToLive(dynamicAttributeFixed);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_MASS])
{
// Property: mass
// If it is a property, it is a fixed value
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_MASS], VAL_REAL))
{
float val = 0.0f;
2021-12-25 10:04:45 +08:00
if (getFloat(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
2021-12-08 00:11:53 +08:00
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
2019-11-23 20:27:39 +08:00
dynamicAttributeFixed->setValue(val);
_emitter->setDynParticleMass(dynamicAttributeFixed);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_START_TEXCOORDS_RANGE])
{
// Property: start_texture_coords_range
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_START_TEXCOORDS_RANGE], VAL_UINT))
{
unsigned int val = 0;
2021-12-25 10:04:45 +08:00
if (getUInt(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setParticleTextureCoordsRangeStart(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_START_TEXCOORDS])
{
// Property: start_texture_coords (deprecated and replaced by start_texture_coords_range)
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_START_TEXCOORDS], VAL_UINT))
{
unsigned int val = 0;
2021-12-25 10:04:45 +08:00
if (getUInt(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setParticleTextureCoordsRangeStart(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_END_TEXCOORDS_RANGE])
{
// Property: end_texture_coords_range
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_END_TEXCOORDS_RANGE], VAL_UINT))
{
unsigned int val = 0;
2021-12-25 10:04:45 +08:00
if (getUInt(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setParticleTextureCoordsRangeEnd(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_END_TEXCOORDS])
{
// Property: end_texture_coords (deprecated and replaced by end_texture_coords_range)
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_END_TEXCOORDS], VAL_UINT))
{
unsigned int val = 0;
2021-12-25 10:04:45 +08:00
if (getUInt(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setParticleTextureCoordsRangeEnd(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_TEXCOORDS])
{
// Property: texture_coords
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_TEXCOORDS], VAL_UINT))
{
unsigned int val = 0;
2021-12-25 10:04:45 +08:00
if (getUInt(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setParticleTextureCoords(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_START_COLOUR_RANGE])
{
// Property: start_colour_range
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_START_COLOUR_RANGE], VAL_COLOURVALUE))
{
Vec4 val;
2021-12-25 10:04:45 +08:00
if (getVector4(prop->values.begin(), prop->values.end(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setParticleColorRangeStart(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_END_COLOUR_RANGE])
{
// Property: end_colour_range
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_END_COLOUR_RANGE], VAL_COLOURVALUE))
{
Vec4 val;
2021-12-25 10:04:45 +08:00
if (getVector4(prop->values.begin(), prop->values.end(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setParticleColorRangeEnd(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_COLOUR])
{
// Property: colour
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_COLOUR], VAL_COLOURVALUE))
{
Vec4 val;
2021-12-25 10:04:45 +08:00
if (getVector4(prop->values.begin(), prop->values.end(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setParticleColor(val);
}
}
}
else if (prop->name == token[TOKEN_VELOCITY])
{
// Property: velocity
// If it is a property, it is a fixed value
if (passValidateProperty(compiler, prop, token[TOKEN_VELOCITY], VAL_REAL))
{
float val = 0.0f;
2021-12-25 10:04:45 +08:00
if (getFloat(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
2021-12-08 00:11:53 +08:00
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
2019-11-23 20:27:39 +08:00
dynamicAttributeFixed->setValue(val);
_emitter->setDynVelocity(dynamicAttributeFixed);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_DURATION])
{
// Property: duration
// If it is a property, it is a fixed value
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_DURATION], VAL_REAL))
{
float val = 0.0f;
2021-12-25 10:04:45 +08:00
if (getFloat(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
2021-12-08 00:11:53 +08:00
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
2019-11-23 20:27:39 +08:00
dynamicAttributeFixed->setValue(val);
_emitter->setDynDuration(dynamicAttributeFixed);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_REPEAT_DELAY])
{
// Property: repeat_delay
// If it is a property, it is a fixed value
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_REPEAT_DELAY], VAL_REAL))
{
float val = 0.0f;
2021-12-25 10:04:45 +08:00
if (getFloat(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
2021-12-08 00:11:53 +08:00
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
2019-11-23 20:27:39 +08:00
dynamicAttributeFixed->setValue(val);
_emitter->setDynRepeatDelay(dynamicAttributeFixed);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_EMITS])
{
// Property: emits
if (passValidatePropertyNumberOfValues(compiler, prop, token[TOKEN_EMITTER_EMITS], 2))
{
std::string particleType;
PUAbstractNodeList::const_iterator it = prop->values.begin();
if (getString(**it, &particleType))
{
if (particleType == token[TOKEN_VISUAL_PARTICLE])
{
_emitter->setEmitsType(PUParticle3D::PT_VISUAL);
}
else if (particleType == token[TOKEN_EMITTER_PARTICLE])
{
_emitter->setEmitsType(PUParticle3D::PT_EMITTER);
}
else if (particleType == token[TOKEN_AFFECTOR_PARTICLE])
{
_emitter->setEmitsType(PUParticle3D::PT_AFFECTOR);
}
else if (particleType == token[TOKEN_TECHNIQUE_PARTICLE])
{
_emitter->setEmitsType(PUParticle3D::PT_TECHNIQUE);
}
else if (particleType == token[TOKEN_SYSTEM_PARTICLE])
{
_emitter->setEmitsType(PUParticle3D::PT_SYSTEM);
}
++it;
if (getString(**it, &name))
{
_emitter->setEmitsName(name);
}
}
}
}
else if (prop->name == token[TOKEN_ANGLE])
{
// Property: angle
// If it is a property, it is a fixed value
if (passValidateProperty(compiler, prop, token[TOKEN_ANGLE], VAL_REAL))
{
float val = 0.0f;
2021-12-25 10:04:45 +08:00
if (getFloat(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
2021-12-08 00:11:53 +08:00
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
2019-11-23 20:27:39 +08:00
dynamicAttributeFixed->setValue(val);
_emitter->setDynAngle(dynamicAttributeFixed);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_ALL_PARTICLE_DIM])
{
// Property: all_particle_dimensions
// If it is a property, it is a fixed value
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_ALL_PARTICLE_DIM], VAL_REAL))
{
float val = 0.0f;
2021-12-25 10:04:45 +08:00
if (getFloat(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
2021-12-08 00:11:53 +08:00
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
2019-11-23 20:27:39 +08:00
dynamicAttributeFixed->setValue(val);
_emitter->setDynParticleAllDimensions(dynamicAttributeFixed);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_PARTICLE_WIDTH])
{
// Property: particle_width
// If it is a property, it is a fixed value
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_PARTICLE_WIDTH], VAL_REAL))
{
float val = 0.0f;
2021-12-25 10:04:45 +08:00
if (getFloat(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
2021-12-08 00:11:53 +08:00
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
2019-11-23 20:27:39 +08:00
dynamicAttributeFixed->setValue(val);
_emitter->setDynParticleWidth(dynamicAttributeFixed);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_PARTICLE_HEIGHT])
{
// Property: particle_height
// If it is a property, it is a fixed value
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_PARTICLE_HEIGHT], VAL_REAL))
{
float val = 0.0f;
2021-12-25 10:04:45 +08:00
if (getFloat(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
2021-12-08 00:11:53 +08:00
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
2019-11-23 20:27:39 +08:00
dynamicAttributeFixed->setValue(val);
_emitter->setDynParticleHeight(dynamicAttributeFixed);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_PARTICLE_DEPTH])
{
// Property: particle_depth
// If it is a property, it is a fixed value
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_PARTICLE_DEPTH], VAL_REAL))
{
float val = 0.0f;
2021-12-25 10:04:45 +08:00
if (getFloat(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
2021-12-08 00:11:53 +08:00
PUDynamicAttributeFixed* dynamicAttributeFixed = new PUDynamicAttributeFixed();
2019-11-23 20:27:39 +08:00
dynamicAttributeFixed->setValue(val);
_emitter->setDynParticleDepth(dynamicAttributeFixed);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_AUTO_DIRECTION])
{
// Property: auto_direction
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_AUTO_DIRECTION], VAL_BOOL))
{
bool val;
2021-12-25 10:04:45 +08:00
if (getBoolean(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setAutoDirection(val);
}
}
}
else if (prop->name == token[TOKEN_KEEP_LOCAL])
{
// Property: keep_local
if (passValidateProperty(compiler, prop, token[TOKEN_KEEP_LOCAL], VAL_BOOL))
{
bool val;
2021-12-25 10:04:45 +08:00
if (getBoolean(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setKeepLocal(val);
}
}
}
else if (prop->name == token[TOKEN_EMITTER_FORCE_EMISSION])
{
// Property: force_emission
if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_FORCE_EMISSION], VAL_BOOL))
{
bool val;
2021-12-25 10:04:45 +08:00
if (getBoolean(*prop->values.front(), &val))
2019-11-23 20:27:39 +08:00
{
_emitter->setForceEmission(val);
}
}
}
else if (particleEmitterTranlator->translateChildProperty(compiler, *i))
{
// Parsed the property by another translator; do nothing
}
else
{
errorUnexpectedProperty(compiler, prop);
}
}
2021-12-25 10:04:45 +08:00
else if ((*i)->type == ANT_OBJECT)
2019-11-23 20:27:39 +08:00
{
PUObjectAbstractNode* child = reinterpret_cast<PUObjectAbstractNode*>((*i));
PUDynamicAttributeTranslator dynamicAttributeTranslator;
if (child->cls == token[TOKEN_EMITTER_EMISSION_RATE])
{
// Property: emission_rate
dynamicAttributeTranslator.translate(compiler, *i);
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
_emitter->setDynEmissionRate(dynamicAttribute);
}
else if (child->cls == token[TOKEN_TIME_TO_LIVE])
{
// Property: time_to_live
dynamicAttributeTranslator.translate(compiler, *i);
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
_emitter->setDynTotalTimeToLive(dynamicAttribute);
}
else if (child->cls == token[TOKEN_EMITTER_MASS])
{
// Property: mass
dynamicAttributeTranslator.translate(compiler, *i);
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
_emitter->setDynParticleMass(dynamicAttribute);
}
else if (child->cls == token[TOKEN_VELOCITY])
{
// Property: velocity
dynamicAttributeTranslator.translate(compiler, *i);
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
_emitter->setDynVelocity(dynamicAttribute);
}
else if (child->cls == token[TOKEN_EMITTER_DURATION])
{
// Property: duration
dynamicAttributeTranslator.translate(compiler, *i);
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
_emitter->setDynDuration(dynamicAttribute);
}
else if (child->cls == token[TOKEN_EMITTER_REPEAT_DELAY])
{
// Property: repeat_delay
dynamicAttributeTranslator.translate(compiler, *i);
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
_emitter->setDynRepeatDelay(dynamicAttribute);
}
else if (child->cls == token[TOKEN_ANGLE])
{
// Property: angle
dynamicAttributeTranslator.translate(compiler, *i);
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
_emitter->setDynAngle(dynamicAttribute);
}
else if (child->cls == token[TOKEN_EMITTER_ALL_PARTICLE_DIM])
{
// Property: all_particle_dimensions
dynamicAttributeTranslator.translate(compiler, *i);
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
_emitter->setDynParticleAllDimensions(dynamicAttribute);
}
else if (child->cls == token[TOKEN_EMITTER_PARTICLE_WIDTH])
{
// Property: particle_width
dynamicAttributeTranslator.translate(compiler, *i);
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
_emitter->setDynParticleWidth(dynamicAttribute);
}
else if (child->cls == token[TOKEN_EMITTER_PARTICLE_HEIGHT])
{
// Property: particle_height
dynamicAttributeTranslator.translate(compiler, *i);
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
_emitter->setDynParticleHeight(dynamicAttribute);
}
else if (child->cls == token[TOKEN_EMITTER_PARTICLE_DEPTH])
{
// Property: particle_depth
dynamicAttributeTranslator.translate(compiler, *i);
PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
_emitter->setDynParticleDepth(dynamicAttribute);
}
else if (child->cls == token[TOKEN_CAMERA_DEPENDENCY])
{
//// Property: it can only be a camera_dependency for emission rate
2021-12-25 10:04:45 +08:00
// CameraDependency* cameraDependency = PU_NEW_T(CameraDependency, MEMCATEGORY_SCRIPTING)();
// child->context = Any(cameraDependency);
// CameraDependencyTranslator cameraDependencyTranslator;
// cameraDependencyTranslator.translate(compiler, *i);
// Real threshold = cameraDependency->getThreshold();
// mEmitter->setEmissionRateCameraDependency(threshold * threshold, cameraDependency->isIncrease());
2019-11-23 20:27:39 +08:00
//// Delete the camera dependency
2021-12-25 10:04:45 +08:00
// PU_DELETE_T(cameraDependency, CameraDependency, MEMCATEGORY_SCRIPTING);
2019-11-23 20:27:39 +08:00
}
else if (particleEmitterTranlator->translateChildObject(compiler, *i))
{
// Parsed the object by another translator; do nothing
}
else
{
processNode(compiler, *i);
}
}
else
{
errorUnexpectedToken(compiler, *i);
}
}
}
NS_CC_END