mirror of https://github.com/axmolengine/axmol.git
Sprite3D Reader and tests
This commit is contained in:
parent
8eb201797d
commit
35e3e8d62d
|
@ -824,6 +824,10 @@
|
|||
182C5CB41A95964C00C30D34 /* Node3DReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 182C5CB01A95964700C30D34 /* Node3DReader.cpp */; };
|
||||
182C5CB51A95964F00C30D34 /* Node3DReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 182C5CB11A95964700C30D34 /* Node3DReader.h */; };
|
||||
182C5CB61A95965500C30D34 /* CSParse3DBinary_generated.h in Headers */ = {isa = PBXBuildFile; fileRef = 182C5CAD1A95961600C30D34 /* CSParse3DBinary_generated.h */; };
|
||||
182C5CD61A98F30500C30D34 /* Sprite3DReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 182C5CD41A98F30500C30D34 /* Sprite3DReader.cpp */; };
|
||||
182C5CD71A98F30500C30D34 /* Sprite3DReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 182C5CD41A98F30500C30D34 /* Sprite3DReader.cpp */; };
|
||||
182C5CD81A98F30500C30D34 /* Sprite3DReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 182C5CD51A98F30500C30D34 /* Sprite3DReader.h */; };
|
||||
182C5CD91A98F30500C30D34 /* Sprite3DReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 182C5CD51A98F30500C30D34 /* Sprite3DReader.h */; };
|
||||
1A01C68418F57BE800EFE3A6 /* CCArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A01C67618F57BE800EFE3A6 /* CCArray.cpp */; };
|
||||
1A01C68518F57BE800EFE3A6 /* CCArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A01C67618F57BE800EFE3A6 /* CCArray.cpp */; };
|
||||
1A01C68618F57BE800EFE3A6 /* CCArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A01C67718F57BE800EFE3A6 /* CCArray.h */; };
|
||||
|
@ -2445,6 +2449,8 @@
|
|||
182C5CAD1A95961600C30D34 /* CSParse3DBinary_generated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSParse3DBinary_generated.h; sourceTree = "<group>"; };
|
||||
182C5CB01A95964700C30D34 /* Node3DReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Node3DReader.cpp; path = Node3DReader/Node3DReader.cpp; sourceTree = "<group>"; };
|
||||
182C5CB11A95964700C30D34 /* Node3DReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Node3DReader.h; path = Node3DReader/Node3DReader.h; sourceTree = "<group>"; };
|
||||
182C5CD41A98F30500C30D34 /* Sprite3DReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sprite3DReader.cpp; path = Sprite3DReader/Sprite3DReader.cpp; sourceTree = "<group>"; };
|
||||
182C5CD51A98F30500C30D34 /* Sprite3DReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Sprite3DReader.h; path = Sprite3DReader/Sprite3DReader.h; sourceTree = "<group>"; };
|
||||
1A01C67618F57BE800EFE3A6 /* CCArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCArray.cpp; sourceTree = "<group>"; };
|
||||
1A01C67718F57BE800EFE3A6 /* CCArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCArray.h; sourceTree = "<group>"; };
|
||||
1A01C67818F57BE800EFE3A6 /* CCBool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCBool.h; sourceTree = "<group>"; };
|
||||
|
@ -3789,6 +3795,15 @@
|
|||
name = Node3DReader;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
182C5CD31A98F2F400C30D34 /* Sprite3DReader */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
182C5CD41A98F30500C30D34 /* Sprite3DReader.cpp */,
|
||||
182C5CD51A98F30500C30D34 /* Sprite3DReader.h */,
|
||||
);
|
||||
name = Sprite3DReader;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1A01C67518F57BE800EFE3A6 /* deprecated */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -5632,6 +5647,7 @@
|
|||
50FCEB6818C72017004AD434 /* WidgetReader */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
182C5CD31A98F2F400C30D34 /* Sprite3DReader */,
|
||||
182C5CAF1A95961E00C30D34 /* Node3DReader */,
|
||||
38F5263A1A48363B000DB7F7 /* ArmatureNodeReader */,
|
||||
382384251A2590F9002C4610 /* NodeReader */,
|
||||
|
@ -6461,6 +6477,7 @@
|
|||
15AE187D19AAD33D00C27E9E /* CCBFileLoader.h in Headers */,
|
||||
15AE181219AAD2F700C27E9E /* CCAnimation3D.h in Headers */,
|
||||
B6877A681A8CA8A700643ABF /* CCPUParticle3DAffector.h in Headers */,
|
||||
182C5CD81A98F30500C30D34 /* Sprite3DReader.h in Headers */,
|
||||
1A5702F0180BCE750088DEC7 /* CCTMXLayer.h in Headers */,
|
||||
50ABC01B1926664800A911A9 /* CCSAXParser.h in Headers */,
|
||||
50ABBED51925AB6F00A911A9 /* utlist.h in Headers */,
|
||||
|
@ -7171,6 +7188,7 @@
|
|||
B6877AA91A8CA8A700643ABF /* CCPUParticle3DFlockCenteringAffectorTranslator.h in Headers */,
|
||||
B68779EF1A8CA88500643ABF /* CCPUParticle3DSphereSurfaceEmitter.h in Headers */,
|
||||
5034CA3E191D591100CE6051 /* ccShader_PositionColor.frag in Headers */,
|
||||
182C5CD91A98F30500C30D34 /* Sprite3DReader.h in Headers */,
|
||||
50ABBE301925AB6F00A911A9 /* ccConfig.h in Headers */,
|
||||
15AE195819AAD35100C27E9E /* CCInputDelegate.h in Headers */,
|
||||
50ABBDAC1925AB4100A911A9 /* CCRenderCommandPool.h in Headers */,
|
||||
|
@ -7955,6 +7973,7 @@
|
|||
50ABBE931925AB6F00A911A9 /* CCProfiling.cpp in Sources */,
|
||||
15AE188819AAD33D00C27E9E /* CCControlButtonLoader.cpp in Sources */,
|
||||
15AE18A419AAD33D00C27E9E /* CCScale9SpriteLoader.cpp in Sources */,
|
||||
182C5CD61A98F30500C30D34 /* Sprite3DReader.cpp in Sources */,
|
||||
15AE1B5719AADA9900C27E9E /* UISlider.cpp in Sources */,
|
||||
B6877B161A8CA8A700643ABF /* CCPUParticle3DSineForceAffectorTranslator.cpp in Sources */,
|
||||
1ABA68AE1888D700007D1BB4 /* CCFontCharMap.cpp in Sources */,
|
||||
|
@ -8385,6 +8404,7 @@
|
|||
50ABBE2C1925AB6F00A911A9 /* ccCArray.cpp in Sources */,
|
||||
15AE193219AAD35100C27E9E /* CCActionNode.cpp in Sources */,
|
||||
15AE195319AAD35100C27E9E /* CCDisplayFactory.cpp in Sources */,
|
||||
182C5CD71A98F30500C30D34 /* Sprite3DReader.cpp in Sources */,
|
||||
B687796B1A8CA84900643ABF /* CCPUParticle3DTranslateManager.cpp in Sources */,
|
||||
50ABC0061926664800A911A9 /* CCThread-apple.mm in Sources */,
|
||||
50ABBEB61925AB6F00A911A9 /* CCUserDefault-android.cpp in Sources */,
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
#include "cocostudio/WidgetReader/ListViewReader/ListViewReader.h"
|
||||
#include "cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h"
|
||||
#include "cocostudio/WidgetReader/Node3DReader/Node3DReader.h"
|
||||
#include "cocostudio/WidgetReader/Sprite3DReader/Sprite3DReader.h"
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers/util.h"
|
||||
|
@ -206,6 +207,7 @@ CSLoader::CSLoader()
|
|||
|
||||
CREATE_CLASS_NODE_READER_INFO(ArmatureNodeReader);
|
||||
CREATE_CLASS_NODE_READER_INFO(Node3DReader);
|
||||
CREATE_CLASS_NODE_READER_INFO(Sprite3DReader);
|
||||
}
|
||||
|
||||
void CSLoader::purge()
|
||||
|
|
|
@ -57,8 +57,26 @@ struct ResourceData;
|
|||
namespace flatbuffers {
|
||||
|
||||
struct Node3DOption;
|
||||
struct Sprite3DOptions;
|
||||
struct Particle3DOptions;
|
||||
struct UserCameraOptions;
|
||||
struct Vector2;
|
||||
struct Vector3;
|
||||
|
||||
MANUALLY_ALIGNED_STRUCT(4) Vector2 {
|
||||
private:
|
||||
float x_;
|
||||
float y_;
|
||||
|
||||
public:
|
||||
Vector2(float x, float y)
|
||||
: x_(flatbuffers::EndianScalar(x)), y_(flatbuffers::EndianScalar(y)) { }
|
||||
|
||||
float x() const { return flatbuffers::EndianScalar(x_); }
|
||||
float y() const { return flatbuffers::EndianScalar(y_); }
|
||||
};
|
||||
STRUCT_END(Vector2, 8);
|
||||
|
||||
MANUALLY_ALIGNED_STRUCT(4) Vector3 {
|
||||
private:
|
||||
float x_;
|
||||
|
@ -124,6 +142,130 @@ inline flatbuffers::Offset<Node3DOption> CreateNode3DOption(flatbuffers::FlatBuf
|
|||
return builder_.Finish();
|
||||
}
|
||||
|
||||
struct Sprite3DOptions : private flatbuffers::Table {
|
||||
const Node3DOption *node3DOption() const { return GetPointer<const Node3DOption *>(4); }
|
||||
const flatbuffers::ResourceData *fileData() const { return GetPointer<const flatbuffers::ResourceData *>(6); }
|
||||
uint8_t runAction() const { return GetField<uint8_t>(8, 0); }
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* node3DOption */) &&
|
||||
verifier.VerifyTable(node3DOption()) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 6 /* fileData */) &&
|
||||
verifier.VerifyTable(fileData()) &&
|
||||
VerifyField<uint8_t>(verifier, 8 /* runAction */) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct Sprite3DOptionsBuilder {
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_node3DOption(flatbuffers::Offset<Node3DOption> node3DOption) { fbb_.AddOffset(4, node3DOption); }
|
||||
void add_fileData(flatbuffers::Offset<flatbuffers::ResourceData> fileData) { fbb_.AddOffset(6, fileData); }
|
||||
void add_runAction(uint8_t runAction) { fbb_.AddElement<uint8_t>(8, runAction, 0); }
|
||||
Sprite3DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||
Sprite3DOptionsBuilder &operator=(const Sprite3DOptionsBuilder &);
|
||||
flatbuffers::Offset<Sprite3DOptions> Finish() {
|
||||
auto o = flatbuffers::Offset<Sprite3DOptions>(fbb_.EndTable(start_, 3));
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<Sprite3DOptions> CreateSprite3DOptions(flatbuffers::FlatBufferBuilder &_fbb,
|
||||
flatbuffers::Offset<Node3DOption> node3DOption = 0,
|
||||
flatbuffers::Offset<flatbuffers::ResourceData> fileData = 0,
|
||||
uint8_t runAction = 0) {
|
||||
Sprite3DOptionsBuilder builder_(_fbb);
|
||||
builder_.add_fileData(fileData);
|
||||
builder_.add_node3DOption(node3DOption);
|
||||
builder_.add_runAction(runAction);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
struct Particle3DOptions : private flatbuffers::Table {
|
||||
const Node3DOption *node3DOption() const { return GetPointer<const Node3DOption *>(4); }
|
||||
const flatbuffers::ResourceData *fileData() const { return GetPointer<const flatbuffers::ResourceData *>(6); }
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* node3DOption */) &&
|
||||
verifier.VerifyTable(node3DOption()) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 6 /* fileData */) &&
|
||||
verifier.VerifyTable(fileData()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct Particle3DOptionsBuilder {
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_node3DOption(flatbuffers::Offset<Node3DOption> node3DOption) { fbb_.AddOffset(4, node3DOption); }
|
||||
void add_fileData(flatbuffers::Offset<flatbuffers::ResourceData> fileData) { fbb_.AddOffset(6, fileData); }
|
||||
Particle3DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||
Particle3DOptionsBuilder &operator=(const Particle3DOptionsBuilder &);
|
||||
flatbuffers::Offset<Particle3DOptions> Finish() {
|
||||
auto o = flatbuffers::Offset<Particle3DOptions>(fbb_.EndTable(start_, 2));
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<Particle3DOptions> CreateParticle3DOptions(flatbuffers::FlatBufferBuilder &_fbb,
|
||||
flatbuffers::Offset<Node3DOption> node3DOption = 0,
|
||||
flatbuffers::Offset<flatbuffers::ResourceData> fileData = 0) {
|
||||
Particle3DOptionsBuilder builder_(_fbb);
|
||||
builder_.add_fileData(fileData);
|
||||
builder_.add_node3DOption(node3DOption);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
struct UserCameraOptions : private flatbuffers::Table {
|
||||
const Node3DOption *node3DOption() const { return GetPointer<const Node3DOption *>(4); }
|
||||
float fov() const { return GetField<float>(6, 60); }
|
||||
float near() const { return GetField<float>(8, 1); }
|
||||
float far() const { return GetField<float>(10, 1000); }
|
||||
int32_t cameraFlag() const { return GetField<int32_t>(12, 0); }
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* node3DOption */) &&
|
||||
verifier.VerifyTable(node3DOption()) &&
|
||||
VerifyField<float>(verifier, 6 /* fov */) &&
|
||||
VerifyField<float>(verifier, 8 /* near */) &&
|
||||
VerifyField<float>(verifier, 10 /* far */) &&
|
||||
VerifyField<int32_t>(verifier, 12 /* cameraFlag */) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct UserCameraOptionsBuilder {
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_node3DOption(flatbuffers::Offset<Node3DOption> node3DOption) { fbb_.AddOffset(4, node3DOption); }
|
||||
void add_fov(float fov) { fbb_.AddElement<float>(6, fov, 60); }
|
||||
void add_near(float near) { fbb_.AddElement<float>(8, near, 1); }
|
||||
void add_far(float far) { fbb_.AddElement<float>(10, far, 1000); }
|
||||
void add_cameraFlag(int32_t cameraFlag) { fbb_.AddElement<int32_t>(12, cameraFlag, 0); }
|
||||
UserCameraOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||
UserCameraOptionsBuilder &operator=(const UserCameraOptionsBuilder &);
|
||||
flatbuffers::Offset<UserCameraOptions> Finish() {
|
||||
auto o = flatbuffers::Offset<UserCameraOptions>(fbb_.EndTable(start_, 5));
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<UserCameraOptions> CreateUserCameraOptions(flatbuffers::FlatBufferBuilder &_fbb,
|
||||
flatbuffers::Offset<Node3DOption> node3DOption = 0,
|
||||
float fov = 60,
|
||||
float near = 1,
|
||||
float far = 1000,
|
||||
int32_t cameraFlag = 0) {
|
||||
UserCameraOptionsBuilder builder_(_fbb);
|
||||
builder_.add_cameraFlag(cameraFlag);
|
||||
builder_.add_far(far);
|
||||
builder_.add_near(near);
|
||||
builder_.add_fov(fov);
|
||||
builder_.add_node3DOption(node3DOption);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline const Node3DOption *GetNode3DOption(const void *buf) { return flatbuffers::GetRoot<Node3DOption>(buf); }
|
||||
|
||||
inline bool VerifyNode3DOptionBuffer(flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer<Node3DOption>(); }
|
||||
|
|
|
@ -0,0 +1,236 @@
|
|||
/****************************************************************************
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#include "Sprite3DReader.h"
|
||||
|
||||
#include "cocostudio/CSParseBinary_generated.h"
|
||||
#include "cocostudio/CSParse3DBinary_generated.h"
|
||||
#include "cocostudio/FlatBuffersSerialize.h"
|
||||
#include "cocostudio/WidgetReader/Node3DReader/Node3DReader.h"
|
||||
|
||||
#include "tinyxml2.h"
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace flatbuffers;
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
IMPLEMENT_CLASS_NODE_READER_INFO(Sprite3DReader)
|
||||
|
||||
Sprite3DReader::Sprite3DReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Sprite3DReader::~Sprite3DReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static Sprite3DReader* _instanceSprite3DReader = nullptr;
|
||||
|
||||
Sprite3DReader* Sprite3DReader::getInstance()
|
||||
{
|
||||
if (!_instanceSprite3DReader)
|
||||
{
|
||||
_instanceSprite3DReader = new Sprite3DReader();
|
||||
}
|
||||
|
||||
return _instanceSprite3DReader;
|
||||
}
|
||||
|
||||
void Sprite3DReader::purge()
|
||||
{
|
||||
CC_SAFE_DELETE(_instanceSprite3DReader);
|
||||
}
|
||||
|
||||
Vec2 Sprite3DReader::getVec2Attribute(const tinyxml2::XMLAttribute* attribute) const
|
||||
{
|
||||
if(!attribute)
|
||||
return Vec2::ZERO;
|
||||
|
||||
Vec2 ret(Vec2::ZERO);
|
||||
std::string attriname;
|
||||
|
||||
while (attribute)
|
||||
{
|
||||
attriname = attribute->Name();
|
||||
std::string value = attribute->Value();
|
||||
|
||||
if (attriname == "ValueX")
|
||||
{
|
||||
ret.x = atof(value.c_str());
|
||||
}
|
||||
else if (attriname == "ValueY")
|
||||
{
|
||||
ret.y = atof(value.c_str());
|
||||
}
|
||||
|
||||
attribute = attribute->Next();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Offset<Table> Sprite3DReader::createOptionsWithFlatBuffers(const tinyxml2::XMLElement *objectData,
|
||||
flatbuffers::FlatBufferBuilder *builder)
|
||||
{
|
||||
auto temp = Node3DReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
|
||||
auto node3DOptions = *(Offset<Node3DOption>*)(&temp);
|
||||
|
||||
bool runAction = false;
|
||||
std::string path;
|
||||
int resourceType = 0;
|
||||
|
||||
std::string attriname;
|
||||
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
|
||||
while(attribute)
|
||||
{
|
||||
attriname = attribute->Name();
|
||||
std::string value = attribute->Value();
|
||||
|
||||
if(attriname == "RunAction3D")
|
||||
{
|
||||
runAction = value == "True" ? true : false;
|
||||
break;
|
||||
}
|
||||
|
||||
attribute = attribute->Next();
|
||||
}
|
||||
|
||||
// FileData
|
||||
const tinyxml2::XMLElement* child = objectData->FirstChildElement();
|
||||
while (child)
|
||||
{
|
||||
std::string name = child->Name();
|
||||
|
||||
if (name == "FileData")
|
||||
{
|
||||
attribute = child->FirstAttribute();
|
||||
|
||||
while (attribute)
|
||||
{
|
||||
name = attribute->Name();
|
||||
std::string value = attribute->Value();
|
||||
|
||||
if (name == "Path")
|
||||
{
|
||||
path = value;
|
||||
}
|
||||
else if (name == "Type")
|
||||
{
|
||||
if(value == "Normal")
|
||||
{
|
||||
resourceType = 1;
|
||||
}
|
||||
else if(value == "Default")
|
||||
{
|
||||
resourceType = 0;
|
||||
}
|
||||
}
|
||||
|
||||
attribute = attribute->Next();
|
||||
}
|
||||
}
|
||||
|
||||
child = child->NextSiblingElement();
|
||||
}
|
||||
|
||||
auto options = CreateSprite3DOptions(*builder,
|
||||
node3DOptions,
|
||||
CreateResourceData(*builder,
|
||||
builder->CreateString(path),
|
||||
builder->CreateString(""),
|
||||
resourceType),
|
||||
runAction
|
||||
);
|
||||
|
||||
return *(Offset<Table>*)(&options);
|
||||
}
|
||||
|
||||
void Sprite3DReader::setPropsWithFlatBuffers(cocos2d::Node *node,
|
||||
const flatbuffers::Table* sprite3DOptions)
|
||||
{
|
||||
Sprite3D* sprite3D = static_cast<Sprite3D*>(node);
|
||||
|
||||
auto options = (Sprite3DOptions*)sprite3DOptions;
|
||||
|
||||
bool runAction = options->runAction() != 0;
|
||||
auto fileData = options->fileData();
|
||||
std::string path = fileData->path()->c_str();
|
||||
|
||||
if(runAction && FileUtils::getInstance()->isFileExist(path))
|
||||
{
|
||||
Animation3D* animation = Animation3D::create(path);
|
||||
if(animation)
|
||||
{
|
||||
Animate3D* animate = Animate3D::create(animation);
|
||||
Action* action = RepeatForever::create(animate);
|
||||
sprite3D->runAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
auto nodeOptions = options->node3DOption()->nodeOptions();
|
||||
|
||||
GLubyte alpha = (GLubyte)nodeOptions->color()->a();
|
||||
GLubyte red = (GLubyte)nodeOptions->color()->r();
|
||||
GLubyte green = (GLubyte)nodeOptions->color()->g();
|
||||
GLubyte blue = (GLubyte)nodeOptions->color()->b();
|
||||
|
||||
if (alpha != 255)
|
||||
{
|
||||
sprite3D->setOpacity(alpha);
|
||||
}
|
||||
if (red != 255 || green != 255 || blue != 255)
|
||||
{
|
||||
sprite3D->setColor(Color3B(red, green, blue));
|
||||
}
|
||||
|
||||
auto node3DReader = Node3DReader::getInstance();
|
||||
node3DReader->setPropsWithFlatBuffers(sprite3D, (Table*)(options->node3DOption()));
|
||||
}
|
||||
|
||||
Node* Sprite3DReader::createNodeWithFlatBuffers(const flatbuffers::Table *sprite3DOptions)
|
||||
{
|
||||
auto options = (Sprite3DOptions*)sprite3DOptions;
|
||||
|
||||
auto fileData = options->fileData();
|
||||
std::string path = fileData->path()->c_str();
|
||||
|
||||
Sprite3D* ret = NULL;
|
||||
if(!FileUtils::getInstance()->isFileExist(path))
|
||||
{
|
||||
ret = Sprite3D::create();
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = Sprite3D::create(path);
|
||||
}
|
||||
|
||||
setPropsWithFlatBuffers(ret, sprite3DOptions);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/****************************************************************************
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __cocos2d_libs__Sprite3DReader__
|
||||
#define __cocos2d_libs__Sprite3DReader__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "cocostudio/CocosStudioExport.h"
|
||||
#include "cocostudio/WidgetReader/NodeReaderProtocol.h"
|
||||
#include "cocostudio/WidgetReader/NodeReaderDefine.h"
|
||||
|
||||
namespace tinyxml2
|
||||
{
|
||||
class XMLAttribute;
|
||||
}
|
||||
|
||||
namespace cocostudio
|
||||
{
|
||||
class CC_STUDIO_DLL Sprite3DReader : public cocos2d::Ref, public NodeReaderProtocol
|
||||
{
|
||||
DECLARE_CLASS_NODE_READER_INFO
|
||||
|
||||
public:
|
||||
Sprite3DReader();
|
||||
~Sprite3DReader();
|
||||
|
||||
static Sprite3DReader* getInstance();
|
||||
static void purge();
|
||||
|
||||
flatbuffers::Offset<flatbuffers::Table> createOptionsWithFlatBuffers(const tinyxml2::XMLElement* objectData,
|
||||
flatbuffers::FlatBufferBuilder* builder);
|
||||
void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* sprite3DOptions);
|
||||
cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* sprite3DOptions);
|
||||
|
||||
protected:
|
||||
|
||||
cocos2d::Vec2 getVec2Attribute(const tinyxml2::XMLAttribute* attribute) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__cocos2d_libs__SpriteReader__) */
|
|
@ -38,7 +38,8 @@ static int sceneIdx = -1;
|
|||
|
||||
static std::function<Layer*()> createFunctions[] =
|
||||
{
|
||||
CL(CSNode3DTest)
|
||||
CL(CSNode3DTest),
|
||||
CL(CSSprite3DTest)
|
||||
};
|
||||
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
@ -138,7 +139,7 @@ CSNode3DTest::CSNode3DTest()
|
|||
|
||||
std::string CSNode3DTest::title() const
|
||||
{
|
||||
return "CocosStudio Node3D Test";
|
||||
return "Node3DReader Test";
|
||||
}
|
||||
|
||||
std::string CSNode3DTest::subtitle() const
|
||||
|
@ -146,6 +147,36 @@ std::string CSNode3DTest::subtitle() const
|
|||
return "CCNode in 3D space";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// CSSprite3DTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
CSSprite3DTest::CSSprite3DTest()
|
||||
{
|
||||
auto node = CSLoader::createNode("CocosStudio3DTest/Sprite3D.csb");
|
||||
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
auto sprite3D = node->getChildByTag(8);
|
||||
|
||||
sprite3D->setPosition(size.width / 2, size.height / 2 - 50);
|
||||
sprite3D->setColor(Color3B::WHITE);
|
||||
sprite3D->setOpacity(255);
|
||||
|
||||
addChild(node);
|
||||
}
|
||||
|
||||
std::string CSSprite3DTest::title() const
|
||||
{
|
||||
return "Sprite3DReader Test";
|
||||
}
|
||||
|
||||
std::string CSSprite3DTest::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// CS3DTestScene
|
||||
|
|
|
@ -58,6 +58,16 @@ public:
|
|||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class CSSprite3DTest : public CocosStudio3DTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(CSSprite3DTest);
|
||||
CSSprite3DTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
};
|
||||
|
||||
class CS3DTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
Binary file not shown.
After Width: | Height: | Size: 83 KiB |
Binary file not shown.
After Width: | Height: | Size: 74 KiB |
Binary file not shown.
After Width: | Height: | Size: 70 KiB |
Binary file not shown.
After Width: | Height: | Size: 106 KiB |
|
@ -16,12 +16,39 @@ function CSNode3DTest.create()
|
|||
return layer
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
----CSSprite3DTest
|
||||
----------------------------------------
|
||||
|
||||
local CSSprite3DTest = {}
|
||||
CSSprite3DTest.__index = CSSprite3DTest
|
||||
|
||||
function CSSprite3DTest.create()
|
||||
local layer = cc.Layer:create()
|
||||
Helper.initWithLayer(layer)
|
||||
Helper.titleLabel:setString("Testing Node3D")
|
||||
|
||||
local node = cc.CSLoader:createNode("CocosStudio3DTest/Sprite3D.csb");
|
||||
|
||||
local sprite3D = node:getChildByTag(8);
|
||||
local size = cc.Director:getInstance():getWinSize();
|
||||
|
||||
sprite3D:setPosition(size.width / 2, size.height / 2 - 50);
|
||||
sprite3D:setColor(cc.c3b(255, 255, 255));
|
||||
sprite3D:setOpacity(255);
|
||||
|
||||
layer:addChild(node);
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
function CocosStudio3DTest()
|
||||
local scene = cc.Scene:create()
|
||||
|
||||
Helper.createFunctionTable =
|
||||
{
|
||||
CSNode3DTest.create
|
||||
CSNode3DTest.create,
|
||||
CSSprite3DTest.create
|
||||
}
|
||||
|
||||
scene:addChild(CSNode3DTest.create())
|
||||
|
|
Loading…
Reference in New Issue