2015-02-26 09:19:14 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2014 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-03-16 14:02:08 +08:00
|
|
|
#include "platform/CCFileUtils.h"
|
2020-08-03 17:51:40 +08:00
|
|
|
#include "cocostudio/WidgetReader/Particle3DReader/Particle3DReader.h"
|
2015-02-26 09:19:14 +08:00
|
|
|
|
2020-08-03 17:51:40 +08:00
|
|
|
#include "cocostudio/CSParseBinary_generated.h"
|
|
|
|
#include "cocostudio/CSParse3DBinary_generated.h"
|
|
|
|
#include "cocostudio/FlatBuffersSerialize.h"
|
|
|
|
#include "cocostudio/WidgetReader/Node3DReader/Node3DReader.h"
|
2015-02-26 09:19:14 +08:00
|
|
|
|
|
|
|
#include "flatbuffers/flatbuffers.h"
|
|
|
|
|
2015-03-05 13:24:06 +08:00
|
|
|
#include "Particle3D/PU/CCPUParticleSystem3D.h"
|
2015-02-26 09:19:14 +08:00
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
using namespace flatbuffers;
|
|
|
|
|
|
|
|
namespace cocostudio
|
|
|
|
{
|
|
|
|
IMPLEMENT_CLASS_NODE_READER_INFO(Particle3DReader)
|
|
|
|
|
|
|
|
Particle3DReader::Particle3DReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Particle3DReader::~Particle3DReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static Particle3DReader* _instanceParticle3DReader = nullptr;
|
|
|
|
|
|
|
|
Particle3DReader* Particle3DReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!_instanceParticle3DReader)
|
|
|
|
{
|
2015-12-16 14:02:55 +08:00
|
|
|
_instanceParticle3DReader = new (std::nothrow) Particle3DReader();
|
2015-02-26 09:19:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return _instanceParticle3DReader;
|
|
|
|
}
|
|
|
|
|
2015-03-31 14:56:24 +08:00
|
|
|
void Particle3DReader::purge()
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(_instanceParticle3DReader);
|
|
|
|
}
|
|
|
|
|
2015-03-30 16:46:33 +08:00
|
|
|
void Particle3DReader::destroyInstance()
|
2015-02-26 09:19:14 +08:00
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(_instanceParticle3DReader);
|
|
|
|
}
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
Offset<Table> Particle3DReader::createOptionsWithFlatBuffers(pugi::xml_node objectData,
|
2015-02-26 09:19:14 +08:00
|
|
|
flatbuffers::FlatBufferBuilder *builder)
|
|
|
|
{
|
|
|
|
auto temp = Node3DReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
|
|
|
|
auto node3DOptions = *(Offset<Node3DOption>*)(&temp);
|
|
|
|
|
|
|
|
std::string path;
|
|
|
|
int resourceType = 0;
|
|
|
|
|
|
|
|
// FileData
|
2019-11-24 23:15:56 +08:00
|
|
|
auto child = objectData.first_child();
|
2015-02-26 09:19:14 +08:00
|
|
|
while (child)
|
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
std::string name = child.name();
|
2015-02-26 09:19:14 +08:00
|
|
|
|
|
|
|
if (name == "FileData")
|
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
auto attribute = child.first_attribute();
|
2015-02-26 09:19:14 +08:00
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
name = attribute.name();
|
|
|
|
std::string value = attribute.value();
|
2015-02-26 09:19:14 +08:00
|
|
|
|
|
|
|
if (name == "Path")
|
|
|
|
{
|
|
|
|
path = value;
|
|
|
|
}
|
|
|
|
else if (name == "Type")
|
|
|
|
{
|
|
|
|
if(value == "Normal")
|
|
|
|
{
|
|
|
|
resourceType = 1;
|
|
|
|
}
|
|
|
|
else if(value == "Default")
|
|
|
|
{
|
|
|
|
resourceType = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
attribute = attribute.next_attribute();
|
2015-02-26 09:19:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
child = child.next_sibling();
|
2015-02-26 09:19:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
auto options = CreateParticle3DOptions(*builder,
|
|
|
|
node3DOptions,
|
|
|
|
CreateResourceData(*builder,
|
|
|
|
builder->CreateString(path),
|
|
|
|
builder->CreateString(""),
|
|
|
|
resourceType)
|
|
|
|
);
|
|
|
|
|
|
|
|
return *(Offset<Table>*)(&options);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Particle3DReader::setPropsWithFlatBuffers(cocos2d::Node *node,
|
|
|
|
const flatbuffers::Table* particle3DOptions)
|
|
|
|
{
|
|
|
|
auto options = (Particle3DOptions*)particle3DOptions;
|
|
|
|
|
|
|
|
auto node3DReader = Node3DReader::getInstance();
|
|
|
|
node3DReader->setPropsWithFlatBuffers(node, (Table*)(options->node3DOption()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* Particle3DReader::createNodeWithFlatBuffers(const flatbuffers::Table *particle3DOptions)
|
|
|
|
{
|
|
|
|
auto options = (Particle3DOptions*)particle3DOptions;
|
|
|
|
|
|
|
|
auto fileData = options->fileData();
|
|
|
|
std::string path = fileData->path()->c_str();
|
|
|
|
|
2015-08-06 15:13:54 +08:00
|
|
|
PUParticleSystem3D* ret = PUParticleSystem3D::create();
|
|
|
|
if (FileUtils::getInstance()->isFileExist(path))
|
2015-02-26 09:19:14 +08:00
|
|
|
{
|
2015-08-06 15:13:54 +08:00
|
|
|
ret->initWithFilePath(path);
|
2015-02-26 09:19:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
setPropsWithFlatBuffers(ret, particle3DOptions);
|
|
|
|
|
|
|
|
if(ret)
|
|
|
|
{
|
|
|
|
ret->startParticleSystem();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|