6e8fbca745
match the genesis editor version 1.3.0.653.
257 lines
8.6 KiB
C++
257 lines
8.6 KiB
C++
/****************************************************************************
|
||
Copyright (c) 2011-2013,WebJet Business Division,CYOU
|
||
|
||
http://www.genesis-3d.com.cn
|
||
|
||
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 "stdneb.h"
|
||
#include "graphicfeature/components/meshrendercomponent.h"
|
||
|
||
|
||
namespace App
|
||
{
|
||
class MeshRenderComponentSerialization
|
||
{
|
||
public:
|
||
MeshRenderComponentSerialization( MeshRenderComponent* pComponent )
|
||
:mObject(pComponent)
|
||
{
|
||
|
||
}
|
||
inline void Load( Version ver, AppReader* pReader, const Serialization::SerializationArgs* args )
|
||
{
|
||
if ( 1 == ver )
|
||
{
|
||
Load_1(pReader);
|
||
return;
|
||
}
|
||
if ( 2 == ver )
|
||
{
|
||
Load_2(pReader, args);
|
||
return;
|
||
}
|
||
if ( 3 == ver )
|
||
{
|
||
Load_3(pReader, args);
|
||
return;
|
||
}
|
||
if (4 == ver )
|
||
{
|
||
Load_4(pReader, args);
|
||
return;
|
||
}
|
||
if (5 == ver )
|
||
{
|
||
Load_5(pReader, args);
|
||
return;
|
||
}
|
||
n_error(" MeshRenderComponentSerialization::Load unknonw version " );
|
||
}
|
||
|
||
void Load_1( AppReader* pReader );
|
||
void Load_2( AppReader* pReader, const Serialization::SerializationArgs* args );
|
||
void Load_3( AppReader* pReader, const Serialization::SerializationArgs* args );
|
||
void Load_4( AppReader* pReader, const Serialization::SerializationArgs* args );
|
||
void Load_5( AppReader* pReader, const Serialization::SerializationArgs* args );
|
||
void Save( AppWriter* pWriter );
|
||
protected:
|
||
MeshRenderComponent* mObject;
|
||
|
||
};
|
||
|
||
const char* s_MeshResID = "Mesh";
|
||
const char* s_MeshLoadingPriority = "LoadingPriority";
|
||
const Util::String s_MeshDummyID = "EmptyNull";
|
||
const char* s_LMID = "LightmapID";
|
||
const char* s_LMTexParam = "LightmapST";
|
||
const char* s_LMScale = "LightmapScale";
|
||
const char* s_LightmapMode = "LightmapMode";
|
||
|
||
//------------------------------------------------------------------------
|
||
void MeshRenderComponentSerialization::Load_1(AppReader* pSerialize)
|
||
{
|
||
/*
|
||
// shader count
|
||
SizeT count = 0;
|
||
pSerialize->SerializeInt(s_ShaderCount, count);
|
||
|
||
for ( IndexT iShader = 0; iShader < count; ++iShader )
|
||
{
|
||
Util::String ShaderID;
|
||
pSerialize->SerializeString(s_ShaderID, ShaderID);
|
||
n_assert( ShaderID.IsValid() );
|
||
mObject->SetShaderID(iShader,ShaderID );
|
||
|
||
SizeT texCount = 0;
|
||
pSerialize->SerializeInt(s_TextureCount, texCount );
|
||
for ( IndexT iTex = 0; iTex < texCount; ++iTex )
|
||
{
|
||
Util::String paramName;
|
||
Util::String texID;
|
||
pSerialize->SerializeString(s_TextureParamName, paramName);
|
||
pSerialize->SerializeString(s_TextureID, texID );
|
||
n_assert(paramName.IsValid());
|
||
n_assert(texID.IsValid());
|
||
mObject->_AddTextureParam(iShader,paramName,texID);
|
||
}
|
||
}
|
||
*/
|
||
}
|
||
|
||
//------------------------------------------------------------------------
|
||
void MeshRenderComponentSerialization::Load_2(AppReader* pSerialize, const Serialization::SerializationArgs* args)
|
||
{
|
||
const ComponentSerializationArgs* cargs = args->cast_fast<ComponentSerializationArgs>();
|
||
|
||
Resources::Priority priority;
|
||
pSerialize->SerializeInt(s_MeshLoadingPriority, priority);//<2F>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѷ<EFBFBD><D1B7><EFBFBD><EFBFBD><EFBFBD>
|
||
|
||
priority = (Resources::ResourcePriority::Undefinition == cargs->getPriority()) ? Resources::ResourcePriority::MeshDefault : cargs->getPriority();
|
||
Util::String meshName;
|
||
pSerialize->SerializeString(s_MeshResID, meshName );
|
||
if ( meshName != s_MeshDummyID )
|
||
{
|
||
mObject->SetMeshID( meshName, priority );
|
||
}
|
||
}
|
||
//------------------------------------------------------------------------
|
||
void MeshRenderComponentSerialization::Load_3(AppReader* pSerialize, const Serialization::SerializationArgs* args)
|
||
{
|
||
const ComponentSerializationArgs* cargs = args->cast_fast<ComponentSerializationArgs>();
|
||
|
||
Resources::Priority priority;
|
||
pSerialize->SerializeInt(s_MeshLoadingPriority, priority);//<2F>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѷ<EFBFBD><D1B7><EFBFBD><EFBFBD><EFBFBD>
|
||
|
||
priority = (Resources::ResourcePriority::Undefinition == cargs->getPriority()) ? Resources::ResourcePriority::MeshDefault : cargs->getPriority();
|
||
Util::String meshName;
|
||
pSerialize->SerializeString(s_MeshResID, meshName );
|
||
if ( meshName != s_MeshDummyID )
|
||
{
|
||
mObject->SetMeshID( meshName, priority );
|
||
}
|
||
|
||
unsigned int lmID = 0xFFFF;
|
||
Math::float4 lmTexParam(1.0f,1.0f,0.0f,0.0f);
|
||
|
||
pSerialize->SerializeUInt(s_LMID, lmID);
|
||
mObject->SetLMIndex(lmID);
|
||
|
||
pSerialize->SerializeFloat4(s_LMTexParam, lmTexParam);
|
||
mObject->SetLMTexParam( lmTexParam );
|
||
}
|
||
//------------------------------------------------------------------------
|
||
void MeshRenderComponentSerialization::Load_4(AppReader* pSerialize, const Serialization::SerializationArgs* args)
|
||
{
|
||
const ComponentSerializationArgs* cargs = args->cast_fast<ComponentSerializationArgs>();
|
||
|
||
Resources::Priority priority;
|
||
pSerialize->SerializeInt(s_MeshLoadingPriority, priority);//<2F>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѷ<EFBFBD><D1B7><EFBFBD><EFBFBD><EFBFBD>
|
||
|
||
priority = (Resources::ResourcePriority::Undefinition == cargs->getPriority()) ? Resources::ResourcePriority::MeshDefault : cargs->getPriority();
|
||
Util::String meshName;
|
||
pSerialize->SerializeString(s_MeshResID, meshName );
|
||
if ( meshName != s_MeshDummyID )
|
||
{
|
||
mObject->SetMeshID( meshName, priority );
|
||
}
|
||
|
||
unsigned int lmID = 0xFFFF;
|
||
Math::float4 lmTexParam(1.0f,1.0f,0.0f,0.0f);
|
||
|
||
pSerialize->SerializeUInt(s_LMID, lmID);
|
||
mObject->SetLMIndex(lmID);
|
||
|
||
pSerialize->SerializeFloat4(s_LMTexParam, lmTexParam);
|
||
mObject->SetLMTexParam( lmTexParam );
|
||
|
||
double lmScale = 1.0f;
|
||
pSerialize->SerializeDouble( s_LMScale, lmScale );
|
||
mObject->SetLMScale( lmScale );
|
||
}
|
||
//------------------------------------------------------------------------
|
||
void MeshRenderComponentSerialization::Load_5( AppReader* pReader, const Serialization::SerializationArgs* args )
|
||
{
|
||
Load_4(pReader, args);
|
||
uint lmMode = SingleMode;
|
||
|
||
pReader->SerializeUInt(s_LightmapMode, lmMode);
|
||
mObject->SetLightmapMode((LMMode)lmMode);
|
||
}
|
||
//------------------------------------------------------------------------
|
||
|
||
void MeshRenderComponentSerialization::Save(AppWriter* pSerialize)
|
||
{
|
||
if (mObject->GetMeshID().IsValid())
|
||
{
|
||
pSerialize->SerializeInt(s_MeshLoadingPriority, mObject->GetPriority());
|
||
pSerialize->SerializeString(s_MeshResID, mObject->GetMeshID().AsString() );
|
||
}
|
||
else
|
||
{
|
||
// can not Serialize empty string
|
||
pSerialize->SerializeInt(s_MeshLoadingPriority, 0);
|
||
pSerialize->SerializeString(s_MeshResID, Util::String(s_MeshDummyID) );
|
||
}
|
||
|
||
unsigned int lmID = mObject->GetLMIndex();
|
||
Math::float4 lmST = mObject->GetLMTexParam();
|
||
double lmScale = mObject->GetLMScale();
|
||
|
||
pSerialize->SerializeUInt(s_LMID, lmID);
|
||
pSerialize->SerializeFloat4(s_LMTexParam, lmST);
|
||
pSerialize->SerializeDouble(s_LMScale, lmScale);
|
||
pSerialize->SerializeUInt(s_LightmapMode, (uint)mObject->GetLightmapMode() );
|
||
}
|
||
|
||
}
|
||
|
||
namespace App
|
||
{
|
||
//------------------------------------------------------------------------
|
||
// @ISerialization::GetVersion. when change storage, must add SerializeVersion count
|
||
Version MeshRenderComponent::GetVersion() const
|
||
{
|
||
//return 2; // <09><>ǰ<EFBFBD>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD>2
|
||
//return 3; // <09><>ǰ<EFBFBD>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD>3,<2C><><EFBFBD><EFBFBD>lightmap<61><70>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
|
||
//return 4; //<2F><>ǰ<EFBFBD>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD>4
|
||
return 5; // <20><><EFBFBD><EFBFBD>lightmapMode<64>Ŀ<EFBFBD><C4BF><EFBFBD>
|
||
}
|
||
|
||
//------------------------------------------------------------------------
|
||
// @ISerialization::Load
|
||
void MeshRenderComponent::Load( Version ver, AppReader* pReader, const Serialization::SerializationArgs* args )
|
||
{
|
||
pReader->SerializeSuper<Super>(this, args);
|
||
MeshRenderComponentSerialization Serialize(this);
|
||
Serialize.Load( ver, pReader, args );
|
||
}
|
||
|
||
//------------------------------------------------------------------------
|
||
// @ISerialization::Save
|
||
void MeshRenderComponent::Save( AppWriter* pWriter ) const
|
||
{
|
||
pWriter->SerializeSuper<Super>(this);
|
||
MeshRenderComponentSerialization Serialize(const_cast<MeshRenderComponent*>(this));
|
||
Serialize.Save( pWriter );
|
||
}
|
||
|
||
}
|
||
|