mirror of https://github.com/axmolengine/axmol.git
Merge pull request #14047 from liamcindy/v3.9
update for light3d reader
This commit is contained in:
commit
f64105b3dc
|
@ -537,6 +537,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
|
|||
<ClCompile Include="..\editor-support\cocostudio\WidgetReader\GameNode3DReader\GameNode3DReader.cpp" />
|
||||
<ClCompile Include="..\editor-support\cocostudio\WidgetReader\ImageViewReader\ImageViewReader.cpp" />
|
||||
<ClCompile Include="..\editor-support\cocostudio\WidgetReader\LayoutReader\LayoutReader.cpp" />
|
||||
<ClCompile Include="..\editor-support\cocostudio\WidgetReader\Light3DReader\Light3DReader.cpp" />
|
||||
<ClCompile Include="..\editor-support\cocostudio\WidgetReader\ListViewReader\ListViewReader.cpp" />
|
||||
<ClCompile Include="..\editor-support\cocostudio\WidgetReader\LoadingBarReader\LoadingBarReader.cpp" />
|
||||
<ClCompile Include="..\editor-support\cocostudio\WidgetReader\NodeReaderDefine.cpp" />
|
||||
|
@ -1138,6 +1139,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
|
|||
<ClInclude Include="..\editor-support\cocostudio\WidgetReader\GameNode3DReader\GameNode3DReader.h" />
|
||||
<ClInclude Include="..\editor-support\cocostudio\WidgetReader\ImageViewReader\ImageViewReader.h" />
|
||||
<ClInclude Include="..\editor-support\cocostudio\WidgetReader\LayoutReader\LayoutReader.h" />
|
||||
<ClInclude Include="..\editor-support\cocostudio\WidgetReader\Light3DReader\Light3DReader.h" />
|
||||
<ClInclude Include="..\editor-support\cocostudio\WidgetReader\ListViewReader\ListViewReader.h" />
|
||||
<ClInclude Include="..\editor-support\cocostudio\WidgetReader\LoadingBarReader\LoadingBarReader.h" />
|
||||
<ClInclude Include="..\editor-support\cocostudio\WidgetReader\NodeReaderDefine.h" />
|
||||
|
|
|
@ -824,7 +824,7 @@
|
|||
<Filter>3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\3d\CCMotionStreak3D.cpp">
|
||||
<Filter>3d</Filter>
|
||||
<Filter>3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\extensions\assets-manager\AssetsManager.cpp">
|
||||
<Filter>extension\AssetsManager</Filter>
|
||||
|
@ -1934,6 +1934,7 @@
|
|||
<ClCompile Include="..\network\CCDownloader-curl.cpp">
|
||||
<Filter>network</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\editor-support\cocostudio\WidgetReader\Light3DReader\Light3DReader.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\physics\CCPhysicsBody.h">
|
||||
|
@ -2547,7 +2548,7 @@
|
|||
<Filter>3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\3d\CCMotionStreak3D.h">
|
||||
<Filter>3d</Filter>
|
||||
<Filter>3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\3d\cocos3d.h">
|
||||
<Filter>3d</Filter>
|
||||
|
@ -3774,6 +3775,7 @@
|
|||
<ClInclude Include="..\network\CCDownloader-curl.h">
|
||||
<Filter>network\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\editor-support\cocostudio\WidgetReader\Light3DReader\Light3DReader.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\math\Mat4.inl">
|
||||
|
|
|
@ -64,6 +64,7 @@ struct Sprite3DOptions;
|
|||
struct Particle3DOptions;
|
||||
struct UserCameraOptions;
|
||||
struct GameNode3DOption;
|
||||
struct Light3DOption;
|
||||
struct Vector2;
|
||||
struct Vector3;
|
||||
|
||||
|
@ -151,6 +152,7 @@ struct Sprite3DOptions : private flatbuffers::Table {
|
|||
const flatbuffers::ResourceData *fileData() const { return GetPointer<const flatbuffers::ResourceData *>(6); }
|
||||
uint8_t runAction() const { return GetField<uint8_t>(8, 0); }
|
||||
uint8_t isFlipped() const { return GetField<uint8_t>(10, 0); }
|
||||
int32_t lightFlag() const { return GetField<int32_t>(12, 0); }
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* node3DOption */) &&
|
||||
|
@ -159,6 +161,7 @@ struct Sprite3DOptions : private flatbuffers::Table {
|
|||
verifier.VerifyTable(fileData()) &&
|
||||
VerifyField<uint8_t>(verifier, 8 /* runAction */) &&
|
||||
VerifyField<uint8_t>(verifier, 10 /* isFlipped */) &&
|
||||
VerifyField<int32_t>(verifier, 12 /* lightFlag */) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
@ -170,10 +173,11 @@ struct Sprite3DOptionsBuilder {
|
|||
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); }
|
||||
void add_isFlipped(uint8_t isFlipped) { fbb_.AddElement<uint8_t>(10, isFlipped, 0); }
|
||||
void add_lightFlag(int32_t lightFlag) { fbb_.AddElement<int32_t>(12, lightFlag, 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_, 4));
|
||||
auto o = flatbuffers::Offset<Sprite3DOptions>(fbb_.EndTable(start_, 5));
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
@ -182,8 +186,10 @@ inline flatbuffers::Offset<Sprite3DOptions> CreateSprite3DOptions(flatbuffers::F
|
|||
flatbuffers::Offset<Node3DOption> node3DOption = 0,
|
||||
flatbuffers::Offset<flatbuffers::ResourceData> fileData = 0,
|
||||
uint8_t runAction = 0,
|
||||
uint8_t isFlipped = 0) {
|
||||
uint8_t isFlipped = 0,
|
||||
int32_t lightFlag = 0) {
|
||||
Sprite3DOptionsBuilder builder_(_fbb);
|
||||
builder_.add_lightFlag(lightFlag);
|
||||
builder_.add_fileData(fileData);
|
||||
builder_.add_node3DOption(node3DOption);
|
||||
builder_.add_isFlipped(isFlipped);
|
||||
|
@ -328,6 +334,7 @@ struct GameNode3DOption : private flatbuffers::Table {
|
|||
const flatbuffers::ResourceData *backFileData() const { return GetPointer<const flatbuffers::ResourceData *>(20); }
|
||||
const flatbuffers::String *frameEvent() const { return GetPointer<const flatbuffers::String *>(22); }
|
||||
const flatbuffers::String *customProperty() const { return GetPointer<const flatbuffers::String *>(24); }
|
||||
uint8_t useDefaultLight() const { return GetField<uint8_t>(26, 0); }
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* name */) &&
|
||||
|
@ -350,6 +357,7 @@ struct GameNode3DOption : private flatbuffers::Table {
|
|||
verifier.Verify(frameEvent()) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 24 /* customProperty */) &&
|
||||
verifier.Verify(customProperty()) &&
|
||||
VerifyField<uint8_t>(verifier, 26 /* useDefaultLight */) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
@ -368,10 +376,11 @@ struct GameNode3DOptionBuilder {
|
|||
void add_backFileData(flatbuffers::Offset<flatbuffers::ResourceData> backFileData) { fbb_.AddOffset(20, backFileData); }
|
||||
void add_frameEvent(flatbuffers::Offset<flatbuffers::String> frameEvent) { fbb_.AddOffset(22, frameEvent); }
|
||||
void add_customProperty(flatbuffers::Offset<flatbuffers::String> customProperty) { fbb_.AddOffset(24, customProperty); }
|
||||
void add_useDefaultLight(uint8_t useDefaultLight) { fbb_.AddElement<uint8_t>(26, useDefaultLight, 0); }
|
||||
GameNode3DOptionBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||
GameNode3DOptionBuilder &operator=(const GameNode3DOptionBuilder &);
|
||||
flatbuffers::Offset<GameNode3DOption> Finish() {
|
||||
auto o = flatbuffers::Offset<GameNode3DOption>(fbb_.EndTable(start_, 11));
|
||||
auto o = flatbuffers::Offset<GameNode3DOption>(fbb_.EndTable(start_, 12));
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
@ -387,7 +396,8 @@ inline flatbuffers::Offset<GameNode3DOption> CreateGameNode3DOption(flatbuffers:
|
|||
flatbuffers::Offset<flatbuffers::ResourceData> forwardFileData = 0,
|
||||
flatbuffers::Offset<flatbuffers::ResourceData> backFileData = 0,
|
||||
flatbuffers::Offset<flatbuffers::String> frameEvent = 0,
|
||||
flatbuffers::Offset<flatbuffers::String> customProperty = 0) {
|
||||
flatbuffers::Offset<flatbuffers::String> customProperty = 0,
|
||||
uint8_t useDefaultLight = 0) {
|
||||
GameNode3DOptionBuilder builder_(_fbb);
|
||||
builder_.add_customProperty(customProperty);
|
||||
builder_.add_frameEvent(frameEvent);
|
||||
|
@ -399,10 +409,70 @@ inline flatbuffers::Offset<GameNode3DOption> CreateGameNode3DOption(flatbuffers:
|
|||
builder_.add_leftFileData(leftFileData);
|
||||
builder_.add_skyBoxMask(skyBoxMask);
|
||||
builder_.add_name(name);
|
||||
builder_.add_useDefaultLight(useDefaultLight);
|
||||
builder_.add_skyBoxEnabled(skyBoxEnabled);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
struct Light3DOption : private flatbuffers::Table {
|
||||
const Node3DOption *node3DOption() const { return GetPointer<const Node3DOption *>(4); }
|
||||
uint8_t enabled() const { return GetField<uint8_t>(6, 0); }
|
||||
int32_t type() const { return GetField<int32_t>(8, 0); }
|
||||
int32_t flag() const { return GetField<int32_t>(10, 0); }
|
||||
float intensity() const { return GetField<float>(12, 0); }
|
||||
float range() const { return GetField<float>(14, 0); }
|
||||
float outerAngle() const { return GetField<float>(16, 0); }
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* node3DOption */) &&
|
||||
verifier.VerifyTable(node3DOption()) &&
|
||||
VerifyField<uint8_t>(verifier, 6 /* enabled */) &&
|
||||
VerifyField<int32_t>(verifier, 8 /* type */) &&
|
||||
VerifyField<int32_t>(verifier, 10 /* flag */) &&
|
||||
VerifyField<float>(verifier, 12 /* intensity */) &&
|
||||
VerifyField<float>(verifier, 14 /* range */) &&
|
||||
VerifyField<float>(verifier, 16 /* outerAngle */) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct Light3DOptionBuilder {
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_node3DOption(flatbuffers::Offset<Node3DOption> node3DOption) { fbb_.AddOffset(4, node3DOption); }
|
||||
void add_enabled(uint8_t enabled) { fbb_.AddElement<uint8_t>(6, enabled, 0); }
|
||||
void add_type(int32_t type) { fbb_.AddElement<int32_t>(8, type, 0); }
|
||||
void add_flag(int32_t flag) { fbb_.AddElement<int32_t>(10, flag, 0); }
|
||||
void add_intensity(float intensity) { fbb_.AddElement<float>(12, intensity, 0); }
|
||||
void add_range(float range) { fbb_.AddElement<float>(14, range, 0); }
|
||||
void add_outerAngle(float outerAngle) { fbb_.AddElement<float>(16, outerAngle, 0); }
|
||||
Light3DOptionBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||
Light3DOptionBuilder &operator=(const Light3DOptionBuilder &);
|
||||
flatbuffers::Offset<Light3DOption> Finish() {
|
||||
auto o = flatbuffers::Offset<Light3DOption>(fbb_.EndTable(start_, 7));
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<Light3DOption> CreateLight3DOption(flatbuffers::FlatBufferBuilder &_fbb,
|
||||
flatbuffers::Offset<Node3DOption> node3DOption = 0,
|
||||
uint8_t enabled = 0,
|
||||
int32_t type = 0,
|
||||
int32_t flag = 0,
|
||||
float intensity = 0,
|
||||
float range = 0,
|
||||
float outerAngle = 0) {
|
||||
Light3DOptionBuilder builder_(_fbb);
|
||||
builder_.add_outerAngle(outerAngle);
|
||||
builder_.add_range(range);
|
||||
builder_.add_intensity(intensity);
|
||||
builder_.add_flag(flag);
|
||||
builder_.add_type(type);
|
||||
builder_.add_node3DOption(node3DOption);
|
||||
builder_.add_enabled(enabled);
|
||||
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>(); }
|
||||
|
|
|
@ -82,6 +82,7 @@ namespace cocostudio
|
|||
flatbuffers::FlatBufferBuilder *builder)
|
||||
{
|
||||
std::string name = "";
|
||||
bool useDefaultLight = false;
|
||||
int skyBoxMask = 1;
|
||||
bool skyBoxEnabled = false;
|
||||
bool skyBoxValid = true;
|
||||
|
@ -124,6 +125,10 @@ namespace cocostudio
|
|||
{
|
||||
name = value;
|
||||
}
|
||||
else if (attriname == "UseDefaultLight")
|
||||
{
|
||||
useDefaultLight = (value == "True") ? true : false;
|
||||
}
|
||||
else if (attriname == "SkyBoxEnabled")
|
||||
{
|
||||
skyBoxEnabled = (value == "True") ? true : false;
|
||||
|
@ -375,7 +380,8 @@ namespace cocostudio
|
|||
builder->CreateString(backPlistFile),
|
||||
backResourceType),
|
||||
builder->CreateString(frameEvent),
|
||||
builder->CreateString(customProperty)
|
||||
builder->CreateString(customProperty),
|
||||
useDefaultLight
|
||||
);
|
||||
|
||||
return *(Offset<Table>*)(&options);
|
||||
|
@ -420,6 +426,14 @@ namespace cocostudio
|
|||
node->removeComponent(ComExtensionData::COMPONENT_NAME);
|
||||
}
|
||||
node->addComponent(extensionData);
|
||||
|
||||
bool useDefaultLight = options->useDefaultLight();
|
||||
if (useDefaultLight)
|
||||
{
|
||||
AmbientLight* defaultLight = AmbientLight::create(Color3B::WHITE);
|
||||
defaultLight->setIntensity(0.5f);
|
||||
node->addChild(defaultLight);
|
||||
}
|
||||
}
|
||||
|
||||
Node* GameNode3DReader::createNodeWithFlatBuffers(const flatbuffers::Table *node3DOptions)
|
||||
|
|
|
@ -0,0 +1,192 @@
|
|||
/****************************************************************************
|
||||
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 "Light3DReader.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(Light3DReader)
|
||||
|
||||
Light3DReader::Light3DReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Light3DReader::~Light3DReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static Light3DReader* _instanceLight3DReader = nullptr;
|
||||
|
||||
Light3DReader* Light3DReader::getInstance()
|
||||
{
|
||||
if (!_instanceLight3DReader)
|
||||
{
|
||||
_instanceLight3DReader = new Light3DReader();
|
||||
}
|
||||
|
||||
return _instanceLight3DReader;
|
||||
}
|
||||
|
||||
void Light3DReader::purge()
|
||||
{
|
||||
CC_SAFE_DELETE(_instanceLight3DReader);
|
||||
}
|
||||
|
||||
void Light3DReader::destroyInstance()
|
||||
{
|
||||
CC_SAFE_DELETE(_instanceLight3DReader);
|
||||
}
|
||||
|
||||
Offset<Table> Light3DReader::createOptionsWithFlatBuffers(const tinyxml2::XMLElement *objectData,
|
||||
flatbuffers::FlatBufferBuilder *builder)
|
||||
{
|
||||
auto temp = Node3DReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
|
||||
auto node3DOptions = *(Offset<Node3DOption>*)(&temp);
|
||||
|
||||
bool enabled = false;
|
||||
int type = 0;
|
||||
int flag = 0;
|
||||
float intensity = 1.0f;
|
||||
float range = 5.0f;
|
||||
float outerAngle = 30.0f;
|
||||
|
||||
std::string attriname;
|
||||
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
|
||||
while(attribute)
|
||||
{
|
||||
attriname = attribute->Name();
|
||||
std::string value = attribute->Value();
|
||||
|
||||
if (attriname == "Type")
|
||||
{
|
||||
if (value == "DIRECTIONAL") type = (int)LightType::DIRECTIONAL;
|
||||
else if (value == "POINT") type = (int)LightType::POINT;
|
||||
else if (value == "SPOT") type = (int)LightType::SPOT;
|
||||
else if (value == "AMBIENT") type = (int)LightType::AMBIENT;
|
||||
}
|
||||
else if (attriname == "Flag")
|
||||
{
|
||||
if (value == "LIGHT0") flag = (int)LightFlag::LIGHT0;
|
||||
else if (value == "LIGHT1") flag = (int)LightFlag::LIGHT1;
|
||||
else if (value == "LIGHT2") flag = (int)LightFlag::LIGHT2;
|
||||
else if (value == "LIGHT3") flag = (int)LightFlag::LIGHT3;
|
||||
else if (value == "LIGHT4") flag = (int)LightFlag::LIGHT4;
|
||||
else if (value == "LIGHT5") flag = (int)LightFlag::LIGHT5;
|
||||
else if (value == "LIGHT6") flag = (int)LightFlag::LIGHT6;
|
||||
else if (value == "LIGHT7") flag = (int)LightFlag::LIGHT7;
|
||||
else if (value == "LIGHT8") flag = (int)LightFlag::LIGHT8;
|
||||
else if (value == "LIGHT9") flag = (int)LightFlag::LIGHT9;
|
||||
else if (value == "LIGHT10") flag = (int)LightFlag::LIGHT10;
|
||||
else if (value == "LIGHT11") flag = (int)LightFlag::LIGHT11;
|
||||
else if (value == "LIGHT12") flag = (int)LightFlag::LIGHT12;
|
||||
}
|
||||
else if (attriname == "Intensity")
|
||||
{
|
||||
intensity = atof(value.c_str());
|
||||
}
|
||||
else if (attriname == "Range")
|
||||
{
|
||||
range = atof(value.c_str());
|
||||
}
|
||||
else if (attriname == "OuterAngle")
|
||||
{
|
||||
outerAngle = atof(value.c_str());
|
||||
}
|
||||
else if (attriname == "Enable")
|
||||
{
|
||||
enabled = (value == "True") ? true : false;
|
||||
}
|
||||
|
||||
attribute = attribute->Next();
|
||||
}
|
||||
|
||||
auto options = CreateLight3DOption(*builder,node3DOptions,enabled,type,flag,intensity,range,outerAngle);
|
||||
|
||||
return *(Offset<Table>*)(&options);
|
||||
}
|
||||
|
||||
void Light3DReader::setPropsWithFlatBuffers(cocos2d::Node *node,
|
||||
const flatbuffers::Table* light3DOptions)
|
||||
{
|
||||
auto options = (Sprite3DOptions*)light3DOptions;
|
||||
auto node3DReader = Node3DReader::getInstance();
|
||||
node3DReader->setPropsWithFlatBuffers(node, (Table*)(options->node3DOption()));
|
||||
}
|
||||
|
||||
Node* Light3DReader::createNodeWithFlatBuffers(const flatbuffers::Table* light3DOptions)
|
||||
{
|
||||
Node* lightNode = Node::create();
|
||||
|
||||
auto options = (Light3DOption*)light3DOptions;
|
||||
|
||||
BaseLight* light = nullptr;
|
||||
LightType type = (LightType)options->type();
|
||||
LightFlag flag = (LightFlag)options->flag();
|
||||
float intensity = options->intensity();
|
||||
float range = options->range();
|
||||
float outerAngle = options->outerAngle()*0.5f;
|
||||
bool enabled = options->enabled();
|
||||
switch (type)
|
||||
{
|
||||
case cocos2d::LightType::DIRECTIONAL:
|
||||
light = DirectionLight::create(Vec3::UNIT_Z , Color3B::WHITE);
|
||||
break;
|
||||
case cocos2d::LightType::POINT:
|
||||
light = PointLight::create(Vec3::ZERO, Color3B::WHITE, range);
|
||||
break;
|
||||
case cocos2d::LightType::SPOT:
|
||||
light = SpotLight::create(Vec3::UNIT_Z, Vec3::ZERO, Color3B::WHITE, 0, CC_DEGREES_TO_RADIANS(outerAngle), range);
|
||||
break;
|
||||
case cocos2d::LightType::AMBIENT:
|
||||
light = AmbientLight::create(Color3B::WHITE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (light != nullptr)
|
||||
{
|
||||
light->setIntensity(intensity);
|
||||
light->setEnabled(enabled);
|
||||
}
|
||||
lightNode->addChild(light);
|
||||
|
||||
setPropsWithFlatBuffers(lightNode, light3DOptions);
|
||||
|
||||
return lightNode;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/****************************************************************************
|
||||
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 Light3DReader : public cocos2d::Ref, public NodeReaderProtocol
|
||||
{
|
||||
DECLARE_CLASS_NODE_READER_INFO
|
||||
|
||||
public:
|
||||
Light3DReader();
|
||||
~Light3DReader();
|
||||
|
||||
static Light3DReader* getInstance();
|
||||
/** @deprecated Use method destroyInstance() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE static void purge();
|
||||
static void destroyInstance();
|
||||
|
||||
flatbuffers::Offset<flatbuffers::Table> createOptionsWithFlatBuffers(const tinyxml2::XMLElement* objectData,
|
||||
flatbuffers::FlatBufferBuilder* builder);
|
||||
void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* light3DOptions);
|
||||
cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* light3DOptions);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* defined(__cocos2d_libs__Sprite3DReader__) */
|
|
@ -110,6 +110,7 @@ namespace cocostudio
|
|||
std::string path;
|
||||
int resourceType = 0;
|
||||
bool isFlipped = false;
|
||||
int lightFlag = 0;
|
||||
|
||||
std::string attriname;
|
||||
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
|
||||
|
@ -126,6 +127,22 @@ namespace cocostudio
|
|||
{
|
||||
isFlipped = value == "True" ? true : false;
|
||||
}
|
||||
else if (attriname == "LightFlag")
|
||||
{
|
||||
if (value == "LIGHT0") lightFlag = (int)LightFlag::LIGHT0;
|
||||
else if (value == "LIGHT1") lightFlag = (int)LightFlag::LIGHT1;
|
||||
else if (value == "LIGHT2") lightFlag = (int)LightFlag::LIGHT2;
|
||||
else if (value == "LIGHT3") lightFlag = (int)LightFlag::LIGHT3;
|
||||
else if (value == "LIGHT4") lightFlag = (int)LightFlag::LIGHT4;
|
||||
else if (value == "LIGHT5") lightFlag = (int)LightFlag::LIGHT5;
|
||||
else if (value == "LIGHT6") lightFlag = (int)LightFlag::LIGHT6;
|
||||
else if (value == "LIGHT7") lightFlag = (int)LightFlag::LIGHT7;
|
||||
else if (value == "LIGHT8") lightFlag = (int)LightFlag::LIGHT8;
|
||||
else if (value == "LIGHT9") lightFlag = (int)LightFlag::LIGHT9;
|
||||
else if (value == "LIGHT10") lightFlag = (int)LightFlag::LIGHT10;
|
||||
else if (value == "LIGHT11") lightFlag = (int)LightFlag::LIGHT11;
|
||||
else if (value == "LIGHT12") lightFlag = (int)LightFlag::LIGHT12;
|
||||
}
|
||||
|
||||
attribute = attribute->Next();
|
||||
}
|
||||
|
@ -175,7 +192,8 @@ namespace cocostudio
|
|||
builder->CreateString(""),
|
||||
resourceType),
|
||||
runAction,
|
||||
isFlipped
|
||||
isFlipped,
|
||||
lightFlag
|
||||
);
|
||||
|
||||
return *(Offset<Table>*)(&options);
|
||||
|
@ -188,6 +206,7 @@ namespace cocostudio
|
|||
|
||||
auto options = (Sprite3DOptions*)sprite3DOptions;
|
||||
|
||||
int lightFlag = options->lightFlag();
|
||||
bool runAction = options->runAction() != 0;
|
||||
bool isFlipped = options->isFlipped() != 0;
|
||||
auto fileData = options->fileData();
|
||||
|
@ -224,6 +243,12 @@ namespace cocostudio
|
|||
sprite3D->setCullFaceEnabled(true);
|
||||
sprite3D->setCullFace(GL_FRONT);
|
||||
}
|
||||
|
||||
if (lightFlag <= 0)
|
||||
{
|
||||
lightFlag = 1;
|
||||
}
|
||||
sprite3D->setLightMask(lightFlag);
|
||||
|
||||
auto node3DReader = Node3DReader::getInstance();
|
||||
node3DReader->setPropsWithFlatBuffers(sprite3D, (Table*)(options->node3DOption()));
|
||||
|
|
|
@ -43,6 +43,7 @@ CocosStudio3DTests::CocosStudio3DTests()
|
|||
ADD_TEST_CASE(CSUserCameraTest);
|
||||
ADD_TEST_CASE(CSParticle3DTest);
|
||||
ADD_TEST_CASE(CSSceneSkyBoxTest);
|
||||
ADD_TEST_CASE(CSSceneLight3DTest);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
@ -192,4 +193,20 @@ void CSSceneSkyBoxTest::onTouchesMoved(const std::vector<Touch*>& touches, cocos
|
|||
_camera->setPosition3D(Vec3(50.0f * sinf(_angle), 0.0f, 50.0f * cosf(_angle)));
|
||||
_camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f));
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// CSSceneLight3DTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
CSSceneLight3DTest::CSSceneLight3DTest()
|
||||
{
|
||||
auto node = CSLoader::createNode("Light3D.csb");
|
||||
addChild(node);
|
||||
}
|
||||
|
||||
std::string CSSceneLight3DTest::title() const
|
||||
{
|
||||
return "Light3DReader Test";
|
||||
}
|
|
@ -84,5 +84,13 @@ public:
|
|||
void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *event);
|
||||
};
|
||||
|
||||
class CSSceneLight3DTest : public CocosStudio3DTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(CSSceneLight3DTest);
|
||||
CSSceneLight3DTest();
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit a7652d6db915e4f7eb2543df8ad1c65c3f73ee03
|
||||
Subproject commit 0f78db5bbf9746f4c0943aae7ffb394653a87874
|
Loading…
Reference in New Issue