2015-02-11 18:14:22 +08:00
|
|
|
/****************************************************************************
|
2015-03-02 16:05:26 +08:00
|
|
|
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
2018-01-29 16:25:32 +08:00
|
|
|
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-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-02-11 18:14:22 +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
|
|
|
|
2015-02-11 18:14:22 +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
|
|
|
|
2015-02-11 18:14:22 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-03-05 13:24:06 +08:00
|
|
|
#include "CCPUAffectorTranslator.h"
|
|
|
|
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
|
|
|
#include "extensions/Particle3D/PU/CCPUAffectorManager.h"
|
2015-02-11 18:14:22 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2015-02-11 18:14:22 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
PUAffectorTranslator::PUAffectorTranslator() : _affector(nullptr) {}
|
2015-02-11 18:14:22 +08:00
|
|
|
//-------------------------------------------------------------------------
|
2021-12-25 10:04:45 +08:00
|
|
|
void PUAffectorTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode* node)
|
2015-02-11 18:14:22 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node);
|
2015-02-11 18:14:22 +08:00
|
|
|
PUObjectAbstractNode* parent = obj->parent ? reinterpret_cast<PUObjectAbstractNode*>(obj->parent) : 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-02-11 18:14:22 +08:00
|
|
|
// The name of the obj is the type of the affector
|
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
|
2015-02-11 18:14:22 +08:00
|
|
|
std::string type;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!obj->name.empty())
|
2015-02-11 18:14:22 +08:00
|
|
|
{
|
|
|
|
type = obj->name;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-02-11 18:14:22 +08:00
|
|
|
//// Get the factory
|
2021-12-25 10:04:45 +08:00
|
|
|
// ParticleAffectorFactory* particleAffectorFactory =
|
|
|
|
// ParticleSystemManager::getSingletonPtr()->getAffectorFactory(type); if (!particleAffectorFactory)
|
2015-02-11 18:14:22 +08:00
|
|
|
//{
|
2021-12-25 10:04:45 +08:00
|
|
|
// compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
PUScriptTranslator* particleAffectorTranlator = PUAffectorManager::Instance()->getTranslator(type);
|
|
|
|
if (!particleAffectorTranlator)
|
|
|
|
return;
|
2015-02-11 18:14:22 +08:00
|
|
|
//// Create the affector
|
2021-12-25 10:04:45 +08:00
|
|
|
// mAffector = ParticleSystemManager::getSingletonPtr()->createAffector(type);
|
|
|
|
// if (!mAffector)
|
2015-02-11 18:14:22 +08:00
|
|
|
//{
|
2021-12-25 10:04:45 +08:00
|
|
|
// compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
|
|
|
|
// return;
|
|
|
|
// }
|
2015-03-05 13:24:06 +08:00
|
|
|
_affector = PUAffectorManager::Instance()->createAffector(type);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!_affector)
|
|
|
|
return;
|
2015-03-02 13:07:32 +08:00
|
|
|
_affector->setAffectorType(type);
|
|
|
|
|
2015-02-11 18:14:22 +08:00
|
|
|
if (parent && parent->context)
|
|
|
|
{
|
|
|
|
PUParticleSystem3D* system = static_cast<PUParticleSystem3D*>(parent->context);
|
|
|
|
system->addAffector(_affector);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-02-11 18:14:22 +08:00
|
|
|
// The first value is the (optional) name
|
|
|
|
std::string name;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!obj->values.empty())
|
2015-02-11 18:14:22 +08:00
|
|
|
{
|
|
|
|
getString(*obj->values.front(), &name);
|
|
|
|
_affector->setName(name);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-02-11 18:14:22 +08:00
|
|
|
// Set it in the context
|
|
|
|
obj->context = _affector;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-02-11 18:14:22 +08:00
|
|
|
// Run through properties
|
2021-12-25 10:04:45 +08:00
|
|
|
for (PUAbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
|
2015-02-11 18:14:22 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if ((*i)->type == ANT_PROPERTY)
|
2015-02-11 18:14:22 +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))
|
2015-02-11 18:14:22 +08:00
|
|
|
{
|
|
|
|
_affector->setEnabled(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (prop->name == token[TOKEN_POSITION])
|
|
|
|
{
|
2015-12-11 23:37:58 +08:00
|
|
|
// Property: position
|
2015-02-11 18:14:22 +08:00
|
|
|
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))
|
2015-02-11 18:14:22 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
// mAffector->position = val;
|
|
|
|
// mAffector->originalPosition = val;
|
2015-02-11 18:14:22 +08:00
|
|
|
_affector->setLocalPosition(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (prop->name == token[TOKEN_AFFECTOR_MASS])
|
|
|
|
{
|
|
|
|
if (passValidateProperty(compiler, prop, token[TOKEN_AFFECTOR_MASS], VAL_REAL))
|
|
|
|
{
|
|
|
|
float val = 0.0f;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (getFloat(*prop->values.front(), &val))
|
2015-02-11 18:14:22 +08:00
|
|
|
{
|
|
|
|
_affector->setMass(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (prop->name == token[TOKEN_AFFECTOR_SPECIALISATION])
|
|
|
|
{
|
|
|
|
if (passValidateProperty(compiler, prop, token[TOKEN_AFFECTOR_SPECIALISATION], VAL_STRING))
|
|
|
|
{
|
|
|
|
std::string val;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (getString(*prop->values.front(), &val))
|
2015-02-11 18:14:22 +08:00
|
|
|
{
|
|
|
|
if (val == token[TOKEN_AFFECTOR_SPEC_DEFAULT])
|
|
|
|
{
|
2015-03-05 13:24:06 +08:00
|
|
|
_affector->setAffectSpecialisation(PUAffector::AFSP_DEFAULT);
|
2015-02-11 18:14:22 +08:00
|
|
|
}
|
|
|
|
else if (val == token[TOKEN_AFFECTOR_SPEC_TTL_INCREASE])
|
|
|
|
{
|
2015-03-05 13:24:06 +08:00
|
|
|
_affector->setAffectSpecialisation(PUAffector::AFSP_TTL_INCREASE);
|
2015-02-11 18:14:22 +08:00
|
|
|
}
|
|
|
|
else if (val == token[TOKEN_AFFECTOR_SPEC_TTL_DECREASE])
|
|
|
|
{
|
2015-03-05 13:24:06 +08:00
|
|
|
_affector->setAffectSpecialisation(PUAffector::AFSP_TTL_DECREASE);
|
2015-02-11 18:14:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (prop->name == token[TOKEN_AFFECTOR_EXCLUDE_EMITTER])
|
|
|
|
{
|
2015-03-02 13:07:32 +08:00
|
|
|
if (passValidatePropertyNoValues(compiler, prop, token[TOKEN_AFFECTOR_EXCLUDE_EMITTER]))
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
for (PUAbstractNodeList::iterator j = prop->values.begin(); j != prop->values.end(); ++j)
|
2015-03-02 13:07:32 +08:00
|
|
|
{
|
|
|
|
std::string val;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (getString(**j, &val))
|
2015-03-02 13:07:32 +08:00
|
|
|
{
|
|
|
|
_affector->addEmitterToExclude(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-11 18:14:22 +08:00
|
|
|
}
|
|
|
|
else if (particleAffectorTranlator->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)
|
2015-02-11 18:14:22 +08:00
|
|
|
{
|
|
|
|
if (particleAffectorTranlator->translateChildObject(compiler, *i))
|
|
|
|
{
|
|
|
|
// Parsed the object by another translator; do nothing
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
processNode(compiler, *i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
errorUnexpectedToken(compiler, *i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|