Refactor: Apply editor config rules to tools

pull/592/head
Richard 2015-06-29 20:54:59 -06:00
parent 83defdddc4
commit 5ae1c28881
28 changed files with 11947 additions and 11947 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,169 +1,169 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
using namespace AssimpView;
// ------------------------------------------------------------------------------------------------
// Constructor on a given animation.
AnimEvaluator::AnimEvaluator( const aiAnimation* pAnim)
{
mAnim = pAnim;
mLastTime = 0.0;
mLastPositions.resize( pAnim->mNumChannels, boost::make_tuple( 0, 0, 0));
}
// ------------------------------------------------------------------------------------------------
// Evaluates the animation tracks for a given time stamp.
void AnimEvaluator::Evaluate( double pTime)
{
// extract ticks per second. Assume default value if not given
double ticksPerSecond = mAnim->mTicksPerSecond != 0.0 ? mAnim->mTicksPerSecond : 25.0;
// every following time calculation happens in ticks
pTime *= ticksPerSecond;
// map into anim's duration
double time = 0.0f;
if( mAnim->mDuration > 0.0)
time = fmod( pTime, mAnim->mDuration);
if( mTransforms.size() != mAnim->mNumChannels)
mTransforms.resize( mAnim->mNumChannels);
// calculate the transformations for each animation channel
for( unsigned int a = 0; a < mAnim->mNumChannels; a++)
{
const aiNodeAnim* channel = mAnim->mChannels[a];
// ******** Position *****
aiVector3D presentPosition( 0, 0, 0);
if( channel->mNumPositionKeys > 0)
{
// Look for present frame number. Search from last position if time is after the last time, else from beginning
// Should be much quicker than always looking from start for the average use case.
unsigned int frame = (time >= mLastTime) ? mLastPositions[a].get<0>() : 0;
while( frame < channel->mNumPositionKeys - 1)
{
if( time < channel->mPositionKeys[frame+1].mTime)
break;
frame++;
}
// interpolate between this frame's value and next frame's value
unsigned int nextFrame = (frame + 1) % channel->mNumPositionKeys;
const aiVectorKey& key = channel->mPositionKeys[frame];
const aiVectorKey& nextKey = channel->mPositionKeys[nextFrame];
double diffTime = nextKey.mTime - key.mTime;
if( diffTime < 0.0)
diffTime += mAnim->mDuration;
if( diffTime > 0)
{
float factor = float( (time - key.mTime) / diffTime);
presentPosition = key.mValue + (nextKey.mValue - key.mValue) * factor;
} else
{
presentPosition = key.mValue;
}
mLastPositions[a].get<0>() = frame;
}
// ******** Rotation *********
aiQuaternion presentRotation( 1, 0, 0, 0);
if( channel->mNumRotationKeys > 0)
{
unsigned int frame = (time >= mLastTime) ? mLastPositions[a].get<1>() : 0;
while( frame < channel->mNumRotationKeys - 1)
{
if( time < channel->mRotationKeys[frame+1].mTime)
break;
frame++;
}
// interpolate between this frame's value and next frame's value
unsigned int nextFrame = (frame + 1) % channel->mNumRotationKeys;
const aiQuatKey& key = channel->mRotationKeys[frame];
const aiQuatKey& nextKey = channel->mRotationKeys[nextFrame];
double diffTime = nextKey.mTime - key.mTime;
if( diffTime < 0.0)
diffTime += mAnim->mDuration;
if( diffTime > 0)
{
float factor = float( (time - key.mTime) / diffTime);
aiQuaternion::Interpolate( presentRotation, key.mValue, nextKey.mValue, factor);
} else
{
presentRotation = key.mValue;
}
mLastPositions[a].get<1>() = frame;
}
// ******** Scaling **********
aiVector3D presentScaling( 1, 1, 1);
if( channel->mNumScalingKeys > 0)
{
unsigned int frame = (time >= mLastTime) ? mLastPositions[a].get<2>() : 0;
while( frame < channel->mNumScalingKeys - 1)
{
if( time < channel->mScalingKeys[frame+1].mTime)
break;
frame++;
}
// TODO: (thom) interpolation maybe? This time maybe even logarithmic, not linear
presentScaling = channel->mScalingKeys[frame].mValue;
mLastPositions[a].get<2>() = frame;
}
// build a transformation matrix from it
aiMatrix4x4& mat = mTransforms[a];
mat = aiMatrix4x4( presentRotation.GetMatrix());
mat.a1 *= presentScaling.x; mat.b1 *= presentScaling.x; mat.c1 *= presentScaling.x;
mat.a2 *= presentScaling.y; mat.b2 *= presentScaling.y; mat.c2 *= presentScaling.y;
mat.a3 *= presentScaling.z; mat.b3 *= presentScaling.z; mat.c3 *= presentScaling.z;
mat.a4 = presentPosition.x; mat.b4 = presentPosition.y; mat.c4 = presentPosition.z;
//mat.Transpose();
}
mLastTime = time;
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
using namespace AssimpView;
// ------------------------------------------------------------------------------------------------
// Constructor on a given animation.
AnimEvaluator::AnimEvaluator( const aiAnimation* pAnim)
{
mAnim = pAnim;
mLastTime = 0.0;
mLastPositions.resize( pAnim->mNumChannels, boost::make_tuple( 0, 0, 0));
}
// ------------------------------------------------------------------------------------------------
// Evaluates the animation tracks for a given time stamp.
void AnimEvaluator::Evaluate( double pTime)
{
// extract ticks per second. Assume default value if not given
double ticksPerSecond = mAnim->mTicksPerSecond != 0.0 ? mAnim->mTicksPerSecond : 25.0;
// every following time calculation happens in ticks
pTime *= ticksPerSecond;
// map into anim's duration
double time = 0.0f;
if( mAnim->mDuration > 0.0)
time = fmod( pTime, mAnim->mDuration);
if( mTransforms.size() != mAnim->mNumChannels)
mTransforms.resize( mAnim->mNumChannels);
// calculate the transformations for each animation channel
for( unsigned int a = 0; a < mAnim->mNumChannels; a++)
{
const aiNodeAnim* channel = mAnim->mChannels[a];
// ******** Position *****
aiVector3D presentPosition( 0, 0, 0);
if( channel->mNumPositionKeys > 0)
{
// Look for present frame number. Search from last position if time is after the last time, else from beginning
// Should be much quicker than always looking from start for the average use case.
unsigned int frame = (time >= mLastTime) ? mLastPositions[a].get<0>() : 0;
while( frame < channel->mNumPositionKeys - 1)
{
if( time < channel->mPositionKeys[frame+1].mTime)
break;
frame++;
}
// interpolate between this frame's value and next frame's value
unsigned int nextFrame = (frame + 1) % channel->mNumPositionKeys;
const aiVectorKey& key = channel->mPositionKeys[frame];
const aiVectorKey& nextKey = channel->mPositionKeys[nextFrame];
double diffTime = nextKey.mTime - key.mTime;
if( diffTime < 0.0)
diffTime += mAnim->mDuration;
if( diffTime > 0)
{
float factor = float( (time - key.mTime) / diffTime);
presentPosition = key.mValue + (nextKey.mValue - key.mValue) * factor;
} else
{
presentPosition = key.mValue;
}
mLastPositions[a].get<0>() = frame;
}
// ******** Rotation *********
aiQuaternion presentRotation( 1, 0, 0, 0);
if( channel->mNumRotationKeys > 0)
{
unsigned int frame = (time >= mLastTime) ? mLastPositions[a].get<1>() : 0;
while( frame < channel->mNumRotationKeys - 1)
{
if( time < channel->mRotationKeys[frame+1].mTime)
break;
frame++;
}
// interpolate between this frame's value and next frame's value
unsigned int nextFrame = (frame + 1) % channel->mNumRotationKeys;
const aiQuatKey& key = channel->mRotationKeys[frame];
const aiQuatKey& nextKey = channel->mRotationKeys[nextFrame];
double diffTime = nextKey.mTime - key.mTime;
if( diffTime < 0.0)
diffTime += mAnim->mDuration;
if( diffTime > 0)
{
float factor = float( (time - key.mTime) / diffTime);
aiQuaternion::Interpolate( presentRotation, key.mValue, nextKey.mValue, factor);
} else
{
presentRotation = key.mValue;
}
mLastPositions[a].get<1>() = frame;
}
// ******** Scaling **********
aiVector3D presentScaling( 1, 1, 1);
if( channel->mNumScalingKeys > 0)
{
unsigned int frame = (time >= mLastTime) ? mLastPositions[a].get<2>() : 0;
while( frame < channel->mNumScalingKeys - 1)
{
if( time < channel->mScalingKeys[frame+1].mTime)
break;
frame++;
}
// TODO: (thom) interpolation maybe? This time maybe even logarithmic, not linear
presentScaling = channel->mScalingKeys[frame].mValue;
mLastPositions[a].get<2>() = frame;
}
// build a transformation matrix from it
aiMatrix4x4& mat = mTransforms[a];
mat = aiMatrix4x4( presentRotation.GetMatrix());
mat.a1 *= presentScaling.x; mat.b1 *= presentScaling.x; mat.c1 *= presentScaling.x;
mat.a2 *= presentScaling.y; mat.b2 *= presentScaling.y; mat.c2 *= presentScaling.y;
mat.a3 *= presentScaling.z; mat.b3 *= presentScaling.z; mat.c3 *= presentScaling.z;
mat.a4 = presentPosition.x; mat.b4 = presentPosition.y; mat.c4 = presentPosition.z;
//mat.Transpose();
}
mLastTime = time;
}

View File

@ -1,91 +1,91 @@
/** Calculates a pose for a given time of an animation */
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#ifndef AV_ANIMEVALUATOR_H_INCLUDED
#define AV_ANIMEVALUATOR_H_INCLUDED
#include <boost/tuple/tuple.hpp>
namespace AssimpView
{
/** Calculates transformations for a given timestamp from a set of animation tracks. Not directly useful,
* better use the AnimPlayer class.
*/
class AnimEvaluator
{
public:
/** Constructor on a given animation. The animation is fixed throughout the lifetime of
* the object.
* @param pAnim The animation to calculate poses for. Ownership of the animation object stays
* at the caller, the evaluator just keeps a reference to it as long as it persists.
*/
AnimEvaluator( const aiAnimation* pAnim);
/** Evaluates the animation tracks for a given time stamp. The calculated pose can be retrieved as a
* array of transformation matrices afterwards by calling GetTransformations().
* @param pTime The time for which you want to evaluate the animation, in seconds. Will be mapped into the animation cycle, so
* it can be an arbitrary value. Best use with ever-increasing time stamps.
*/
void Evaluate( double pTime);
/** Returns the transform matrices calculated at the last Evaluate() call. The array matches the mChannels array of
* the aiAnimation. */
const std::vector<aiMatrix4x4>& GetTransformations() const { return mTransforms; }
protected:
/** The animation we're working on */
const aiAnimation* mAnim;
/** At which frame the last evaluation happened for each channel.
* Useful to quickly find the corresponding frame for slightly increased time stamps
*/
double mLastTime;
std::vector<boost::tuple<unsigned int, unsigned int, unsigned int> > mLastPositions;
/** The array to store the transformations results of the evaluation */
std::vector<aiMatrix4x4> mTransforms;
};
} // end of namespace AssimpView
#endif // AV_ANIMEVALUATOR_H_INCLUDED
/** Calculates a pose for a given time of an animation */
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#ifndef AV_ANIMEVALUATOR_H_INCLUDED
#define AV_ANIMEVALUATOR_H_INCLUDED
#include <boost/tuple/tuple.hpp>
namespace AssimpView
{
/** Calculates transformations for a given timestamp from a set of animation tracks. Not directly useful,
* better use the AnimPlayer class.
*/
class AnimEvaluator
{
public:
/** Constructor on a given animation. The animation is fixed throughout the lifetime of
* the object.
* @param pAnim The animation to calculate poses for. Ownership of the animation object stays
* at the caller, the evaluator just keeps a reference to it as long as it persists.
*/
AnimEvaluator( const aiAnimation* pAnim);
/** Evaluates the animation tracks for a given time stamp. The calculated pose can be retrieved as a
* array of transformation matrices afterwards by calling GetTransformations().
* @param pTime The time for which you want to evaluate the animation, in seconds. Will be mapped into the animation cycle, so
* it can be an arbitrary value. Best use with ever-increasing time stamps.
*/
void Evaluate( double pTime);
/** Returns the transform matrices calculated at the last Evaluate() call. The array matches the mChannels array of
* the aiAnimation. */
const std::vector<aiMatrix4x4>& GetTransformations() const { return mTransforms; }
protected:
/** The animation we're working on */
const aiAnimation* mAnim;
/** At which frame the last evaluation happened for each channel.
* Useful to quickly find the corresponding frame for slightly increased time stamps
*/
double mLastTime;
std::vector<boost::tuple<unsigned int, unsigned int, unsigned int> > mLastPositions;
/** The array to store the transformations results of the evaluation */
std::vector<aiMatrix4x4> mTransforms;
};
} // end of namespace AssimpView
#endif // AV_ANIMEVALUATOR_H_INCLUDED

View File

@ -1,246 +1,246 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#if (!defined AV_ASSET_HELPER_H_INCLUDED)
#define AV_ASSET_HELPER_H_INCLUDED
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dx9mesh.h>
#include <assimp/scene.h>
namespace AssimpView {
class SceneAnimator;
//-------------------------------------------------------------------------------
/** \brief Class to wrap ASSIMP's asset output structures
*/
//-------------------------------------------------------------------------------
class AssetHelper
{
public:
enum
{
// the original normal set will be used
ORIGINAL = 0x0u,
// a smoothed normal set will be used
SMOOTH = 0x1u,
// a hard normal set will be used
HARD = 0x2u,
};
// default constructor
AssetHelper()
: iNormalSet( ORIGINAL )
{
mAnimator = NULL;
apcMeshes = NULL;
pcScene = NULL;
}
//---------------------------------------------------------------
// default vertex data structure
// (even if tangents, bitangents or normals aren't
// required by the shader they will be committed to the GPU)
//---------------------------------------------------------------
struct Vertex
{
aiVector3D vPosition;
aiVector3D vNormal;
D3DCOLOR dColorDiffuse;
aiVector3D vTangent;
aiVector3D vBitangent;
aiVector2D vTextureUV;
aiVector2D vTextureUV2;
unsigned char mBoneIndices[ 4 ];
unsigned char mBoneWeights[ 4 ]; // last Weight not used, calculated inside the vertex shader
/** Returns the vertex declaration elements to create a declaration from. */
static D3DVERTEXELEMENT9* GetDeclarationElements()
{
static D3DVERTEXELEMENT9 decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 24, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
{ 0, 28, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
{ 0, 40, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },
{ 0, 52, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 60, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
{ 0, 68, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0 },
{ 0, 72, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0 },
D3DDECL_END()
};
return decl;
}
};
//---------------------------------------------------------------
// FVF vertex structure used for normals
//---------------------------------------------------------------
struct LineVertex
{
aiVector3D vPosition;
DWORD dColorDiffuse;
// retrieves the FVF code of the vertex type
static DWORD GetFVF()
{
return D3DFVF_DIFFUSE | D3DFVF_XYZ;
}
};
//---------------------------------------------------------------
// Helper class to store GPU related resources created for
// a given aiMesh
//---------------------------------------------------------------
class MeshHelper
{
public:
MeshHelper()
:
piVB( NULL ),
piIB( NULL ),
piVBNormals( NULL ),
piEffect( NULL ),
bSharedFX( false ),
piDiffuseTexture( NULL ),
piSpecularTexture( NULL ),
piAmbientTexture( NULL ),
piEmissiveTexture( NULL ),
piNormalTexture( NULL ),
piOpacityTexture( NULL ),
piShininessTexture( NULL ),
piLightmapTexture( NULL ),
twosided( false ),
pvOriginalNormals( NULL )
{}
~MeshHelper()
{
// NOTE: This is done in DeleteAssetData()
// TODO: Make this a proper d'tor
}
// shading mode to use. Either Lambert or otherwise phong
// will be used in every case
aiShadingMode eShadingMode;
// vertex buffer
IDirect3DVertexBuffer9* piVB;
// index buffer. For partially transparent meshes
// created with dynamic usage to be able to update
// the buffer contents quickly
IDirect3DIndexBuffer9* piIB;
// vertex buffer to be used to draw vertex normals
// (vertex normals are generated in every case)
IDirect3DVertexBuffer9* piVBNormals;
// shader to be used
ID3DXEffect* piEffect;
bool bSharedFX;
// material textures
IDirect3DTexture9* piDiffuseTexture;
IDirect3DTexture9* piSpecularTexture;
IDirect3DTexture9* piAmbientTexture;
IDirect3DTexture9* piEmissiveTexture;
IDirect3DTexture9* piNormalTexture;
IDirect3DTexture9* piOpacityTexture;
IDirect3DTexture9* piShininessTexture;
IDirect3DTexture9* piLightmapTexture;
// material colors
D3DXVECTOR4 vDiffuseColor;
D3DXVECTOR4 vSpecularColor;
D3DXVECTOR4 vAmbientColor;
D3DXVECTOR4 vEmissiveColor;
// opacity for the material
float fOpacity;
// shininess for the material
float fShininess;
// strength of the specular highlight
float fSpecularStrength;
// two-sided?
bool twosided;
// Stores a pointer to the original normal set of the asset
aiVector3D* pvOriginalNormals;
};
// One instance per aiMesh in the globally loaded asset
MeshHelper** apcMeshes;
// Scene wrapper instance
aiScene* pcScene;
// Animation player to animate the scene if necessary
SceneAnimator* mAnimator;
// Specifies the normal set to be used
unsigned int iNormalSet;
// ------------------------------------------------------------------
// set the normal set to be used
void SetNormalSet( unsigned int iSet );
// ------------------------------------------------------------------
// flip all normal vectors
void FlipNormals();
void FlipNormalsInt();
};
}
#endif // !! IG
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#if (!defined AV_ASSET_HELPER_H_INCLUDED)
#define AV_ASSET_HELPER_H_INCLUDED
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dx9mesh.h>
#include <assimp/scene.h>
namespace AssimpView {
class SceneAnimator;
//-------------------------------------------------------------------------------
/** \brief Class to wrap ASSIMP's asset output structures
*/
//-------------------------------------------------------------------------------
class AssetHelper
{
public:
enum
{
// the original normal set will be used
ORIGINAL = 0x0u,
// a smoothed normal set will be used
SMOOTH = 0x1u,
// a hard normal set will be used
HARD = 0x2u,
};
// default constructor
AssetHelper()
: iNormalSet( ORIGINAL )
{
mAnimator = NULL;
apcMeshes = NULL;
pcScene = NULL;
}
//---------------------------------------------------------------
// default vertex data structure
// (even if tangents, bitangents or normals aren't
// required by the shader they will be committed to the GPU)
//---------------------------------------------------------------
struct Vertex
{
aiVector3D vPosition;
aiVector3D vNormal;
D3DCOLOR dColorDiffuse;
aiVector3D vTangent;
aiVector3D vBitangent;
aiVector2D vTextureUV;
aiVector2D vTextureUV2;
unsigned char mBoneIndices[ 4 ];
unsigned char mBoneWeights[ 4 ]; // last Weight not used, calculated inside the vertex shader
/** Returns the vertex declaration elements to create a declaration from. */
static D3DVERTEXELEMENT9* GetDeclarationElements()
{
static D3DVERTEXELEMENT9 decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 24, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
{ 0, 28, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
{ 0, 40, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },
{ 0, 52, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 60, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
{ 0, 68, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0 },
{ 0, 72, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0 },
D3DDECL_END()
};
return decl;
}
};
//---------------------------------------------------------------
// FVF vertex structure used for normals
//---------------------------------------------------------------
struct LineVertex
{
aiVector3D vPosition;
DWORD dColorDiffuse;
// retrieves the FVF code of the vertex type
static DWORD GetFVF()
{
return D3DFVF_DIFFUSE | D3DFVF_XYZ;
}
};
//---------------------------------------------------------------
// Helper class to store GPU related resources created for
// a given aiMesh
//---------------------------------------------------------------
class MeshHelper
{
public:
MeshHelper()
:
piVB( NULL ),
piIB( NULL ),
piVBNormals( NULL ),
piEffect( NULL ),
bSharedFX( false ),
piDiffuseTexture( NULL ),
piSpecularTexture( NULL ),
piAmbientTexture( NULL ),
piEmissiveTexture( NULL ),
piNormalTexture( NULL ),
piOpacityTexture( NULL ),
piShininessTexture( NULL ),
piLightmapTexture( NULL ),
twosided( false ),
pvOriginalNormals( NULL )
{}
~MeshHelper()
{
// NOTE: This is done in DeleteAssetData()
// TODO: Make this a proper d'tor
}
// shading mode to use. Either Lambert or otherwise phong
// will be used in every case
aiShadingMode eShadingMode;
// vertex buffer
IDirect3DVertexBuffer9* piVB;
// index buffer. For partially transparent meshes
// created with dynamic usage to be able to update
// the buffer contents quickly
IDirect3DIndexBuffer9* piIB;
// vertex buffer to be used to draw vertex normals
// (vertex normals are generated in every case)
IDirect3DVertexBuffer9* piVBNormals;
// shader to be used
ID3DXEffect* piEffect;
bool bSharedFX;
// material textures
IDirect3DTexture9* piDiffuseTexture;
IDirect3DTexture9* piSpecularTexture;
IDirect3DTexture9* piAmbientTexture;
IDirect3DTexture9* piEmissiveTexture;
IDirect3DTexture9* piNormalTexture;
IDirect3DTexture9* piOpacityTexture;
IDirect3DTexture9* piShininessTexture;
IDirect3DTexture9* piLightmapTexture;
// material colors
D3DXVECTOR4 vDiffuseColor;
D3DXVECTOR4 vSpecularColor;
D3DXVECTOR4 vAmbientColor;
D3DXVECTOR4 vEmissiveColor;
// opacity for the material
float fOpacity;
// shininess for the material
float fShininess;
// strength of the specular highlight
float fSpecularStrength;
// two-sided?
bool twosided;
// Stores a pointer to the original normal set of the asset
aiVector3D* pvOriginalNormals;
};
// One instance per aiMesh in the globally loaded asset
MeshHelper** apcMeshes;
// Scene wrapper instance
aiScene* pcScene;
// Animation player to animate the scene if necessary
SceneAnimator* mAnimator;
// Specifies the normal set to be used
unsigned int iNormalSet;
// ------------------------------------------------------------------
// set the normal set to be used
void SetNormalSet( unsigned int iSet );
// ------------------------------------------------------------------
// flip all normal vectors
void FlipNormals();
void FlipNormalsInt();
};
}
#endif // !! IG

View File

@ -1,470 +1,470 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
namespace AssimpView {
extern std::string g_szSkyboxShader;
// From: U3D build 1256 (src\kernel\graphic\scenegraph\SkyBox.cpp)
// ------------------------------------------------------------------------------
/** \brief Vertex structure for the skybox
*/
// ------------------------------------------------------------------------------
struct SkyBoxVertex
{
float x,y,z;
float u,v,w;
};
// ------------------------------------------------------------------------------
/** \brief Vertices for the skybox
*/
// ------------------------------------------------------------------------------
SkyBoxVertex g_cubeVertices_indexed[] =
{
{ -1.0f, 1.0f, -1.0f, -1.0f,1.0f,-1.0f }, // 0
{ 1.0f, 1.0f, -1.0f, 1.0f,1.0f,-1.0f }, // 1
{ -1.0f, -1.0f, -1.0f, -1.0f,-1.0f,-1.0f }, // 2
{ 1.0f,-1.0f,-1.0f, 1.0f,-1.0f,-1.0f }, // 3
{-1.0f, 1.0f, 1.0f, -1.0f,1.0f,1.0f }, // 4
{-1.0f,-1.0f, 1.0f, -1.0f,-1.0f,1.0f }, // 5
{ 1.0f, 1.0f, 1.0f, 1.0f,1.0f,1.0f }, // 6
{ 1.0f,-1.0f, 1.0f, 1.0f,-1.0f,1.0f } // 7
};
// ------------------------------------------------------------------------------
/** \brief Indices for the skybox
*/
// ------------------------------------------------------------------------------
unsigned short g_cubeIndices[] =
{
0, 1, 2, 3, 2, 1,4, 5, 6,
7, 6, 5, 4, 6, 0, 1, 6, 0,
5, 2, 7,3, 2, 7, 1, 6, 3,
7, 3, 6, 0, 2, 4, 5, 4, 2,
};
CBackgroundPainter CBackgroundPainter::s_cInstance;
//-------------------------------------------------------------------------------
void CBackgroundPainter::SetColor (D3DCOLOR p_clrNew)
{
if (TEXTURE_CUBE == eMode)
RemoveSBDeps();
clrColor = p_clrNew;
eMode = SIMPLE_COLOR;
if (pcTexture)
{
pcTexture->Release();
pcTexture = NULL;
}
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::RemoveSBDeps()
{
MODE e = eMode;
eMode = SIMPLE_COLOR;
if (g_pcAsset && g_pcAsset->pcScene)
{
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
{
if (aiShadingMode_Gouraud != g_pcAsset->apcMeshes[i]->eShadingMode)
{
CMaterialManager::Instance().DeleteMaterial(g_pcAsset->apcMeshes[i]);
CMaterialManager::Instance().CreateMaterial(
g_pcAsset->apcMeshes[i],g_pcAsset->pcScene->mMeshes[i]);
}
}
}
eMode = e;
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::ResetSB()
{
mMatrix = aiMatrix4x4();
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::SetCubeMapBG (const char* p_szPath)
{
bool bHad = false;
if (pcTexture)
{
pcTexture->Release();
pcTexture = NULL;
if(TEXTURE_CUBE ==eMode)bHad = true;
}
eMode = TEXTURE_CUBE;
szPath = std::string( p_szPath );
// ARRRGHH... ugly. TODO: Rewrite this!
aiString sz;
sz.Set(szPath);
CMaterialManager::Instance().FindValidPath(&sz);
szPath = std::string( sz.data );
// now recreate all native resources
RecreateNativeResource();
if (SIMPLE_COLOR != this->eMode)
{
// this influences all material with specular components
if (!bHad)
{
if (g_pcAsset && g_pcAsset->pcScene)
{
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
{
if (aiShadingMode_Phong == g_pcAsset->apcMeshes[i]->eShadingMode)
{
CMaterialManager::Instance().DeleteMaterial(g_pcAsset->apcMeshes[i]);
CMaterialManager::Instance().CreateMaterial(
g_pcAsset->apcMeshes[i],g_pcAsset->pcScene->mMeshes[i]);
}
}
}
}
else
{
if (g_pcAsset && g_pcAsset->pcScene)
{
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
{
if (aiShadingMode_Phong == g_pcAsset->apcMeshes[i]->eShadingMode)
{
g_pcAsset->apcMeshes[i]->piEffect->SetTexture(
"lw_tex_envmap",CBackgroundPainter::Instance().GetTexture());
}
}
}
}
}
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::RotateSB(const aiMatrix4x4* pm)
{
this->mMatrix = mMatrix * (*pm);
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::SetTextureBG (const char* p_szPath)
{
if (TEXTURE_CUBE == this->eMode)this->RemoveSBDeps();
if (pcTexture)
{
pcTexture->Release();
pcTexture = NULL;
}
eMode = TEXTURE_2D;
szPath = std::string( p_szPath );
// ARRRGHH... ugly. TODO: Rewrite this!
aiString sz;
sz.Set(szPath);
CMaterialManager::Instance().FindValidPath(&sz);
szPath = std::string( sz.data );
// now recreate all native resources
RecreateNativeResource();
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::OnPreRender()
{
if (SIMPLE_COLOR != eMode)
{
// clear the z-buffer only (in wireframe mode we must also clear
// the color buffer )
if (g_sOptions.eDrawMode == RenderOptions::WIREFRAME)
{
g_piDevice->Clear(0,NULL,D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET,
D3DCOLOR_ARGB(0xff,100,100,100),1.0f,0);
}
else
{
g_piDevice->Clear(0,NULL,D3DCLEAR_ZBUFFER,0,1.0f,0);
}
if (TEXTURE_2D == eMode)
{
RECT sRect;
GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect);
sRect.right -= sRect.left;
sRect.bottom -= sRect.top;
struct SVertex
{
float x,y,z,w,u,v;
};
UINT dw;
this->piSkyBoxEffect->Begin(&dw,0);
this->piSkyBoxEffect->BeginPass(0);
SVertex as[4];
as[1].x = 0.0f;
as[1].y = 0.0f;
as[1].z = 0.2f;
as[1].w = 1.0f;
as[1].u = 0.0f;
as[1].v = 0.0f;
as[3].x = (float)sRect.right;
as[3].y = 0.0f;
as[3].z = 0.2f;
as[3].w = 1.0f;
as[3].u = 1.0f;
as[3].v = 0.0f;
as[0].x = 0.0f;
as[0].y = (float)sRect.bottom;
as[0].z = 0.2f;
as[0].w = 1.0f;
as[0].u = 0.0f;
as[0].v = 1.0f;
as[2].x = (float)sRect.right;
as[2].y = (float)sRect.bottom;
as[2].z = 0.2f;
as[2].w = 1.0f;
as[2].u = 1.0f;
as[2].v = 1.0f;
as[0].x -= 0.5f;as[1].x -= 0.5f;as[2].x -= 0.5f;as[3].x -= 0.5f;
as[0].y -= 0.5f;as[1].y -= 0.5f;as[2].y -= 0.5f;as[3].y -= 0.5f;
DWORD dw2;g_piDevice->GetFVF(&dw2);
g_piDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);
g_piDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,
&as,sizeof(SVertex));
piSkyBoxEffect->EndPass();
piSkyBoxEffect->End();
g_piDevice->SetFVF(dw2);
}
return;
}
// clear both the render target and the z-buffer
g_piDevice->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
clrColor,1.0f,0);
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::OnPostRender()
{
if (TEXTURE_CUBE == eMode)
{
aiMatrix4x4 pcProj;
GetProjectionMatrix(pcProj);
aiMatrix4x4 pcCam;
aiVector3D vPos = GetCameraMatrix(pcCam);
aiMatrix4x4 aiMe;
aiMe[3][0] = vPos.x;
aiMe[3][1] = vPos.y;
aiMe[3][2] = vPos.z;
aiMe = mMatrix * aiMe;
pcProj = (aiMe * pcCam) * pcProj;
piSkyBoxEffect->SetMatrix("WorldViewProjection",
(const D3DXMATRIX*)&pcProj);
UINT dwPasses;
piSkyBoxEffect->Begin(&dwPasses,0);
piSkyBoxEffect->BeginPass(0);
DWORD dw2;
g_piDevice->GetFVF(&dw2);
g_piDevice->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0));
g_piDevice->DrawIndexedPrimitiveUP(
D3DPT_TRIANGLELIST,0,8,12,g_cubeIndices,D3DFMT_INDEX16,
g_cubeVertices_indexed,sizeof(SkyBoxVertex));
g_piDevice->SetFVF(dw2);
piSkyBoxEffect->EndPass();
piSkyBoxEffect->End();
}
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::ReleaseNativeResource()
{
if ( piSkyBoxEffect)
{
piSkyBoxEffect->Release();
piSkyBoxEffect = NULL;
}
if (pcTexture)
{
pcTexture->Release();
pcTexture = NULL;
}
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::RecreateNativeResource()
{
if (SIMPLE_COLOR == eMode)return;
if (TEXTURE_CUBE == eMode)
{
// many skyboxes are 16bit FP format which isn't supported
// with bilinear filtering on older cards
D3DFORMAT eFmt = D3DFMT_UNKNOWN;
if(FAILED(g_piD3D->CheckDeviceFormat(0,D3DDEVTYPE_HAL,
D3DFMT_X8R8G8B8,D3DUSAGE_QUERY_FILTER,D3DRTYPE_CUBETEXTURE,D3DFMT_A16B16G16R16F)))
{
eFmt = D3DFMT_A8R8G8B8;
}
if (FAILED(D3DXCreateCubeTextureFromFileEx(
g_piDevice,
szPath.c_str(),
D3DX_DEFAULT,
0,
0,
eFmt,
D3DPOOL_MANAGED,
D3DX_DEFAULT,
D3DX_DEFAULT,
0,
NULL,
NULL,
(IDirect3DCubeTexture9**)&pcTexture)))
{
const char* szEnd = strrchr(szPath.c_str(),'\\');
if (!szEnd)szEnd = strrchr(szPath.c_str(),'/');
if (!szEnd)szEnd = szPath.c_str()-1;
char szTemp[1024];
sprintf(szTemp,"[ERROR] Unable to load background cubemap %s",szEnd+1);
CLogDisplay::Instance().AddEntry(szTemp,
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
eMode = SIMPLE_COLOR;
return;
}
else CLogDisplay::Instance().AddEntry("[OK] The skybox has been imported successfully",
D3DCOLOR_ARGB(0xFF,0,0xFF,0));
}
else
{
if (FAILED(D3DXCreateTextureFromFileEx(
g_piDevice,
szPath.c_str(),
D3DX_DEFAULT,
D3DX_DEFAULT,
0,
0,
D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED,
D3DX_DEFAULT,
D3DX_DEFAULT,
0,
NULL,
NULL,
(IDirect3DTexture9**)&pcTexture)))
{
const char* szEnd = strrchr(szPath.c_str(),'\\');
if (!szEnd)szEnd = strrchr(szPath.c_str(),'/');
if (!szEnd)szEnd = szPath.c_str()-1;
char szTemp[1024];
sprintf(szTemp,"[ERROR] Unable to load background texture %s",szEnd+1);
CLogDisplay::Instance().AddEntry(szTemp,
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
eMode = SIMPLE_COLOR;
return;
}
else CLogDisplay::Instance().AddEntry("[OK] The background texture has been imported successfully",
D3DCOLOR_ARGB(0xFF,0,0xFF,0));
}
if (!piSkyBoxEffect)
{
ID3DXBuffer* piBuffer = NULL;
if(FAILED( D3DXCreateEffect(
g_piDevice,
g_szSkyboxShader.c_str(),
(UINT)g_szSkyboxShader.length(),
NULL,
NULL,
AI_SHADER_COMPILE_FLAGS,
NULL,
&piSkyBoxEffect,&piBuffer)))
{
// failed to compile the shader
if( piBuffer) {
MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK);
piBuffer->Release();
}
CLogDisplay::Instance().AddEntry("[ERROR] Unable to compile skybox shader",
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
eMode = SIMPLE_COLOR;
return ;
}
}
// commit the correct textures to the shader
if (TEXTURE_CUBE == eMode)
{
piSkyBoxEffect->SetTexture("lw_tex_envmap",pcTexture);
piSkyBoxEffect->SetTechnique("RenderSkyBox");
}
else if (TEXTURE_2D == eMode)
{
piSkyBoxEffect->SetTexture("TEXTURE_2D",pcTexture);
piSkyBoxEffect->SetTechnique("RenderImage2D");
}
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
namespace AssimpView {
extern std::string g_szSkyboxShader;
// From: U3D build 1256 (src\kernel\graphic\scenegraph\SkyBox.cpp)
// ------------------------------------------------------------------------------
/** \brief Vertex structure for the skybox
*/
// ------------------------------------------------------------------------------
struct SkyBoxVertex
{
float x,y,z;
float u,v,w;
};
// ------------------------------------------------------------------------------
/** \brief Vertices for the skybox
*/
// ------------------------------------------------------------------------------
SkyBoxVertex g_cubeVertices_indexed[] =
{
{ -1.0f, 1.0f, -1.0f, -1.0f,1.0f,-1.0f }, // 0
{ 1.0f, 1.0f, -1.0f, 1.0f,1.0f,-1.0f }, // 1
{ -1.0f, -1.0f, -1.0f, -1.0f,-1.0f,-1.0f }, // 2
{ 1.0f,-1.0f,-1.0f, 1.0f,-1.0f,-1.0f }, // 3
{-1.0f, 1.0f, 1.0f, -1.0f,1.0f,1.0f }, // 4
{-1.0f,-1.0f, 1.0f, -1.0f,-1.0f,1.0f }, // 5
{ 1.0f, 1.0f, 1.0f, 1.0f,1.0f,1.0f }, // 6
{ 1.0f,-1.0f, 1.0f, 1.0f,-1.0f,1.0f } // 7
};
// ------------------------------------------------------------------------------
/** \brief Indices for the skybox
*/
// ------------------------------------------------------------------------------
unsigned short g_cubeIndices[] =
{
0, 1, 2, 3, 2, 1,4, 5, 6,
7, 6, 5, 4, 6, 0, 1, 6, 0,
5, 2, 7,3, 2, 7, 1, 6, 3,
7, 3, 6, 0, 2, 4, 5, 4, 2,
};
CBackgroundPainter CBackgroundPainter::s_cInstance;
//-------------------------------------------------------------------------------
void CBackgroundPainter::SetColor (D3DCOLOR p_clrNew)
{
if (TEXTURE_CUBE == eMode)
RemoveSBDeps();
clrColor = p_clrNew;
eMode = SIMPLE_COLOR;
if (pcTexture)
{
pcTexture->Release();
pcTexture = NULL;
}
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::RemoveSBDeps()
{
MODE e = eMode;
eMode = SIMPLE_COLOR;
if (g_pcAsset && g_pcAsset->pcScene)
{
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
{
if (aiShadingMode_Gouraud != g_pcAsset->apcMeshes[i]->eShadingMode)
{
CMaterialManager::Instance().DeleteMaterial(g_pcAsset->apcMeshes[i]);
CMaterialManager::Instance().CreateMaterial(
g_pcAsset->apcMeshes[i],g_pcAsset->pcScene->mMeshes[i]);
}
}
}
eMode = e;
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::ResetSB()
{
mMatrix = aiMatrix4x4();
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::SetCubeMapBG (const char* p_szPath)
{
bool bHad = false;
if (pcTexture)
{
pcTexture->Release();
pcTexture = NULL;
if(TEXTURE_CUBE ==eMode)bHad = true;
}
eMode = TEXTURE_CUBE;
szPath = std::string( p_szPath );
// ARRRGHH... ugly. TODO: Rewrite this!
aiString sz;
sz.Set(szPath);
CMaterialManager::Instance().FindValidPath(&sz);
szPath = std::string( sz.data );
// now recreate all native resources
RecreateNativeResource();
if (SIMPLE_COLOR != this->eMode)
{
// this influences all material with specular components
if (!bHad)
{
if (g_pcAsset && g_pcAsset->pcScene)
{
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
{
if (aiShadingMode_Phong == g_pcAsset->apcMeshes[i]->eShadingMode)
{
CMaterialManager::Instance().DeleteMaterial(g_pcAsset->apcMeshes[i]);
CMaterialManager::Instance().CreateMaterial(
g_pcAsset->apcMeshes[i],g_pcAsset->pcScene->mMeshes[i]);
}
}
}
}
else
{
if (g_pcAsset && g_pcAsset->pcScene)
{
for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
{
if (aiShadingMode_Phong == g_pcAsset->apcMeshes[i]->eShadingMode)
{
g_pcAsset->apcMeshes[i]->piEffect->SetTexture(
"lw_tex_envmap",CBackgroundPainter::Instance().GetTexture());
}
}
}
}
}
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::RotateSB(const aiMatrix4x4* pm)
{
this->mMatrix = mMatrix * (*pm);
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::SetTextureBG (const char* p_szPath)
{
if (TEXTURE_CUBE == this->eMode)this->RemoveSBDeps();
if (pcTexture)
{
pcTexture->Release();
pcTexture = NULL;
}
eMode = TEXTURE_2D;
szPath = std::string( p_szPath );
// ARRRGHH... ugly. TODO: Rewrite this!
aiString sz;
sz.Set(szPath);
CMaterialManager::Instance().FindValidPath(&sz);
szPath = std::string( sz.data );
// now recreate all native resources
RecreateNativeResource();
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::OnPreRender()
{
if (SIMPLE_COLOR != eMode)
{
// clear the z-buffer only (in wireframe mode we must also clear
// the color buffer )
if (g_sOptions.eDrawMode == RenderOptions::WIREFRAME)
{
g_piDevice->Clear(0,NULL,D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET,
D3DCOLOR_ARGB(0xff,100,100,100),1.0f,0);
}
else
{
g_piDevice->Clear(0,NULL,D3DCLEAR_ZBUFFER,0,1.0f,0);
}
if (TEXTURE_2D == eMode)
{
RECT sRect;
GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect);
sRect.right -= sRect.left;
sRect.bottom -= sRect.top;
struct SVertex
{
float x,y,z,w,u,v;
};
UINT dw;
this->piSkyBoxEffect->Begin(&dw,0);
this->piSkyBoxEffect->BeginPass(0);
SVertex as[4];
as[1].x = 0.0f;
as[1].y = 0.0f;
as[1].z = 0.2f;
as[1].w = 1.0f;
as[1].u = 0.0f;
as[1].v = 0.0f;
as[3].x = (float)sRect.right;
as[3].y = 0.0f;
as[3].z = 0.2f;
as[3].w = 1.0f;
as[3].u = 1.0f;
as[3].v = 0.0f;
as[0].x = 0.0f;
as[0].y = (float)sRect.bottom;
as[0].z = 0.2f;
as[0].w = 1.0f;
as[0].u = 0.0f;
as[0].v = 1.0f;
as[2].x = (float)sRect.right;
as[2].y = (float)sRect.bottom;
as[2].z = 0.2f;
as[2].w = 1.0f;
as[2].u = 1.0f;
as[2].v = 1.0f;
as[0].x -= 0.5f;as[1].x -= 0.5f;as[2].x -= 0.5f;as[3].x -= 0.5f;
as[0].y -= 0.5f;as[1].y -= 0.5f;as[2].y -= 0.5f;as[3].y -= 0.5f;
DWORD dw2;g_piDevice->GetFVF(&dw2);
g_piDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);
g_piDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,
&as,sizeof(SVertex));
piSkyBoxEffect->EndPass();
piSkyBoxEffect->End();
g_piDevice->SetFVF(dw2);
}
return;
}
// clear both the render target and the z-buffer
g_piDevice->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
clrColor,1.0f,0);
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::OnPostRender()
{
if (TEXTURE_CUBE == eMode)
{
aiMatrix4x4 pcProj;
GetProjectionMatrix(pcProj);
aiMatrix4x4 pcCam;
aiVector3D vPos = GetCameraMatrix(pcCam);
aiMatrix4x4 aiMe;
aiMe[3][0] = vPos.x;
aiMe[3][1] = vPos.y;
aiMe[3][2] = vPos.z;
aiMe = mMatrix * aiMe;
pcProj = (aiMe * pcCam) * pcProj;
piSkyBoxEffect->SetMatrix("WorldViewProjection",
(const D3DXMATRIX*)&pcProj);
UINT dwPasses;
piSkyBoxEffect->Begin(&dwPasses,0);
piSkyBoxEffect->BeginPass(0);
DWORD dw2;
g_piDevice->GetFVF(&dw2);
g_piDevice->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0));
g_piDevice->DrawIndexedPrimitiveUP(
D3DPT_TRIANGLELIST,0,8,12,g_cubeIndices,D3DFMT_INDEX16,
g_cubeVertices_indexed,sizeof(SkyBoxVertex));
g_piDevice->SetFVF(dw2);
piSkyBoxEffect->EndPass();
piSkyBoxEffect->End();
}
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::ReleaseNativeResource()
{
if ( piSkyBoxEffect)
{
piSkyBoxEffect->Release();
piSkyBoxEffect = NULL;
}
if (pcTexture)
{
pcTexture->Release();
pcTexture = NULL;
}
}
//-------------------------------------------------------------------------------
void CBackgroundPainter::RecreateNativeResource()
{
if (SIMPLE_COLOR == eMode)return;
if (TEXTURE_CUBE == eMode)
{
// many skyboxes are 16bit FP format which isn't supported
// with bilinear filtering on older cards
D3DFORMAT eFmt = D3DFMT_UNKNOWN;
if(FAILED(g_piD3D->CheckDeviceFormat(0,D3DDEVTYPE_HAL,
D3DFMT_X8R8G8B8,D3DUSAGE_QUERY_FILTER,D3DRTYPE_CUBETEXTURE,D3DFMT_A16B16G16R16F)))
{
eFmt = D3DFMT_A8R8G8B8;
}
if (FAILED(D3DXCreateCubeTextureFromFileEx(
g_piDevice,
szPath.c_str(),
D3DX_DEFAULT,
0,
0,
eFmt,
D3DPOOL_MANAGED,
D3DX_DEFAULT,
D3DX_DEFAULT,
0,
NULL,
NULL,
(IDirect3DCubeTexture9**)&pcTexture)))
{
const char* szEnd = strrchr(szPath.c_str(),'\\');
if (!szEnd)szEnd = strrchr(szPath.c_str(),'/');
if (!szEnd)szEnd = szPath.c_str()-1;
char szTemp[1024];
sprintf(szTemp,"[ERROR] Unable to load background cubemap %s",szEnd+1);
CLogDisplay::Instance().AddEntry(szTemp,
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
eMode = SIMPLE_COLOR;
return;
}
else CLogDisplay::Instance().AddEntry("[OK] The skybox has been imported successfully",
D3DCOLOR_ARGB(0xFF,0,0xFF,0));
}
else
{
if (FAILED(D3DXCreateTextureFromFileEx(
g_piDevice,
szPath.c_str(),
D3DX_DEFAULT,
D3DX_DEFAULT,
0,
0,
D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED,
D3DX_DEFAULT,
D3DX_DEFAULT,
0,
NULL,
NULL,
(IDirect3DTexture9**)&pcTexture)))
{
const char* szEnd = strrchr(szPath.c_str(),'\\');
if (!szEnd)szEnd = strrchr(szPath.c_str(),'/');
if (!szEnd)szEnd = szPath.c_str()-1;
char szTemp[1024];
sprintf(szTemp,"[ERROR] Unable to load background texture %s",szEnd+1);
CLogDisplay::Instance().AddEntry(szTemp,
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
eMode = SIMPLE_COLOR;
return;
}
else CLogDisplay::Instance().AddEntry("[OK] The background texture has been imported successfully",
D3DCOLOR_ARGB(0xFF,0,0xFF,0));
}
if (!piSkyBoxEffect)
{
ID3DXBuffer* piBuffer = NULL;
if(FAILED( D3DXCreateEffect(
g_piDevice,
g_szSkyboxShader.c_str(),
(UINT)g_szSkyboxShader.length(),
NULL,
NULL,
AI_SHADER_COMPILE_FLAGS,
NULL,
&piSkyBoxEffect,&piBuffer)))
{
// failed to compile the shader
if( piBuffer) {
MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK);
piBuffer->Release();
}
CLogDisplay::Instance().AddEntry("[ERROR] Unable to compile skybox shader",
D3DCOLOR_ARGB(0xFF,0xFF,0,0));
eMode = SIMPLE_COLOR;
return ;
}
}
// commit the correct textures to the shader
if (TEXTURE_CUBE == eMode)
{
piSkyBoxEffect->SetTexture("lw_tex_envmap",pcTexture);
piSkyBoxEffect->SetTechnique("RenderSkyBox");
}
else if (TEXTURE_2D == eMode)
{
piSkyBoxEffect->SetTexture("TEXTURE_2D",pcTexture);
piSkyBoxEffect->SetTechnique("RenderImage2D");
}
}
};

View File

@ -1,128 +1,128 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#pragma once
namespace AssimpView
{
class CBackgroundPainter
{
CBackgroundPainter()
:
clrColor( D3DCOLOR_ARGB( 0xFF, 100, 100, 100 ) ),
pcTexture( NULL ),
piSkyBoxEffect( NULL ),
eMode( SIMPLE_COLOR )
{}
public:
// Supported background draw modi
enum MODE { SIMPLE_COLOR, TEXTURE_2D, TEXTURE_CUBE };
// Singleton accessors
static CBackgroundPainter s_cInstance;
inline static CBackgroundPainter& Instance()
{
return s_cInstance;
}
// set the current background color
// (this removes any textures loaded)
void SetColor( D3DCOLOR p_clrNew );
// Setup a cubemap/a 2d texture as background
void SetCubeMapBG( const char* p_szPath );
void SetTextureBG( const char* p_szPath );
// Called by the render loop
void OnPreRender();
void OnPostRender();
// Release any native resources associated with the instance
void ReleaseNativeResource();
// Recreate any native resources associated with the instance
void RecreateNativeResource();
// Rotate the skybox
void RotateSB( const aiMatrix4x4* pm );
// Reset the state of the skybox
void ResetSB();
inline MODE GetMode() const
{
return this->eMode;
}
inline IDirect3DBaseTexture9* GetTexture()
{
return this->pcTexture;
}
inline ID3DXBaseEffect* GetEffect()
{
return this->piSkyBoxEffect;
}
private:
void RemoveSBDeps();
// current background color
D3DCOLOR clrColor;
// current background texture
IDirect3DBaseTexture9* pcTexture;
ID3DXEffect* piSkyBoxEffect;
// current background mode
MODE eMode;
// path to the texture
std::string szPath;
// transformation matrix for the skybox
aiMatrix4x4 mMatrix;
};
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#pragma once
namespace AssimpView
{
class CBackgroundPainter
{
CBackgroundPainter()
:
clrColor( D3DCOLOR_ARGB( 0xFF, 100, 100, 100 ) ),
pcTexture( NULL ),
piSkyBoxEffect( NULL ),
eMode( SIMPLE_COLOR )
{}
public:
// Supported background draw modi
enum MODE { SIMPLE_COLOR, TEXTURE_2D, TEXTURE_CUBE };
// Singleton accessors
static CBackgroundPainter s_cInstance;
inline static CBackgroundPainter& Instance()
{
return s_cInstance;
}
// set the current background color
// (this removes any textures loaded)
void SetColor( D3DCOLOR p_clrNew );
// Setup a cubemap/a 2d texture as background
void SetCubeMapBG( const char* p_szPath );
void SetTextureBG( const char* p_szPath );
// Called by the render loop
void OnPreRender();
void OnPostRender();
// Release any native resources associated with the instance
void ReleaseNativeResource();
// Recreate any native resources associated with the instance
void RecreateNativeResource();
// Rotate the skybox
void RotateSB( const aiMatrix4x4* pm );
// Reset the state of the skybox
void ResetSB();
inline MODE GetMode() const
{
return this->eMode;
}
inline IDirect3DBaseTexture9* GetTexture()
{
return this->pcTexture;
}
inline ID3DXBaseEffect* GetEffect()
{
return this->piSkyBoxEffect;
}
private:
void RemoveSBDeps();
// current background color
D3DCOLOR clrColor;
// current background texture
IDirect3DBaseTexture9* pcTexture;
ID3DXEffect* piSkyBoxEffect;
// current background mode
MODE eMode;
// path to the texture
std::string szPath;
// transformation matrix for the skybox
aiMatrix4x4 mMatrix;
};
}

View File

@ -1,85 +1,85 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#if (!defined AV_CAMERA_H_INCLUDED)
#define AV_CAMERA_H_INCLUDED
//-------------------------------------------------------------------------------
/** \brief Camera class
*/
//-------------------------------------------------------------------------------
class Camera
{
public:
Camera ()
:
vPos(0.0f,0.0f,-10.0f),
vUp(0.0f,1.0f,0.0f),
vLookAt(0.0f,0.0f,1.0f),
vRight(0.0f,1.0f,0.0f)
{
}
public:
// position of the camera
aiVector3D vPos;
// up-vector of the camera
aiVector3D vUp;
// camera's looking point is vPos + vLookAt
aiVector3D vLookAt;
// right vector of the camera
aiVector3D vRight;
// Equation
// (vRight ^ vUp) - vLookAt == 0
// needn't apply
} ;
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#if (!defined AV_CAMERA_H_INCLUDED)
#define AV_CAMERA_H_INCLUDED
//-------------------------------------------------------------------------------
/** \brief Camera class
*/
//-------------------------------------------------------------------------------
class Camera
{
public:
Camera ()
:
vPos(0.0f,0.0f,-10.0f),
vUp(0.0f,1.0f,0.0f),
vLookAt(0.0f,0.0f,1.0f),
vRight(0.0f,1.0f,0.0f)
{
}
public:
// position of the camera
aiVector3D vPos;
// up-vector of the camera
aiVector3D vUp;
// camera's looking point is vPos + vLookAt
aiVector3D vLookAt;
// right vector of the camera
aiVector3D vRight;
// Equation
// (vRight ^ vUp) - vLookAt == 0
// needn't apply
} ;
#endif // !!IG

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,108 +1,108 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
#include "richedit.h"
namespace AssimpView {
//-------------------------------------------------------------------------------
// Message procedure for the help dialog
//-------------------------------------------------------------------------------
INT_PTR CALLBACK HelpDialogProc(HWND hwndDlg,UINT uMsg,
WPARAM wParam,LPARAM lParam)
{
(void)lParam;
switch (uMsg)
{
case WM_INITDIALOG:
{
// load the help file ...
HRSRC res = FindResource(NULL,MAKEINTRESOURCE(IDR_TEXT1),"TEXT");
HGLOBAL hg = LoadResource(NULL,res);
void* pData = LockResource(hg);
SETTEXTEX sInfo;
sInfo.flags = ST_DEFAULT;
sInfo.codepage = CP_ACP;
SendDlgItemMessage(hwndDlg,IDC_RICHEDIT21,
EM_SETTEXTEX,(WPARAM)&sInfo,( LPARAM) pData);
FreeResource(hg);
return TRUE;
}
case WM_CLOSE:
EndDialog(hwndDlg,0);
return TRUE;
case WM_COMMAND:
if (IDOK == LOWORD(wParam))
{
EndDialog(hwndDlg,0);
return TRUE;
}
case WM_PAINT:
{
PAINTSTRUCT sPaint;
HDC hdc = BeginPaint(hwndDlg,&sPaint);
HBRUSH hBrush = CreateSolidBrush(RGB(0xFF,0xFF,0xFF));
RECT sRect;
sRect.left = 0;
sRect.top = 26;
sRect.right = 1000;
sRect.bottom = 507;
FillRect(hdc, &sRect, hBrush);
EndPaint(hwndDlg,&sPaint);
return TRUE;
}
};
return FALSE;
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
#include "richedit.h"
namespace AssimpView {
//-------------------------------------------------------------------------------
// Message procedure for the help dialog
//-------------------------------------------------------------------------------
INT_PTR CALLBACK HelpDialogProc(HWND hwndDlg,UINT uMsg,
WPARAM wParam,LPARAM lParam)
{
(void)lParam;
switch (uMsg)
{
case WM_INITDIALOG:
{
// load the help file ...
HRSRC res = FindResource(NULL,MAKEINTRESOURCE(IDR_TEXT1),"TEXT");
HGLOBAL hg = LoadResource(NULL,res);
void* pData = LockResource(hg);
SETTEXTEX sInfo;
sInfo.flags = ST_DEFAULT;
sInfo.codepage = CP_ACP;
SendDlgItemMessage(hwndDlg,IDC_RICHEDIT21,
EM_SETTEXTEX,(WPARAM)&sInfo,( LPARAM) pData);
FreeResource(hg);
return TRUE;
}
case WM_CLOSE:
EndDialog(hwndDlg,0);
return TRUE;
case WM_COMMAND:
if (IDOK == LOWORD(wParam))
{
EndDialog(hwndDlg,0);
return TRUE;
}
case WM_PAINT:
{
PAINTSTRUCT sPaint;
HDC hdc = BeginPaint(hwndDlg,&sPaint);
HBRUSH hBrush = CreateSolidBrush(RGB(0xFF,0xFF,0xFF));
RECT sRect;
sRect.left = 0;
sRect.top = 26;
sRect.right = 1000;
sRect.bottom = 507;
FillRect(hdc, &sRect, hBrush);
EndPaint(hwndDlg,&sPaint);
return TRUE;
}
};
return FALSE;
}
};

View File

@ -1,372 +1,372 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
namespace AssimpView {
//-------------------------------------------------------------------------------
// Handle mouse input for the FPS input behaviour
//
// Movement in x and y axis is possible
//-------------------------------------------------------------------------------
void HandleMouseInputFPS( void )
{
POINT mousePos;
GetCursorPos( &mousePos );
ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
g_mousePos.x = mousePos.x;
g_mousePos.y = mousePos.y;
D3DXMATRIX matRotation;
if (g_bMousePressed)
{
int nXDiff = (g_mousePos.x - g_LastmousePos.x);
int nYDiff = (g_mousePos.y - g_LastmousePos.y);
if( 0 != nYDiff)
{
D3DXMatrixRotationAxis( &matRotation, (D3DXVECTOR3*)& g_sCamera.vRight, D3DXToRadian((float)nYDiff / 6.0f));
D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)& g_sCamera.vLookAt, &matRotation );
D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vUp, (D3DXVECTOR3*)&g_sCamera.vUp, &matRotation );
}
if( 0 != nXDiff )
{
D3DXVECTOR3 v(0,1,0);
D3DXMatrixRotationAxis( &matRotation, (D3DXVECTOR3*)&g_sCamera.vUp, D3DXToRadian((float)nXDiff / 6.0f) );
D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)&g_sCamera.vLookAt, &matRotation );
D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vRight,(D3DXVECTOR3*) &g_sCamera.vRight, &matRotation );
}
}
g_LastmousePos.x = g_mousePos.x;
g_LastmousePos.y = g_mousePos.y;
}
//-------------------------------------------------------------------------------
// Handle mouse input for the FPS input behaviour
//
// Movement in x and y axis is possible
//-------------------------------------------------------------------------------
void HandleMouseInputTextureView( void )
{
POINT mousePos;
GetCursorPos( &mousePos );
ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
g_mousePos.x = mousePos.x;
g_mousePos.y = mousePos.y;
D3DXMATRIX matRotation;
if (g_bMousePressed)
{
CDisplay::Instance().SetTextureViewOffsetX((float)(g_mousePos.x - g_LastmousePos.x));
CDisplay::Instance().SetTextureViewOffsetY((float)(g_mousePos.y - g_LastmousePos.y));
}
g_LastmousePos.x = g_mousePos.x;
g_LastmousePos.y = g_mousePos.y;
}
//-------------------------------------------------------------------------------
// handle mouse input for the light rotation
//
// Axes: global x/y axis
//-------------------------------------------------------------------------------
void HandleMouseInputLightRotate( void )
{
POINT mousePos;
GetCursorPos( &mousePos );
ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
g_mousePos.x = mousePos.x;
g_mousePos.y = mousePos.y;
if (g_bMousePressedR)
{
int nXDiff = -(g_mousePos.x - g_LastmousePos.x);
int nYDiff = -(g_mousePos.y - g_LastmousePos.y);
aiVector3D v = aiVector3D(1.0f,0.0f,0.0f);
aiMatrix4x4 mTemp;
D3DXMatrixRotationAxis( (D3DXMATRIX*) &mTemp, (D3DXVECTOR3*)&v, D3DXToRadian((float)nYDiff / 2.0f));
D3DXVec3TransformCoord((D3DXVECTOR3*)&g_avLightDirs[0],
(const D3DXVECTOR3*)&g_avLightDirs[0],(const D3DXMATRIX*)&mTemp);
v = aiVector3D(0.0f,1.0f,0.0f);
D3DXMatrixRotationAxis( (D3DXMATRIX*) &mTemp, (D3DXVECTOR3*)&v, D3DXToRadian((float)nXDiff / 2.0f));
D3DXVec3TransformCoord((D3DXVECTOR3*)&g_avLightDirs[0],
(const D3DXVECTOR3*)&g_avLightDirs[0],(const D3DXMATRIX*)&mTemp);
}
return;
}
//-------------------------------------------------------------------------------
// Handle mouse input for movements of the skybox
//
// The skybox can be moved by holding both the left and the right mouse button
// pressed. Rotation is possible in x and y direction.
//-------------------------------------------------------------------------------
void HandleMouseInputSkyBox( void )
{
POINT mousePos;
GetCursorPos( &mousePos );
ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
g_mousePos.x = mousePos.x;
g_mousePos.y = mousePos.y;
aiMatrix4x4 matRotation;
if (g_bMousePressedBoth )
{
int nXDiff = -(g_mousePos.x - g_LastmousePos.x);
int nYDiff = -(g_mousePos.y - g_LastmousePos.y);
aiMatrix4x4 matWorld;
if( 0 != nYDiff)
{
aiVector3D v = aiVector3D(1.0f,0.0f,0.0f);
D3DXMatrixRotationAxis( (D3DXMATRIX*) &matWorld, (D3DXVECTOR3*)&v, D3DXToRadian((float)nYDiff / 2.0f));
CBackgroundPainter::Instance().RotateSB(&matWorld);
}
if( 0 != nXDiff)
{
aiMatrix4x4 matWorldOld;
if( 0 != nYDiff)
{
matWorldOld = matWorld;
}
aiVector3D v = aiVector3D(0.0f,1.0f,0.0f);
D3DXMatrixRotationAxis( (D3DXMATRIX*)&matWorld, (D3DXVECTOR3*)&v, D3DXToRadian((float)nXDiff / 2.0f) );
matWorld = matWorldOld * matWorld;
CBackgroundPainter::Instance().RotateSB(&matWorld);
}
}
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
void HandleMouseInputLightIntensityAndColor( void )
{
POINT mousePos;
GetCursorPos( &mousePos );
ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
g_mousePos.x = mousePos.x;
g_mousePos.y = mousePos.y;
if (g_bMousePressedM)
{
int nXDiff = -(g_mousePos.x - g_LastmousePos.x);
int nYDiff = -(g_mousePos.y - g_LastmousePos.y);
g_fLightIntensity -= (float)nXDiff / 400.0f;
if ((nYDiff > 2 || nYDiff < -2) && (nXDiff < 20 && nXDiff > -20))
{
if (!g_bFPSView)
{
g_sCamera.vPos.z += nYDiff / 120.0f;
}
else
{
g_sCamera.vPos += (nYDiff / 120.0f) * g_sCamera.vLookAt.Normalize();
}
}
}
return;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
void HandleMouseInputLocal( void )
{
POINT mousePos;
GetCursorPos( &mousePos );
ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
g_mousePos.x = mousePos.x;
g_mousePos.y = mousePos.y;
aiMatrix4x4 matRotation;
if (g_bMousePressed)
{
int nXDiff = -(g_mousePos.x - g_LastmousePos.x);
int nYDiff = -(g_mousePos.y - g_LastmousePos.y);
aiMatrix4x4 matWorld;
if (g_eClick != EClickPos_Outside)
{
if( 0 != nYDiff && g_eClick != EClickPos_CircleHor)
{
aiVector3D v = aiVector3D(1.0f,0.0f,0.0f);
D3DXMatrixRotationAxis( (D3DXMATRIX*) &matWorld, (D3DXVECTOR3*)&v, D3DXToRadian((float)nYDiff / 2.0f));
g_mWorldRotate = g_mWorldRotate * matWorld;
}
if( 0 != nXDiff && g_eClick != EClickPos_CircleVert)
{
aiVector3D v = aiVector3D(0.0f,1.0f,0.0f);
D3DXMatrixRotationAxis( (D3DXMATRIX*)&matWorld, (D3DXVECTOR3*)&v, D3DXToRadian((float)nXDiff / 2.0f) );
g_mWorldRotate = g_mWorldRotate * matWorld;
}
}
else
{
if(0 != nYDiff || 0 != nXDiff)
{
// rotate around the z-axis
RECT sRect;
GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect);
sRect.right -= sRect.left;
sRect.bottom -= sRect.top;
int xPos = g_mousePos.x - sRect.right/2;
int yPos = g_mousePos.y - sRect.bottom/2;
float fXDist = (float)xPos;
float fYDist = (float)yPos / sqrtf((float)(yPos * yPos + xPos * xPos));
bool bSign1;
if (fXDist < 0.0f)bSign1 = false;
else bSign1 = true;
float fAngle = asin(fYDist);
xPos = g_LastmousePos.x - sRect.right/2;
yPos = g_LastmousePos.y - sRect.bottom/2;
fXDist = (float)xPos;
fYDist = (float)yPos / sqrtf((float)(yPos * yPos + xPos * xPos));
bool bSign2;
if (fXDist < 0.0f)bSign2 = false;
else bSign2 = true;
float fAngle2 = asin(fYDist);
fAngle -= fAngle2;
if (bSign1 != bSign2)
{
g_bInvert = !g_bInvert;
}
if (g_bInvert)fAngle *= -1.0f;
aiVector3D v = aiVector3D(0.0f,0.0f,1.0f);
D3DXMatrixRotationAxis( (D3DXMATRIX*)&matWorld, (D3DXVECTOR3*)&v, (float) (fAngle * 1.2) );
g_mWorldRotate = g_mWorldRotate * matWorld;
}
}
}
g_LastmousePos.x = g_mousePos.x;
g_LastmousePos.y = g_mousePos.y;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
void HandleKeyboardInputFPS( void )
{
unsigned char keys[256];
GetKeyboardState( keys );
aiVector3D tmpLook = g_sCamera.vLookAt;
aiVector3D tmpRight = g_sCamera.vRight;
aiVector3D vOldPos = g_sCamera.vPos;
// Up Arrow Key - View moves forward
if( keys[VK_UP] & 0x80 )
g_sCamera.vPos -= (tmpLook*-MOVE_SPEED)*g_fElpasedTime;
// Down Arrow Key - View moves backward
if( keys[VK_DOWN] & 0x80 )
g_sCamera.vPos += (tmpLook*-MOVE_SPEED)*g_fElpasedTime;
// Left Arrow Key - View side-steps or strafes to the left
if( keys[VK_LEFT] & 0x80 )
g_sCamera.vPos -= (tmpRight*MOVE_SPEED)*g_fElpasedTime;
// Right Arrow Key - View side-steps or strafes to the right
if( keys[VK_RIGHT] & 0x80 )
g_sCamera.vPos += (tmpRight*MOVE_SPEED)*g_fElpasedTime;
// Home Key - View elevates up
if( keys[VK_HOME] & 0x80 )
g_sCamera.vPos .y += MOVE_SPEED*g_fElpasedTime;
// End Key - View elevates down
if( keys[VK_END] & 0x80 )
g_sCamera.vPos.y -= MOVE_SPEED*g_fElpasedTime;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
void HandleKeyboardInputTextureView( void )
{
unsigned char keys[256];
GetKeyboardState( keys );
// Up Arrow Key
if( keys[VK_UP] & 0x80 )
CDisplay::Instance().SetTextureViewOffsetY ( g_fElpasedTime * 150.0f );
// Down Arrow Key
if( keys[VK_DOWN] & 0x80 )
CDisplay::Instance().SetTextureViewOffsetY ( -g_fElpasedTime * 150.0f );
// Left Arrow Key
if( keys[VK_LEFT] & 0x80 )
CDisplay::Instance().SetTextureViewOffsetX ( g_fElpasedTime * 150.0f );
// Right Arrow Key
if( keys[VK_RIGHT] & 0x80 )
CDisplay::Instance().SetTextureViewOffsetX ( -g_fElpasedTime * 150.0f );
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
namespace AssimpView {
//-------------------------------------------------------------------------------
// Handle mouse input for the FPS input behaviour
//
// Movement in x and y axis is possible
//-------------------------------------------------------------------------------
void HandleMouseInputFPS( void )
{
POINT mousePos;
GetCursorPos( &mousePos );
ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
g_mousePos.x = mousePos.x;
g_mousePos.y = mousePos.y;
D3DXMATRIX matRotation;
if (g_bMousePressed)
{
int nXDiff = (g_mousePos.x - g_LastmousePos.x);
int nYDiff = (g_mousePos.y - g_LastmousePos.y);
if( 0 != nYDiff)
{
D3DXMatrixRotationAxis( &matRotation, (D3DXVECTOR3*)& g_sCamera.vRight, D3DXToRadian((float)nYDiff / 6.0f));
D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)& g_sCamera.vLookAt, &matRotation );
D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vUp, (D3DXVECTOR3*)&g_sCamera.vUp, &matRotation );
}
if( 0 != nXDiff )
{
D3DXVECTOR3 v(0,1,0);
D3DXMatrixRotationAxis( &matRotation, (D3DXVECTOR3*)&g_sCamera.vUp, D3DXToRadian((float)nXDiff / 6.0f) );
D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)&g_sCamera.vLookAt, &matRotation );
D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vRight,(D3DXVECTOR3*) &g_sCamera.vRight, &matRotation );
}
}
g_LastmousePos.x = g_mousePos.x;
g_LastmousePos.y = g_mousePos.y;
}
//-------------------------------------------------------------------------------
// Handle mouse input for the FPS input behaviour
//
// Movement in x and y axis is possible
//-------------------------------------------------------------------------------
void HandleMouseInputTextureView( void )
{
POINT mousePos;
GetCursorPos( &mousePos );
ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
g_mousePos.x = mousePos.x;
g_mousePos.y = mousePos.y;
D3DXMATRIX matRotation;
if (g_bMousePressed)
{
CDisplay::Instance().SetTextureViewOffsetX((float)(g_mousePos.x - g_LastmousePos.x));
CDisplay::Instance().SetTextureViewOffsetY((float)(g_mousePos.y - g_LastmousePos.y));
}
g_LastmousePos.x = g_mousePos.x;
g_LastmousePos.y = g_mousePos.y;
}
//-------------------------------------------------------------------------------
// handle mouse input for the light rotation
//
// Axes: global x/y axis
//-------------------------------------------------------------------------------
void HandleMouseInputLightRotate( void )
{
POINT mousePos;
GetCursorPos( &mousePos );
ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
g_mousePos.x = mousePos.x;
g_mousePos.y = mousePos.y;
if (g_bMousePressedR)
{
int nXDiff = -(g_mousePos.x - g_LastmousePos.x);
int nYDiff = -(g_mousePos.y - g_LastmousePos.y);
aiVector3D v = aiVector3D(1.0f,0.0f,0.0f);
aiMatrix4x4 mTemp;
D3DXMatrixRotationAxis( (D3DXMATRIX*) &mTemp, (D3DXVECTOR3*)&v, D3DXToRadian((float)nYDiff / 2.0f));
D3DXVec3TransformCoord((D3DXVECTOR3*)&g_avLightDirs[0],
(const D3DXVECTOR3*)&g_avLightDirs[0],(const D3DXMATRIX*)&mTemp);
v = aiVector3D(0.0f,1.0f,0.0f);
D3DXMatrixRotationAxis( (D3DXMATRIX*) &mTemp, (D3DXVECTOR3*)&v, D3DXToRadian((float)nXDiff / 2.0f));
D3DXVec3TransformCoord((D3DXVECTOR3*)&g_avLightDirs[0],
(const D3DXVECTOR3*)&g_avLightDirs[0],(const D3DXMATRIX*)&mTemp);
}
return;
}
//-------------------------------------------------------------------------------
// Handle mouse input for movements of the skybox
//
// The skybox can be moved by holding both the left and the right mouse button
// pressed. Rotation is possible in x and y direction.
//-------------------------------------------------------------------------------
void HandleMouseInputSkyBox( void )
{
POINT mousePos;
GetCursorPos( &mousePos );
ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
g_mousePos.x = mousePos.x;
g_mousePos.y = mousePos.y;
aiMatrix4x4 matRotation;
if (g_bMousePressedBoth )
{
int nXDiff = -(g_mousePos.x - g_LastmousePos.x);
int nYDiff = -(g_mousePos.y - g_LastmousePos.y);
aiMatrix4x4 matWorld;
if( 0 != nYDiff)
{
aiVector3D v = aiVector3D(1.0f,0.0f,0.0f);
D3DXMatrixRotationAxis( (D3DXMATRIX*) &matWorld, (D3DXVECTOR3*)&v, D3DXToRadian((float)nYDiff / 2.0f));
CBackgroundPainter::Instance().RotateSB(&matWorld);
}
if( 0 != nXDiff)
{
aiMatrix4x4 matWorldOld;
if( 0 != nYDiff)
{
matWorldOld = matWorld;
}
aiVector3D v = aiVector3D(0.0f,1.0f,0.0f);
D3DXMatrixRotationAxis( (D3DXMATRIX*)&matWorld, (D3DXVECTOR3*)&v, D3DXToRadian((float)nXDiff / 2.0f) );
matWorld = matWorldOld * matWorld;
CBackgroundPainter::Instance().RotateSB(&matWorld);
}
}
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
void HandleMouseInputLightIntensityAndColor( void )
{
POINT mousePos;
GetCursorPos( &mousePos );
ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
g_mousePos.x = mousePos.x;
g_mousePos.y = mousePos.y;
if (g_bMousePressedM)
{
int nXDiff = -(g_mousePos.x - g_LastmousePos.x);
int nYDiff = -(g_mousePos.y - g_LastmousePos.y);
g_fLightIntensity -= (float)nXDiff / 400.0f;
if ((nYDiff > 2 || nYDiff < -2) && (nXDiff < 20 && nXDiff > -20))
{
if (!g_bFPSView)
{
g_sCamera.vPos.z += nYDiff / 120.0f;
}
else
{
g_sCamera.vPos += (nYDiff / 120.0f) * g_sCamera.vLookAt.Normalize();
}
}
}
return;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
void HandleMouseInputLocal( void )
{
POINT mousePos;
GetCursorPos( &mousePos );
ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
g_mousePos.x = mousePos.x;
g_mousePos.y = mousePos.y;
aiMatrix4x4 matRotation;
if (g_bMousePressed)
{
int nXDiff = -(g_mousePos.x - g_LastmousePos.x);
int nYDiff = -(g_mousePos.y - g_LastmousePos.y);
aiMatrix4x4 matWorld;
if (g_eClick != EClickPos_Outside)
{
if( 0 != nYDiff && g_eClick != EClickPos_CircleHor)
{
aiVector3D v = aiVector3D(1.0f,0.0f,0.0f);
D3DXMatrixRotationAxis( (D3DXMATRIX*) &matWorld, (D3DXVECTOR3*)&v, D3DXToRadian((float)nYDiff / 2.0f));
g_mWorldRotate = g_mWorldRotate * matWorld;
}
if( 0 != nXDiff && g_eClick != EClickPos_CircleVert)
{
aiVector3D v = aiVector3D(0.0f,1.0f,0.0f);
D3DXMatrixRotationAxis( (D3DXMATRIX*)&matWorld, (D3DXVECTOR3*)&v, D3DXToRadian((float)nXDiff / 2.0f) );
g_mWorldRotate = g_mWorldRotate * matWorld;
}
}
else
{
if(0 != nYDiff || 0 != nXDiff)
{
// rotate around the z-axis
RECT sRect;
GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect);
sRect.right -= sRect.left;
sRect.bottom -= sRect.top;
int xPos = g_mousePos.x - sRect.right/2;
int yPos = g_mousePos.y - sRect.bottom/2;
float fXDist = (float)xPos;
float fYDist = (float)yPos / sqrtf((float)(yPos * yPos + xPos * xPos));
bool bSign1;
if (fXDist < 0.0f)bSign1 = false;
else bSign1 = true;
float fAngle = asin(fYDist);
xPos = g_LastmousePos.x - sRect.right/2;
yPos = g_LastmousePos.y - sRect.bottom/2;
fXDist = (float)xPos;
fYDist = (float)yPos / sqrtf((float)(yPos * yPos + xPos * xPos));
bool bSign2;
if (fXDist < 0.0f)bSign2 = false;
else bSign2 = true;
float fAngle2 = asin(fYDist);
fAngle -= fAngle2;
if (bSign1 != bSign2)
{
g_bInvert = !g_bInvert;
}
if (g_bInvert)fAngle *= -1.0f;
aiVector3D v = aiVector3D(0.0f,0.0f,1.0f);
D3DXMatrixRotationAxis( (D3DXMATRIX*)&matWorld, (D3DXVECTOR3*)&v, (float) (fAngle * 1.2) );
g_mWorldRotate = g_mWorldRotate * matWorld;
}
}
}
g_LastmousePos.x = g_mousePos.x;
g_LastmousePos.y = g_mousePos.y;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
void HandleKeyboardInputFPS( void )
{
unsigned char keys[256];
GetKeyboardState( keys );
aiVector3D tmpLook = g_sCamera.vLookAt;
aiVector3D tmpRight = g_sCamera.vRight;
aiVector3D vOldPos = g_sCamera.vPos;
// Up Arrow Key - View moves forward
if( keys[VK_UP] & 0x80 )
g_sCamera.vPos -= (tmpLook*-MOVE_SPEED)*g_fElpasedTime;
// Down Arrow Key - View moves backward
if( keys[VK_DOWN] & 0x80 )
g_sCamera.vPos += (tmpLook*-MOVE_SPEED)*g_fElpasedTime;
// Left Arrow Key - View side-steps or strafes to the left
if( keys[VK_LEFT] & 0x80 )
g_sCamera.vPos -= (tmpRight*MOVE_SPEED)*g_fElpasedTime;
// Right Arrow Key - View side-steps or strafes to the right
if( keys[VK_RIGHT] & 0x80 )
g_sCamera.vPos += (tmpRight*MOVE_SPEED)*g_fElpasedTime;
// Home Key - View elevates up
if( keys[VK_HOME] & 0x80 )
g_sCamera.vPos .y += MOVE_SPEED*g_fElpasedTime;
// End Key - View elevates down
if( keys[VK_END] & 0x80 )
g_sCamera.vPos.y -= MOVE_SPEED*g_fElpasedTime;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
void HandleKeyboardInputTextureView( void )
{
unsigned char keys[256];
GetKeyboardState( keys );
// Up Arrow Key
if( keys[VK_UP] & 0x80 )
CDisplay::Instance().SetTextureViewOffsetY ( g_fElpasedTime * 150.0f );
// Down Arrow Key
if( keys[VK_DOWN] & 0x80 )
CDisplay::Instance().SetTextureViewOffsetY ( -g_fElpasedTime * 150.0f );
// Left Arrow Key
if( keys[VK_LEFT] & 0x80 )
CDisplay::Instance().SetTextureViewOffsetX ( g_fElpasedTime * 150.0f );
// Right Arrow Key
if( keys[VK_RIGHT] & 0x80 )
CDisplay::Instance().SetTextureViewOffsetX ( -g_fElpasedTime * 150.0f );
}
};

View File

@ -1,233 +1,233 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
namespace AssimpView {
CLogDisplay CLogDisplay::s_cInstance;
//-------------------------------------------------------------------------------
void CLogDisplay::AddEntry(const std::string& szText,
const D3DCOLOR clrColor)
{
SEntry sNew;
sNew.clrColor = clrColor;
sNew.szText = szText;
sNew.dwStartTicks = (DWORD)GetTickCount();
this->asEntries.push_back(sNew);
}
//-------------------------------------------------------------------------------
void CLogDisplay::ReleaseNativeResource()
{
if (this->piFont)
{
this->piFont->Release();
this->piFont = NULL;
}
}
//-------------------------------------------------------------------------------
void CLogDisplay::RecreateNativeResource()
{
if (!this->piFont)
{
if (FAILED(D3DXCreateFont(g_piDevice,
16, //Font height
0, //Font width
FW_BOLD, //Font Weight
1, //MipLevels
false, //Italic
DEFAULT_CHARSET, //CharSet
OUT_DEFAULT_PRECIS, //OutputPrecision
//CLEARTYPE_QUALITY, //Quality
5, //Quality
DEFAULT_PITCH|FF_DONTCARE, //PitchAndFamily
"Verdana", //pFacename,
&this->piFont)))
{
CLogDisplay::Instance().AddEntry("Unable to load font",D3DCOLOR_ARGB(0xFF,0xFF,0,0));
this->piFont = NULL;
return;
}
}
return;
}
//-------------------------------------------------------------------------------
void CLogDisplay::OnRender()
{
DWORD dwTick = (DWORD) GetTickCount();
DWORD dwLimit = dwTick - 8000;
DWORD dwLimit2 = dwLimit + 3000;
unsigned int iCnt = 0;
RECT sRect;
sRect.left = 10;
sRect.top = 10;
RECT sWndRect;
GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sWndRect);
sWndRect.right -= sWndRect.left;
sWndRect.bottom -= sWndRect.top;
sWndRect.left = sWndRect.top = 0;
sRect.right = sWndRect.right - 30;
sRect.bottom = sWndRect.bottom;
// if no asset is loaded draw a "no asset loaded" text in the center
if (!g_pcAsset)
{
const char* szText = "Nothing to display ... \r\nTry [Viewer | Open asset] to load an asset";
// shadow
RECT sCopy;
sCopy.left = sWndRect.left+1;
sCopy.top = sWndRect.top+1;
sCopy.bottom = sWndRect.bottom+1;
sCopy.right = sWndRect.right+1;
this->piFont->DrawText(NULL,szText ,
-1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
sCopy.left = sWndRect.left+1;
sCopy.top = sWndRect.top+1;
sCopy.bottom = sWndRect.bottom-1;
sCopy.right = sWndRect.right-1;
this->piFont->DrawText(NULL,szText ,
-1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
sCopy.left = sWndRect.left-1;
sCopy.top = sWndRect.top-1;
sCopy.bottom = sWndRect.bottom+1;
sCopy.right = sWndRect.right+1;
this->piFont->DrawText(NULL,szText ,
-1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
sCopy.left = sWndRect.left-1;
sCopy.top = sWndRect.top-1;
sCopy.bottom = sWndRect.bottom-1;
sCopy.right = sWndRect.right-1;
this->piFont->DrawText(NULL,szText ,
-1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
// text
this->piFont->DrawText(NULL,szText ,
-1,&sWndRect,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0xFF));
}
// update all elements in the queue and render them
for (std::list<SEntry>::iterator
i = this->asEntries.begin();
i != this->asEntries.end();++i,++iCnt)
{
if ((*i).dwStartTicks < dwLimit)
{
i = this->asEntries.erase(i);
if(i == this->asEntries.end())break;
}
else if (NULL != this->piFont)
{
float fAlpha = 1.0f;
if ((*i).dwStartTicks <= dwLimit2)
{
// linearly interpolate to create the fade out effect
fAlpha = 1.0f - (float)(dwLimit2 - (*i).dwStartTicks) / 3000.0f;
}
D3DCOLOR& clrColor = (*i).clrColor;
clrColor &= ~(0xFFu << 24);
clrColor |= (((unsigned char)(fAlpha * 255.0f)) & 0xFFu) << 24;
const char* szText = (*i).szText.c_str();
if (sRect.top + 30 > sWndRect.bottom)
{
// end of window. send a special message
szText = "... too many errors";
clrColor = D3DCOLOR_ARGB(0xFF,0xFF,100,0x0);
}
// draw the black shadow
RECT sCopy;
sCopy.left = sRect.left+1;
sCopy.top = sRect.top+1;
sCopy.bottom = sRect.bottom+1;
sCopy.right = sRect.right+1;
this->piFont->DrawText(NULL,szText,
-1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
(unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
sCopy.left = sRect.left-1;
sCopy.top = sRect.top-1;
sCopy.bottom = sRect.bottom-1;
sCopy.right = sRect.right-1;
this->piFont->DrawText(NULL,szText,
-1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
(unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
sCopy.left = sRect.left-1;
sCopy.top = sRect.top-1;
sCopy.bottom = sRect.bottom+1;
sCopy.right = sRect.right+1;
this->piFont->DrawText(NULL,szText,
-1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
(unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
sCopy.left = sRect.left+1;
sCopy.top = sRect.top+1;
sCopy.bottom = sRect.bottom-1;
sCopy.right = sRect.right-1;
this->piFont->DrawText(NULL,szText,
-1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
(unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
// draw the text itself
int iPX = this->piFont->DrawText(NULL,szText,
-1,&sRect,DT_RIGHT | DT_TOP,clrColor);
sRect.top += iPX;
sRect.bottom += iPX;
if (szText != (*i).szText.c_str())break;
}
}
return;
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
namespace AssimpView {
CLogDisplay CLogDisplay::s_cInstance;
//-------------------------------------------------------------------------------
void CLogDisplay::AddEntry(const std::string& szText,
const D3DCOLOR clrColor)
{
SEntry sNew;
sNew.clrColor = clrColor;
sNew.szText = szText;
sNew.dwStartTicks = (DWORD)GetTickCount();
this->asEntries.push_back(sNew);
}
//-------------------------------------------------------------------------------
void CLogDisplay::ReleaseNativeResource()
{
if (this->piFont)
{
this->piFont->Release();
this->piFont = NULL;
}
}
//-------------------------------------------------------------------------------
void CLogDisplay::RecreateNativeResource()
{
if (!this->piFont)
{
if (FAILED(D3DXCreateFont(g_piDevice,
16, //Font height
0, //Font width
FW_BOLD, //Font Weight
1, //MipLevels
false, //Italic
DEFAULT_CHARSET, //CharSet
OUT_DEFAULT_PRECIS, //OutputPrecision
//CLEARTYPE_QUALITY, //Quality
5, //Quality
DEFAULT_PITCH|FF_DONTCARE, //PitchAndFamily
"Verdana", //pFacename,
&this->piFont)))
{
CLogDisplay::Instance().AddEntry("Unable to load font",D3DCOLOR_ARGB(0xFF,0xFF,0,0));
this->piFont = NULL;
return;
}
}
return;
}
//-------------------------------------------------------------------------------
void CLogDisplay::OnRender()
{
DWORD dwTick = (DWORD) GetTickCount();
DWORD dwLimit = dwTick - 8000;
DWORD dwLimit2 = dwLimit + 3000;
unsigned int iCnt = 0;
RECT sRect;
sRect.left = 10;
sRect.top = 10;
RECT sWndRect;
GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sWndRect);
sWndRect.right -= sWndRect.left;
sWndRect.bottom -= sWndRect.top;
sWndRect.left = sWndRect.top = 0;
sRect.right = sWndRect.right - 30;
sRect.bottom = sWndRect.bottom;
// if no asset is loaded draw a "no asset loaded" text in the center
if (!g_pcAsset)
{
const char* szText = "Nothing to display ... \r\nTry [Viewer | Open asset] to load an asset";
// shadow
RECT sCopy;
sCopy.left = sWndRect.left+1;
sCopy.top = sWndRect.top+1;
sCopy.bottom = sWndRect.bottom+1;
sCopy.right = sWndRect.right+1;
this->piFont->DrawText(NULL,szText ,
-1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
sCopy.left = sWndRect.left+1;
sCopy.top = sWndRect.top+1;
sCopy.bottom = sWndRect.bottom-1;
sCopy.right = sWndRect.right-1;
this->piFont->DrawText(NULL,szText ,
-1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
sCopy.left = sWndRect.left-1;
sCopy.top = sWndRect.top-1;
sCopy.bottom = sWndRect.bottom+1;
sCopy.right = sWndRect.right+1;
this->piFont->DrawText(NULL,szText ,
-1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
sCopy.left = sWndRect.left-1;
sCopy.top = sWndRect.top-1;
sCopy.bottom = sWndRect.bottom-1;
sCopy.right = sWndRect.right-1;
this->piFont->DrawText(NULL,szText ,
-1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
// text
this->piFont->DrawText(NULL,szText ,
-1,&sWndRect,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0xFF));
}
// update all elements in the queue and render them
for (std::list<SEntry>::iterator
i = this->asEntries.begin();
i != this->asEntries.end();++i,++iCnt)
{
if ((*i).dwStartTicks < dwLimit)
{
i = this->asEntries.erase(i);
if(i == this->asEntries.end())break;
}
else if (NULL != this->piFont)
{
float fAlpha = 1.0f;
if ((*i).dwStartTicks <= dwLimit2)
{
// linearly interpolate to create the fade out effect
fAlpha = 1.0f - (float)(dwLimit2 - (*i).dwStartTicks) / 3000.0f;
}
D3DCOLOR& clrColor = (*i).clrColor;
clrColor &= ~(0xFFu << 24);
clrColor |= (((unsigned char)(fAlpha * 255.0f)) & 0xFFu) << 24;
const char* szText = (*i).szText.c_str();
if (sRect.top + 30 > sWndRect.bottom)
{
// end of window. send a special message
szText = "... too many errors";
clrColor = D3DCOLOR_ARGB(0xFF,0xFF,100,0x0);
}
// draw the black shadow
RECT sCopy;
sCopy.left = sRect.left+1;
sCopy.top = sRect.top+1;
sCopy.bottom = sRect.bottom+1;
sCopy.right = sRect.right+1;
this->piFont->DrawText(NULL,szText,
-1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
(unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
sCopy.left = sRect.left-1;
sCopy.top = sRect.top-1;
sCopy.bottom = sRect.bottom-1;
sCopy.right = sRect.right-1;
this->piFont->DrawText(NULL,szText,
-1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
(unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
sCopy.left = sRect.left-1;
sCopy.top = sRect.top-1;
sCopy.bottom = sRect.bottom+1;
sCopy.right = sRect.right+1;
this->piFont->DrawText(NULL,szText,
-1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
(unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
sCopy.left = sRect.left+1;
sCopy.top = sRect.top+1;
sCopy.bottom = sRect.bottom-1;
sCopy.right = sRect.right-1;
this->piFont->DrawText(NULL,szText,
-1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
(unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
// draw the text itself
int iPX = this->piFont->DrawText(NULL,szText,
-1,&sRect,DT_RIGHT | DT_TOP,clrColor);
sRect.top += iPX;
sRect.bottom += iPX;
if (szText != (*i).szText.c_str())break;
}
}
return;
}
};

View File

@ -1,99 +1,99 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#pragma once
#include <list>
namespace AssimpView
{
//-------------------------------------------------------------------------------
/** \brief Class to display log strings in the upper right corner of the view
*/
//-------------------------------------------------------------------------------
class CLogDisplay
{
private:
CLogDisplay() {}
public:
// data structure for an entry in the log queue
struct SEntry
{
SEntry()
:
clrColor( D3DCOLOR_ARGB( 0xFF, 0xFF, 0xFF, 0x00 ) ), dwStartTicks( 0 )
{}
std::string szText;
D3DCOLOR clrColor;
DWORD dwStartTicks;
};
// Singleton accessors
static CLogDisplay s_cInstance;
inline static CLogDisplay& Instance()
{
return s_cInstance;
}
// Add an entry to the log queue
void AddEntry( const std::string& szText,
const D3DCOLOR clrColor = D3DCOLOR_ARGB( 0xFF, 0xFF, 0xFF, 0x00 ) );
// Release any native resources associated with the instance
void ReleaseNativeResource();
// Recreate any native resources associated with the instance
void RecreateNativeResource();
// Called during the render loop
void OnRender();
private:
std::list<SEntry> asEntries;
ID3DXFont* piFont;
};
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#pragma once
#include <list>
namespace AssimpView
{
//-------------------------------------------------------------------------------
/** \brief Class to display log strings in the upper right corner of the view
*/
//-------------------------------------------------------------------------------
class CLogDisplay
{
private:
CLogDisplay() {}
public:
// data structure for an entry in the log queue
struct SEntry
{
SEntry()
:
clrColor( D3DCOLOR_ARGB( 0xFF, 0xFF, 0xFF, 0x00 ) ), dwStartTicks( 0 )
{}
std::string szText;
D3DCOLOR clrColor;
DWORD dwStartTicks;
};
// Singleton accessors
static CLogDisplay s_cInstance;
inline static CLogDisplay& Instance()
{
return s_cInstance;
}
// Add an entry to the log queue
void AddEntry( const std::string& szText,
const D3DCOLOR clrColor = D3DCOLOR_ARGB( 0xFF, 0xFF, 0xFF, 0x00 ) );
// Release any native resources associated with the instance
void ReleaseNativeResource();
// Recreate any native resources associated with the instance
void RecreateNativeResource();
// Called during the render loop
void OnRender();
private:
std::list<SEntry> asEntries;
ID3DXFont* piFont;
};
}

View File

@ -1,255 +1,255 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
#include "richedit.h"
namespace AssimpView {
CLogWindow CLogWindow::s_cInstance;
extern HKEY g_hRegistry;
// header for the RTF log file
static const char* AI_VIEW_RTF_LOG_HEADER =
"{\\rtf1"
"\\ansi"
"\\deff0"
"{"
"\\fonttbl{\\f0 Courier New;}"
"}"
"{\\colortbl;"
"\\red255\\green0\\blue0;" // red for errors
"\\red255\\green120\\blue0;" // orange for warnings
"\\red0\\green150\\blue0;" // green for infos
"\\red0\\green0\\blue180;" // blue for debug messages
"\\red0\\green0\\blue0;" // black for everything else
"}}";
//-------------------------------------------------------------------------------
// Message procedure for the log window
//-------------------------------------------------------------------------------
INT_PTR CALLBACK LogDialogProc(HWND hwndDlg,UINT uMsg,
WPARAM wParam,LPARAM lParam)
{
(void)lParam;
switch (uMsg)
{
case WM_INITDIALOG:
{
return TRUE;
}
case WM_SIZE:
{
int x = LOWORD(lParam);
int y = HIWORD(lParam);
SetWindowPos(GetDlgItem(hwndDlg,IDC_EDIT1),NULL,0,0,
x-10,y-12,SWP_NOMOVE|SWP_NOZORDER);
return TRUE;
}
case WM_CLOSE:
EndDialog(hwndDlg,0);
CLogWindow::Instance().bIsVisible = false;
return TRUE;
};
return FALSE;
}
//-------------------------------------------------------------------------------
void CLogWindow::Init ()
{
this->hwnd = ::CreateDialog(g_hInstance,MAKEINTRESOURCE(IDD_LOGVIEW),
NULL,&LogDialogProc);
if (!this->hwnd)
{
CLogDisplay::Instance().AddEntry("[ERROR] Unable to create logger window",
D3DCOLOR_ARGB(0xFF,0,0xFF,0));
}
// setup the log text
this->szText = AI_VIEW_RTF_LOG_HEADER;;
this->szPlainText = "";
}
//-------------------------------------------------------------------------------
void CLogWindow::Show()
{
if (this->hwnd)
{
ShowWindow(this->hwnd,SW_SHOW);
this->bIsVisible = true;
// contents aren't updated while the logger isn't displayed
this->Update();
}
}
//-------------------------------------------------------------------------------
void CMyLogStream::write(const char* message)
{
CLogWindow::Instance().WriteLine(message);
}
//-------------------------------------------------------------------------------
void CLogWindow::Clear()
{
this->szText = AI_VIEW_RTF_LOG_HEADER;;
this->szPlainText = "";
this->Update();
}
//-------------------------------------------------------------------------------
void CLogWindow::Update()
{
if (this->bIsVisible)
{
SETTEXTEX sInfo;
sInfo.flags = ST_DEFAULT;
sInfo.codepage = CP_ACP;
SendDlgItemMessage(this->hwnd,IDC_EDIT1,
EM_SETTEXTEX,(WPARAM)&sInfo,( LPARAM)this->szText.c_str());
}
}
//-------------------------------------------------------------------------------
void CLogWindow::Save()
{
char szFileName[MAX_PATH];
DWORD dwTemp = MAX_PATH;
if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LogDestination",NULL,NULL,
(BYTE*)szFileName,&dwTemp))
{
// Key was not found. Use C:
strcpy(szFileName,"");
}
else
{
// need to remove the file name
char* sz = strrchr(szFileName,'\\');
if (!sz)sz = strrchr(szFileName,'/');
if (!sz)*sz = 0;
}
OPENFILENAME sFilename1 = {
sizeof(OPENFILENAME),
g_hDlg,GetModuleHandle(NULL),
"Log files\0*.txt", NULL, 0, 1,
szFileName, MAX_PATH, NULL, 0, NULL,
"Save log to file",
OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
0, 1, ".txt", 0, NULL, NULL
};
if(GetSaveFileName(&sFilename1) == 0) return;
// Now store the file in the registry
RegSetValueExA(g_hRegistry,"LogDestination",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
FILE* pFile = fopen(szFileName,"wt");
fprintf(pFile,this->szPlainText.c_str());
fclose(pFile);
CLogDisplay::Instance().AddEntry("[INFO] The log file has been saved",
D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
}
//-------------------------------------------------------------------------------
void CLogWindow::WriteLine(const char* message)
{
this->szPlainText.append(message);
this->szPlainText.append("\r\n");
if (0 != this->szText.length())
{
this->szText.resize(this->szText.length()-1);
}
switch (message[0])
{
case 'e':
case 'E':
this->szText.append("{\\pard \\cf1 \\b \\fs18 ");
break;
case 'w':
case 'W':
this->szText.append("{\\pard \\cf2 \\b \\fs18 ");
break;
case 'i':
case 'I':
this->szText.append("{\\pard \\cf3 \\b \\fs18 ");
break;
case 'd':
case 'D':
this->szText.append("{\\pard \\cf4 \\b \\fs18 ");
break;
default:
this->szText.append("{\\pard \\cf5 \\b \\fs18 ");
break;
}
std::string _message = message;
for (unsigned int i = 0; i < _message.length();++i)
{
if ('\\' == _message[i] ||
'}' == _message[i] ||
'{' == _message[i])
{
_message.insert(i++,"\\");
}
}
this->szText.append(_message);
this->szText.append("\\par}}");
if (this->bIsVisible && this->bUpdate)
{
SETTEXTEX sInfo;
sInfo.flags = ST_DEFAULT;
sInfo.codepage = CP_ACP;
SendDlgItemMessage(this->hwnd,IDC_EDIT1,
EM_SETTEXTEX,(WPARAM)&sInfo,( LPARAM)this->szText.c_str());
}
return;
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
#include "richedit.h"
namespace AssimpView {
CLogWindow CLogWindow::s_cInstance;
extern HKEY g_hRegistry;
// header for the RTF log file
static const char* AI_VIEW_RTF_LOG_HEADER =
"{\\rtf1"
"\\ansi"
"\\deff0"
"{"
"\\fonttbl{\\f0 Courier New;}"
"}"
"{\\colortbl;"
"\\red255\\green0\\blue0;" // red for errors
"\\red255\\green120\\blue0;" // orange for warnings
"\\red0\\green150\\blue0;" // green for infos
"\\red0\\green0\\blue180;" // blue for debug messages
"\\red0\\green0\\blue0;" // black for everything else
"}}";
//-------------------------------------------------------------------------------
// Message procedure for the log window
//-------------------------------------------------------------------------------
INT_PTR CALLBACK LogDialogProc(HWND hwndDlg,UINT uMsg,
WPARAM wParam,LPARAM lParam)
{
(void)lParam;
switch (uMsg)
{
case WM_INITDIALOG:
{
return TRUE;
}
case WM_SIZE:
{
int x = LOWORD(lParam);
int y = HIWORD(lParam);
SetWindowPos(GetDlgItem(hwndDlg,IDC_EDIT1),NULL,0,0,
x-10,y-12,SWP_NOMOVE|SWP_NOZORDER);
return TRUE;
}
case WM_CLOSE:
EndDialog(hwndDlg,0);
CLogWindow::Instance().bIsVisible = false;
return TRUE;
};
return FALSE;
}
//-------------------------------------------------------------------------------
void CLogWindow::Init ()
{
this->hwnd = ::CreateDialog(g_hInstance,MAKEINTRESOURCE(IDD_LOGVIEW),
NULL,&LogDialogProc);
if (!this->hwnd)
{
CLogDisplay::Instance().AddEntry("[ERROR] Unable to create logger window",
D3DCOLOR_ARGB(0xFF,0,0xFF,0));
}
// setup the log text
this->szText = AI_VIEW_RTF_LOG_HEADER;;
this->szPlainText = "";
}
//-------------------------------------------------------------------------------
void CLogWindow::Show()
{
if (this->hwnd)
{
ShowWindow(this->hwnd,SW_SHOW);
this->bIsVisible = true;
// contents aren't updated while the logger isn't displayed
this->Update();
}
}
//-------------------------------------------------------------------------------
void CMyLogStream::write(const char* message)
{
CLogWindow::Instance().WriteLine(message);
}
//-------------------------------------------------------------------------------
void CLogWindow::Clear()
{
this->szText = AI_VIEW_RTF_LOG_HEADER;;
this->szPlainText = "";
this->Update();
}
//-------------------------------------------------------------------------------
void CLogWindow::Update()
{
if (this->bIsVisible)
{
SETTEXTEX sInfo;
sInfo.flags = ST_DEFAULT;
sInfo.codepage = CP_ACP;
SendDlgItemMessage(this->hwnd,IDC_EDIT1,
EM_SETTEXTEX,(WPARAM)&sInfo,( LPARAM)this->szText.c_str());
}
}
//-------------------------------------------------------------------------------
void CLogWindow::Save()
{
char szFileName[MAX_PATH];
DWORD dwTemp = MAX_PATH;
if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LogDestination",NULL,NULL,
(BYTE*)szFileName,&dwTemp))
{
// Key was not found. Use C:
strcpy(szFileName,"");
}
else
{
// need to remove the file name
char* sz = strrchr(szFileName,'\\');
if (!sz)sz = strrchr(szFileName,'/');
if (!sz)*sz = 0;
}
OPENFILENAME sFilename1 = {
sizeof(OPENFILENAME),
g_hDlg,GetModuleHandle(NULL),
"Log files\0*.txt", NULL, 0, 1,
szFileName, MAX_PATH, NULL, 0, NULL,
"Save log to file",
OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
0, 1, ".txt", 0, NULL, NULL
};
if(GetSaveFileName(&sFilename1) == 0) return;
// Now store the file in the registry
RegSetValueExA(g_hRegistry,"LogDestination",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
FILE* pFile = fopen(szFileName,"wt");
fprintf(pFile,this->szPlainText.c_str());
fclose(pFile);
CLogDisplay::Instance().AddEntry("[INFO] The log file has been saved",
D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
}
//-------------------------------------------------------------------------------
void CLogWindow::WriteLine(const char* message)
{
this->szPlainText.append(message);
this->szPlainText.append("\r\n");
if (0 != this->szText.length())
{
this->szText.resize(this->szText.length()-1);
}
switch (message[0])
{
case 'e':
case 'E':
this->szText.append("{\\pard \\cf1 \\b \\fs18 ");
break;
case 'w':
case 'W':
this->szText.append("{\\pard \\cf2 \\b \\fs18 ");
break;
case 'i':
case 'I':
this->szText.append("{\\pard \\cf3 \\b \\fs18 ");
break;
case 'd':
case 'D':
this->szText.append("{\\pard \\cf4 \\b \\fs18 ");
break;
default:
this->szText.append("{\\pard \\cf5 \\b \\fs18 ");
break;
}
std::string _message = message;
for (unsigned int i = 0; i < _message.length();++i)
{
if ('\\' == _message[i] ||
'}' == _message[i] ||
'{' == _message[i])
{
_message.insert(i++,"\\");
}
}
this->szText.append(_message);
this->szText.append("\\par}}");
if (this->bIsVisible && this->bUpdate)
{
SETTEXTEX sInfo;
sInfo.flags = ST_DEFAULT;
sInfo.codepage = CP_ACP;
SendDlgItemMessage(this->hwnd,IDC_EDIT1,
EM_SETTEXTEX,(WPARAM)&sInfo,( LPARAM)this->szText.c_str());
}
return;
}
}; //! AssimpView

View File

@ -1,133 +1,133 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#if (!defined AV_LOG_WINDOW_H_INCLUDED)
#define AV_LOG_WINDOW_H_INCLUDE
namespace AssimpView
{
//-------------------------------------------------------------------------------
/** \brief Subclass of Assimp::LogStream used to add all log messages to the
* log window.
*/
//-------------------------------------------------------------------------------
class CMyLogStream : public Assimp::LogStream
{
public:
/** @brief Implementation of the abstract method */
void write( const char* message );
};
//-------------------------------------------------------------------------------
/** \brief Class to display log strings in a separate window
*/
//-------------------------------------------------------------------------------
class CLogWindow
{
private:
friend class CMyLogStream;
friend INT_PTR CALLBACK LogDialogProc( HWND hwndDlg, UINT uMsg,
WPARAM wParam, LPARAM lParam );
CLogWindow() : hwnd( NULL ), bIsVisible( false ), bUpdate( true ) {}
public:
// Singleton accessors
static CLogWindow s_cInstance;
inline static CLogWindow& Instance()
{
return s_cInstance;
}
// initializes the log window
void Init();
// Shows the log window
void Show();
// Clears the log window
void Clear();
// Save the log window to an user-defined file
void Save();
// write a line to the log window
void WriteLine( const char* message );
// Set the bUpdate member
inline void SetAutoUpdate( bool b )
{
this->bUpdate = b;
}
// updates the log file
void Update();
private:
// Window handle
HWND hwnd;
// current text of the window (contains RTF tags)
std::string szText;
std::string szPlainText;
// is the log window currently visible?
bool bIsVisible;
// Specified whether each new log message updates the log automatically
bool bUpdate;
public:
// associated log stream
CMyLogStream* pcStream;
};
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#if (!defined AV_LOG_WINDOW_H_INCLUDED)
#define AV_LOG_WINDOW_H_INCLUDE
namespace AssimpView
{
//-------------------------------------------------------------------------------
/** \brief Subclass of Assimp::LogStream used to add all log messages to the
* log window.
*/
//-------------------------------------------------------------------------------
class CMyLogStream : public Assimp::LogStream
{
public:
/** @brief Implementation of the abstract method */
void write( const char* message );
};
//-------------------------------------------------------------------------------
/** \brief Class to display log strings in a separate window
*/
//-------------------------------------------------------------------------------
class CLogWindow
{
private:
friend class CMyLogStream;
friend INT_PTR CALLBACK LogDialogProc( HWND hwndDlg, UINT uMsg,
WPARAM wParam, LPARAM lParam );
CLogWindow() : hwnd( NULL ), bIsVisible( false ), bUpdate( true ) {}
public:
// Singleton accessors
static CLogWindow s_cInstance;
inline static CLogWindow& Instance()
{
return s_cInstance;
}
// initializes the log window
void Init();
// Shows the log window
void Show();
// Clears the log window
void Clear();
// Save the log window to an user-defined file
void Save();
// write a line to the log window
void WriteLine( const char* message );
// Set the bUpdate member
inline void SetAutoUpdate( bool b )
{
this->bUpdate = b;
}
// updates the log file
void Update();
private:
// Window handle
HWND hwnd;
// current text of the window (contains RTF tags)
std::string szText;
std::string szPlainText;
// is the log window currently visible?
bool bIsVisible;
// Specified whether each new log message updates the log automatically
bool bUpdate;
public:
// associated log stream
CMyLogStream* pcStream;
};
}
#endif // AV_LOG_DISPLA

File diff suppressed because it is too large Load Diff

View File

@ -1,208 +1,208 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#pragma once
#include <map>
#include "AssetHelper.h"
namespace AssimpView
{
//-------------------------------------------------------------------------------
/* Helper class to create, access and destroy materials
*/
//-------------------------------------------------------------------------------
class CMaterialManager
{
private:
friend class CDisplay;
// default constructor
CMaterialManager()
: m_iShaderCount( 0 ), sDefaultTexture() {}
~CMaterialManager() {
if( sDefaultTexture ) {
sDefaultTexture->Release();
}
Reset();
}
public:
//------------------------------------------------------------------
// Singleton accessors
static CMaterialManager s_cInstance;
inline static CMaterialManager& Instance()
{
return s_cInstance;
}
//------------------------------------------------------------------
// Delete all resources of a given material
//
// Must be called before CreateMaterial() to prevent memory leaking
void DeleteMaterial( AssetHelper::MeshHelper* pcIn );
//------------------------------------------------------------------
// Create the material for a mesh.
//
// The function checks whether an identical shader is already in use.
// A shader is considered to be identical if it has the same input
// signature and takes the same number of texture channels.
int CreateMaterial( AssetHelper::MeshHelper* pcMesh,
const aiMesh* pcSource );
//------------------------------------------------------------------
// Setup the material for a given mesh
// pcMesh Mesh to be rendered
// pcProj Projection matrix
// aiMe Current world matrix
// pcCam Camera matrix
// vPos Position of the camera
// TODO: Extract camera position from matrix ...
//
int SetupMaterial( AssetHelper::MeshHelper* pcMesh,
const aiMatrix4x4& pcProj,
const aiMatrix4x4& aiMe,
const aiMatrix4x4& pcCam,
const aiVector3D& vPos );
//------------------------------------------------------------------
// End the material for a given mesh
// Called after mesh rendering is complete
// pcMesh Mesh object
int EndMaterial( AssetHelper::MeshHelper* pcMesh );
//------------------------------------------------------------------
// Recreate all specular materials depending on the current
// specularity settings
//
// Diffuse-only materials are ignored.
// Must be called after specular highlights have been toggled
int UpdateSpecularMaterials();
//------------------------------------------------------------------
// find a valid path to a texture file
//
// Handle 8.3 syntax correctly, search the environment of the
// executable and the asset for a texture with a name very similar
// to a given one
int FindValidPath( aiString* p_szString );
//------------------------------------------------------------------
// Load a texture into memory and create a native D3D texture resource
//
// The function tries to find a valid path for a texture
int LoadTexture( IDirect3DTexture9** p_ppiOut, aiString* szPath );
//------------------------------------------------------------------
// Getter for m_iShaderCount
//
inline unsigned int GetShaderCount()
{
return this->m_iShaderCount;
}
//------------------------------------------------------------------
// Reset the state of the class
// Called whenever a new asset is loaded
inline void Reset()
{
this->m_iShaderCount = 0;
for( TextureCache::iterator it = sCachedTextures.begin(); it != sCachedTextures.end(); ++it ) {
( *it ).second->Release();
}
sCachedTextures.clear();
}
private:
//------------------------------------------------------------------
// find a valid path to a texture file
//
// Handle 8.3 syntax correctly, search the environment of the
// executable and the asset for a texture with a name very similar
// to a given one
bool TryLongerPath( char* szTemp, aiString* p_szString );
//------------------------------------------------------------------
// Setup the default texture for a texture channel
//
// Generates a default checker pattern for a texture
int SetDefaultTexture( IDirect3DTexture9** p_ppiOut );
//------------------------------------------------------------------
// Convert a height map to a normal map if necessary
//
// The function tries to detect the type of a texture automatically.
// However, this wont work in every case.
void HMtoNMIfNecessary( IDirect3DTexture9* piTexture,
IDirect3DTexture9** piTextureOut,
bool bWasOriginallyHM = true );
//------------------------------------------------------------------
// Search for non-opaque pixels in a texture
//
// A pixel is considered to be non-opaque if its alpha value is
// less than 255
//------------------------------------------------------------------
bool HasAlphaPixels( IDirect3DTexture9* piTexture );
private:
//
// Specifies the number of different shaders generated for
// the current asset. This number is incremented by CreateMaterial()
// each time a shader isn't found in cache and needs to be created
//
unsigned int m_iShaderCount;
IDirect3DTexture9* sDefaultTexture;
typedef std::map<std::string, IDirect3DTexture9*> TextureCache;
TextureCache sCachedTextures;
};
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#pragma once
#include <map>
#include "AssetHelper.h"
namespace AssimpView
{
//-------------------------------------------------------------------------------
/* Helper class to create, access and destroy materials
*/
//-------------------------------------------------------------------------------
class CMaterialManager
{
private:
friend class CDisplay;
// default constructor
CMaterialManager()
: m_iShaderCount( 0 ), sDefaultTexture() {}
~CMaterialManager() {
if( sDefaultTexture ) {
sDefaultTexture->Release();
}
Reset();
}
public:
//------------------------------------------------------------------
// Singleton accessors
static CMaterialManager s_cInstance;
inline static CMaterialManager& Instance()
{
return s_cInstance;
}
//------------------------------------------------------------------
// Delete all resources of a given material
//
// Must be called before CreateMaterial() to prevent memory leaking
void DeleteMaterial( AssetHelper::MeshHelper* pcIn );
//------------------------------------------------------------------
// Create the material for a mesh.
//
// The function checks whether an identical shader is already in use.
// A shader is considered to be identical if it has the same input
// signature and takes the same number of texture channels.
int CreateMaterial( AssetHelper::MeshHelper* pcMesh,
const aiMesh* pcSource );
//------------------------------------------------------------------
// Setup the material for a given mesh
// pcMesh Mesh to be rendered
// pcProj Projection matrix
// aiMe Current world matrix
// pcCam Camera matrix
// vPos Position of the camera
// TODO: Extract camera position from matrix ...
//
int SetupMaterial( AssetHelper::MeshHelper* pcMesh,
const aiMatrix4x4& pcProj,
const aiMatrix4x4& aiMe,
const aiMatrix4x4& pcCam,
const aiVector3D& vPos );
//------------------------------------------------------------------
// End the material for a given mesh
// Called after mesh rendering is complete
// pcMesh Mesh object
int EndMaterial( AssetHelper::MeshHelper* pcMesh );
//------------------------------------------------------------------
// Recreate all specular materials depending on the current
// specularity settings
//
// Diffuse-only materials are ignored.
// Must be called after specular highlights have been toggled
int UpdateSpecularMaterials();
//------------------------------------------------------------------
// find a valid path to a texture file
//
// Handle 8.3 syntax correctly, search the environment of the
// executable and the asset for a texture with a name very similar
// to a given one
int FindValidPath( aiString* p_szString );
//------------------------------------------------------------------
// Load a texture into memory and create a native D3D texture resource
//
// The function tries to find a valid path for a texture
int LoadTexture( IDirect3DTexture9** p_ppiOut, aiString* szPath );
//------------------------------------------------------------------
// Getter for m_iShaderCount
//
inline unsigned int GetShaderCount()
{
return this->m_iShaderCount;
}
//------------------------------------------------------------------
// Reset the state of the class
// Called whenever a new asset is loaded
inline void Reset()
{
this->m_iShaderCount = 0;
for( TextureCache::iterator it = sCachedTextures.begin(); it != sCachedTextures.end(); ++it ) {
( *it ).second->Release();
}
sCachedTextures.clear();
}
private:
//------------------------------------------------------------------
// find a valid path to a texture file
//
// Handle 8.3 syntax correctly, search the environment of the
// executable and the asset for a texture with a name very similar
// to a given one
bool TryLongerPath( char* szTemp, aiString* p_szString );
//------------------------------------------------------------------
// Setup the default texture for a texture channel
//
// Generates a default checker pattern for a texture
int SetDefaultTexture( IDirect3DTexture9** p_ppiOut );
//------------------------------------------------------------------
// Convert a height map to a normal map if necessary
//
// The function tries to detect the type of a texture automatically.
// However, this wont work in every case.
void HMtoNMIfNecessary( IDirect3DTexture9* piTexture,
IDirect3DTexture9** piTextureOut,
bool bWasOriginallyHM = true );
//------------------------------------------------------------------
// Search for non-opaque pixels in a texture
//
// A pixel is considered to be non-opaque if its alpha value is
// less than 255
//------------------------------------------------------------------
bool HasAlphaPixels( IDirect3DTexture9* piTexture );
private:
//
// Specifies the number of different shaders generated for
// the current asset. This number is incremented by CreateMaterial()
// each time a shader isn't found in cache and needs to be created
//
unsigned int m_iShaderCount;
IDirect3DTexture9* sDefaultTexture;
typedef std::map<std::string, IDirect3DTexture9*> TextureCache;
TextureCache sCachedTextures;
};
}

View File

@ -1,166 +1,166 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
#include <map>
#include <functional>
namespace AssimpView {
CMeshRenderer CMeshRenderer::s_cInstance;
//-------------------------------------------------------------------------------
int CMeshRenderer::DrawUnsorted(unsigned int iIndex)
{
ai_assert(iIndex < g_pcAsset->pcScene->mNumMeshes);
// set vertex and index buffer
g_piDevice->SetStreamSource(0,g_pcAsset->apcMeshes[iIndex]->piVB,0,
sizeof(AssetHelper::Vertex));
g_piDevice->SetIndices(g_pcAsset->apcMeshes[iIndex]->piIB);
D3DPRIMITIVETYPE type = D3DPT_POINTLIST;
switch (g_pcAsset->pcScene->mMeshes[iIndex]->mPrimitiveTypes) {
case aiPrimitiveType_POINT:
type = D3DPT_POINTLIST;break;
case aiPrimitiveType_LINE:
type = D3DPT_LINELIST;break;
case aiPrimitiveType_TRIANGLE:
type = D3DPT_TRIANGLELIST;break;
}
// and draw the mesh
g_piDevice->DrawIndexedPrimitive(type,
0,0,
g_pcAsset->pcScene->mMeshes[iIndex]->mNumVertices,0,
g_pcAsset->pcScene->mMeshes[iIndex]->mNumFaces);
return 1;
}
//-------------------------------------------------------------------------------
int CMeshRenderer::DrawSorted(unsigned int iIndex,const aiMatrix4x4& mWorld)
{
ai_assert(iIndex < g_pcAsset->pcScene->mNumMeshes);
AssetHelper::MeshHelper* pcHelper = g_pcAsset->apcMeshes[iIndex];
const aiMesh* pcMesh = g_pcAsset->pcScene->mMeshes[iIndex];
if (!pcHelper || !pcMesh || !pcHelper->piIB)
return -5;
if (pcMesh->mPrimitiveTypes != aiPrimitiveType_TRIANGLE || pcMesh->HasBones() || g_sOptions.bNoAlphaBlending)
return DrawUnsorted(iIndex);
// compute the position of the camera in worldspace
aiMatrix4x4 mWorldInverse = mWorld;
mWorldInverse.Inverse();
mWorldInverse.Transpose();
const aiVector3D vLocalCamera = mWorldInverse * g_sCamera.vPos;
// well ... this is really funny now. We must compute their distance
// from the camera. We take the average distance of a face and add it
// to a map which sorts it
std::map<float,unsigned int, std::greater<float> > smap;
for (unsigned int iFace = 0; iFace < pcMesh->mNumFaces;++iFace)
{
const aiFace* pcFace = &pcMesh->mFaces[iFace];
float fDist = 0.0f;
for (unsigned int c = 0; c < 3;++c)
{
aiVector3D vPos = pcMesh->mVertices[pcFace->mIndices[c]];
vPos -= vLocalCamera;
fDist += vPos.SquareLength();
}
smap.insert(std::pair<float, unsigned int>(fDist,iFace));
}
// now we can lock the index buffer and rebuild it
D3DINDEXBUFFER_DESC sDesc;
pcHelper->piIB->GetDesc(&sDesc);
if (D3DFMT_INDEX16 == sDesc.Format)
{
uint16_t* aiIndices;
pcHelper->piIB->Lock(0,0,(void**)&aiIndices,D3DLOCK_DISCARD);
for (std::map<float,unsigned int, std::greater<float> >::const_iterator
i = smap.begin();
i != smap.end();++i)
{
const aiFace* pcFace = &pcMesh->mFaces[(*i).second];
*aiIndices++ = (uint16_t)pcFace->mIndices[0];
*aiIndices++ = (uint16_t)pcFace->mIndices[1];
*aiIndices++ = (uint16_t)pcFace->mIndices[2];
}
}
else if (D3DFMT_INDEX32 == sDesc.Format)
{
uint32_t* aiIndices;
pcHelper->piIB->Lock(0,0,(void**)&aiIndices,D3DLOCK_DISCARD);
for (std::map<float,unsigned int, std::greater<float> >::const_iterator
i = smap.begin();
i != smap.end();++i)
{
const aiFace* pcFace = &pcMesh->mFaces[(*i).second];
*aiIndices++ = (uint32_t)pcFace->mIndices[0];
*aiIndices++ = (uint32_t)pcFace->mIndices[1];
*aiIndices++ = (uint32_t)pcFace->mIndices[2];
}
}
pcHelper->piIB->Unlock();
// set vertex and index buffer
g_piDevice->SetStreamSource(0,pcHelper->piVB,0,sizeof(AssetHelper::Vertex));
// and draw the mesh
g_piDevice->SetIndices(pcHelper->piIB);
g_piDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
0,0,
pcMesh->mNumVertices,0,
pcMesh->mNumFaces);
return 1;
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
#include <map>
#include <functional>
namespace AssimpView {
CMeshRenderer CMeshRenderer::s_cInstance;
//-------------------------------------------------------------------------------
int CMeshRenderer::DrawUnsorted(unsigned int iIndex)
{
ai_assert(iIndex < g_pcAsset->pcScene->mNumMeshes);
// set vertex and index buffer
g_piDevice->SetStreamSource(0,g_pcAsset->apcMeshes[iIndex]->piVB,0,
sizeof(AssetHelper::Vertex));
g_piDevice->SetIndices(g_pcAsset->apcMeshes[iIndex]->piIB);
D3DPRIMITIVETYPE type = D3DPT_POINTLIST;
switch (g_pcAsset->pcScene->mMeshes[iIndex]->mPrimitiveTypes) {
case aiPrimitiveType_POINT:
type = D3DPT_POINTLIST;break;
case aiPrimitiveType_LINE:
type = D3DPT_LINELIST;break;
case aiPrimitiveType_TRIANGLE:
type = D3DPT_TRIANGLELIST;break;
}
// and draw the mesh
g_piDevice->DrawIndexedPrimitive(type,
0,0,
g_pcAsset->pcScene->mMeshes[iIndex]->mNumVertices,0,
g_pcAsset->pcScene->mMeshes[iIndex]->mNumFaces);
return 1;
}
//-------------------------------------------------------------------------------
int CMeshRenderer::DrawSorted(unsigned int iIndex,const aiMatrix4x4& mWorld)
{
ai_assert(iIndex < g_pcAsset->pcScene->mNumMeshes);
AssetHelper::MeshHelper* pcHelper = g_pcAsset->apcMeshes[iIndex];
const aiMesh* pcMesh = g_pcAsset->pcScene->mMeshes[iIndex];
if (!pcHelper || !pcMesh || !pcHelper->piIB)
return -5;
if (pcMesh->mPrimitiveTypes != aiPrimitiveType_TRIANGLE || pcMesh->HasBones() || g_sOptions.bNoAlphaBlending)
return DrawUnsorted(iIndex);
// compute the position of the camera in worldspace
aiMatrix4x4 mWorldInverse = mWorld;
mWorldInverse.Inverse();
mWorldInverse.Transpose();
const aiVector3D vLocalCamera = mWorldInverse * g_sCamera.vPos;
// well ... this is really funny now. We must compute their distance
// from the camera. We take the average distance of a face and add it
// to a map which sorts it
std::map<float,unsigned int, std::greater<float> > smap;
for (unsigned int iFace = 0; iFace < pcMesh->mNumFaces;++iFace)
{
const aiFace* pcFace = &pcMesh->mFaces[iFace];
float fDist = 0.0f;
for (unsigned int c = 0; c < 3;++c)
{
aiVector3D vPos = pcMesh->mVertices[pcFace->mIndices[c]];
vPos -= vLocalCamera;
fDist += vPos.SquareLength();
}
smap.insert(std::pair<float, unsigned int>(fDist,iFace));
}
// now we can lock the index buffer and rebuild it
D3DINDEXBUFFER_DESC sDesc;
pcHelper->piIB->GetDesc(&sDesc);
if (D3DFMT_INDEX16 == sDesc.Format)
{
uint16_t* aiIndices;
pcHelper->piIB->Lock(0,0,(void**)&aiIndices,D3DLOCK_DISCARD);
for (std::map<float,unsigned int, std::greater<float> >::const_iterator
i = smap.begin();
i != smap.end();++i)
{
const aiFace* pcFace = &pcMesh->mFaces[(*i).second];
*aiIndices++ = (uint16_t)pcFace->mIndices[0];
*aiIndices++ = (uint16_t)pcFace->mIndices[1];
*aiIndices++ = (uint16_t)pcFace->mIndices[2];
}
}
else if (D3DFMT_INDEX32 == sDesc.Format)
{
uint32_t* aiIndices;
pcHelper->piIB->Lock(0,0,(void**)&aiIndices,D3DLOCK_DISCARD);
for (std::map<float,unsigned int, std::greater<float> >::const_iterator
i = smap.begin();
i != smap.end();++i)
{
const aiFace* pcFace = &pcMesh->mFaces[(*i).second];
*aiIndices++ = (uint32_t)pcFace->mIndices[0];
*aiIndices++ = (uint32_t)pcFace->mIndices[1];
*aiIndices++ = (uint32_t)pcFace->mIndices[2];
}
}
pcHelper->piIB->Unlock();
// set vertex and index buffer
g_piDevice->SetStreamSource(0,pcHelper->piVB,0,sizeof(AssetHelper::Vertex));
// and draw the mesh
g_piDevice->SetIndices(pcHelper->piIB);
g_piDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
0,0,
pcMesh->mNumVertices,0,
pcMesh->mNumFaces);
return 1;
}
};

View File

@ -1,99 +1,99 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#if (!defined AV_MESH_RENDERER_H_INCLUDED)
#define AV_MESH_RENDERER_H_INCLUDED
namespace AssimpView {
//-------------------------------------------------------------------------------
/* Helper class tp render meshes
*/
//-------------------------------------------------------------------------------
class CMeshRenderer
{
private:
// default constructor
CMeshRenderer()
{
// no other members to initialize
}
public:
//------------------------------------------------------------------
// Singleton accessors
static CMeshRenderer s_cInstance;
inline static CMeshRenderer& Instance()
{
return s_cInstance;
}
//------------------------------------------------------------------
// Draw a mesh in the global mesh list using the current pipeline state
// iIndex Index of the mesh to be drawn
//
// The function draws all faces in order, regardless of their distance
int DrawUnsorted( unsigned int iIndex );
//------------------------------------------------------------------
// Draw a mesh in the global mesh list using the current pipeline state
// iIndex Index of the mesh to be drawn
//
// The method sorts all vertices by their distance (back to front)
//
// mWorld World matrix for the node
int DrawSorted( unsigned int iIndex,
const aiMatrix4x4& mWorld );
private:
};
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#if (!defined AV_MESH_RENDERER_H_INCLUDED)
#define AV_MESH_RENDERER_H_INCLUDED
namespace AssimpView {
//-------------------------------------------------------------------------------
/* Helper class tp render meshes
*/
//-------------------------------------------------------------------------------
class CMeshRenderer
{
private:
// default constructor
CMeshRenderer()
{
// no other members to initialize
}
public:
//------------------------------------------------------------------
// Singleton accessors
static CMeshRenderer s_cInstance;
inline static CMeshRenderer& Instance()
{
return s_cInstance;
}
//------------------------------------------------------------------
// Draw a mesh in the global mesh list using the current pipeline state
// iIndex Index of the mesh to be drawn
//
// The function draws all faces in order, regardless of their distance
int DrawUnsorted( unsigned int iIndex );
//------------------------------------------------------------------
// Draw a mesh in the global mesh list using the current pipeline state
// iIndex Index of the mesh to be drawn
//
// The method sorts all vertices by their distance (back to front)
//
// mWorld World matrix for the node
int DrawSorted( unsigned int iIndex,
const aiMatrix4x4& mWorld );
private:
};
}
#endif //!! include guard

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +1,2 @@
text1.bin is the corresponding bin file to be included with the executable file.
text1.bin is the corresponding bin file to be included with the executable file.
When updating the rich formatted text inside Visual Studio, a terminating 0 character must be appended

View File

@ -1,175 +1,175 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
// note: these are no longer part of the public API, but they are
// exported on Windows to keep AssimpView alive.
#include "GenFaceNormalsProcess.h"
#include "GenVertexNormalsProcess.h"
#include "JoinVerticesProcess.h"
#include "CalcTangentsProcess.h"
#include "MakeVerboseFormat.h"
namespace AssimpView {
using namespace Assimp;
bool g_bWasFlipped = false;
float g_smoothAngle = 80.f;
//-------------------------------------------------------------------------------
// Flip all normal vectors
//-------------------------------------------------------------------------------
void AssetHelper::FlipNormalsInt()
{
// invert all normal vectors
for (unsigned int i = 0; i < this->pcScene->mNumMeshes;++i)
{
aiMesh* pcMesh = this->pcScene->mMeshes[i];
if (!pcMesh->mNormals)
continue;
for (unsigned int a = 0; a < pcMesh->mNumVertices;++a){
pcMesh->mNormals[a] *= -1.0f;
}
}
}
//-------------------------------------------------------------------------------
void AssetHelper::FlipNormals()
{
FlipNormalsInt();
// recreate native data
DeleteAssetData(true);
CreateAssetData();
g_bWasFlipped = ! g_bWasFlipped;
}
//-------------------------------------------------------------------------------
// Set the normal set of the scene
//-------------------------------------------------------------------------------
void AssetHelper::SetNormalSet(unsigned int iSet)
{
// we need to build an unique set of vertices for this ...
{
MakeVerboseFormatProcess* pcProcess = new MakeVerboseFormatProcess();
pcProcess->Execute(pcScene);
delete pcProcess;
for (unsigned int i = 0; i < pcScene->mNumMeshes;++i)
{
if (!apcMeshes[i]->pvOriginalNormals)
{
apcMeshes[i]->pvOriginalNormals = new aiVector3D[pcScene->mMeshes[i]->mNumVertices];
memcpy( apcMeshes[i]->pvOriginalNormals,pcScene->mMeshes[i]->mNormals,
pcScene->mMeshes[i]->mNumVertices * sizeof(aiVector3D));
}
delete[] pcScene->mMeshes[i]->mNormals;
pcScene->mMeshes[i]->mNormals = NULL;
}
}
// now we can start to calculate a new set of normals
if (HARD == iSet)
{
GenFaceNormalsProcess* pcProcess = new GenFaceNormalsProcess();
pcProcess->Execute(pcScene);
FlipNormalsInt();
delete pcProcess;
}
else if (SMOOTH == iSet)
{
GenVertexNormalsProcess* pcProcess = new GenVertexNormalsProcess();
pcProcess->SetMaxSmoothAngle((float)AI_DEG_TO_RAD(g_smoothAngle));
pcProcess->Execute(pcScene);
FlipNormalsInt();
delete pcProcess;
}
else if (ORIGINAL == iSet)
{
for (unsigned int i = 0; i < pcScene->mNumMeshes;++i)
{
if (apcMeshes[i]->pvOriginalNormals)
{
delete[] pcScene->mMeshes[i]->mNormals;
pcScene->mMeshes[i]->mNormals = apcMeshes[i]->pvOriginalNormals;
apcMeshes[i]->pvOriginalNormals = NULL;
}
}
}
// recalculate tangents and bitangents
Assimp::BaseProcess* pcProcess = new CalcTangentsProcess();
pcProcess->Execute(pcScene);
delete pcProcess;
// join the mesh vertices again
pcProcess = new JoinVerticesProcess();
pcProcess->Execute(pcScene);
delete pcProcess;
iNormalSet = iSet;
if (g_bWasFlipped)
{
// invert all normal vectors
for (unsigned int i = 0; i < pcScene->mNumMeshes;++i)
{
aiMesh* pcMesh = pcScene->mMeshes[i];
for (unsigned int a = 0; a < pcMesh->mNumVertices;++a)
{
pcMesh->mNormals[a] *= -1.0f;
}
}
}
// recreate native data
DeleteAssetData(true);
CreateAssetData();
return;
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "assimp_view.h"
// note: these are no longer part of the public API, but they are
// exported on Windows to keep AssimpView alive.
#include "GenFaceNormalsProcess.h"
#include "GenVertexNormalsProcess.h"
#include "JoinVerticesProcess.h"
#include "CalcTangentsProcess.h"
#include "MakeVerboseFormat.h"
namespace AssimpView {
using namespace Assimp;
bool g_bWasFlipped = false;
float g_smoothAngle = 80.f;
//-------------------------------------------------------------------------------
// Flip all normal vectors
//-------------------------------------------------------------------------------
void AssetHelper::FlipNormalsInt()
{
// invert all normal vectors
for (unsigned int i = 0; i < this->pcScene->mNumMeshes;++i)
{
aiMesh* pcMesh = this->pcScene->mMeshes[i];
if (!pcMesh->mNormals)
continue;
for (unsigned int a = 0; a < pcMesh->mNumVertices;++a){
pcMesh->mNormals[a] *= -1.0f;
}
}
}
//-------------------------------------------------------------------------------
void AssetHelper::FlipNormals()
{
FlipNormalsInt();
// recreate native data
DeleteAssetData(true);
CreateAssetData();
g_bWasFlipped = ! g_bWasFlipped;
}
//-------------------------------------------------------------------------------
// Set the normal set of the scene
//-------------------------------------------------------------------------------
void AssetHelper::SetNormalSet(unsigned int iSet)
{
// we need to build an unique set of vertices for this ...
{
MakeVerboseFormatProcess* pcProcess = new MakeVerboseFormatProcess();
pcProcess->Execute(pcScene);
delete pcProcess;
for (unsigned int i = 0; i < pcScene->mNumMeshes;++i)
{
if (!apcMeshes[i]->pvOriginalNormals)
{
apcMeshes[i]->pvOriginalNormals = new aiVector3D[pcScene->mMeshes[i]->mNumVertices];
memcpy( apcMeshes[i]->pvOriginalNormals,pcScene->mMeshes[i]->mNormals,
pcScene->mMeshes[i]->mNumVertices * sizeof(aiVector3D));
}
delete[] pcScene->mMeshes[i]->mNormals;
pcScene->mMeshes[i]->mNormals = NULL;
}
}
// now we can start to calculate a new set of normals
if (HARD == iSet)
{
GenFaceNormalsProcess* pcProcess = new GenFaceNormalsProcess();
pcProcess->Execute(pcScene);
FlipNormalsInt();
delete pcProcess;
}
else if (SMOOTH == iSet)
{
GenVertexNormalsProcess* pcProcess = new GenVertexNormalsProcess();
pcProcess->SetMaxSmoothAngle((float)AI_DEG_TO_RAD(g_smoothAngle));
pcProcess->Execute(pcScene);
FlipNormalsInt();
delete pcProcess;
}
else if (ORIGINAL == iSet)
{
for (unsigned int i = 0; i < pcScene->mNumMeshes;++i)
{
if (apcMeshes[i]->pvOriginalNormals)
{
delete[] pcScene->mMeshes[i]->mNormals;
pcScene->mMeshes[i]->mNormals = apcMeshes[i]->pvOriginalNormals;
apcMeshes[i]->pvOriginalNormals = NULL;
}
}
}
// recalculate tangents and bitangents
Assimp::BaseProcess* pcProcess = new CalcTangentsProcess();
pcProcess->Execute(pcScene);
delete pcProcess;
// join the mesh vertices again
pcProcess = new JoinVerticesProcess();
pcProcess->Execute(pcScene);
delete pcProcess;
iNormalSet = iSet;
if (g_bWasFlipped)
{
// invert all normal vectors
for (unsigned int i = 0; i < pcScene->mNumMeshes;++i)
{
aiMesh* pcMesh = pcScene->mMeshes[i];
for (unsigned int a = 0; a < pcMesh->mNumVertices;++a)
{
pcMesh->mNormals[a] *= -1.0f;
}
}
}
// recreate native data
DeleteAssetData(true);
CreateAssetData();
return;
}
};

View File

@ -1,113 +1,113 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#if (!defined AV_RO_H_INCLUDED)
#define AV_RO_H_INCLUDED
//-------------------------------------------------------------------------------
/** \brief Class to manage render options. One global instance
*/
//-------------------------------------------------------------------------------
class RenderOptions
{
public:
// enumerates different drawing modi. POINT is currently
// not supported and probably will never be.
enum DrawMode {NORMAL, WIREFRAME, POINT};
inline RenderOptions (void) :
bMultiSample (true),
bSuperSample (false),
bRenderMats (true),
bRenderNormals (false),
b3Lights (false),
bLightRotate (false),
bRotate (true),
bLowQuality (false),
bNoSpecular (false),
bStereoView (false),
bNoAlphaBlending(false),
eDrawMode (NORMAL),
bCulling (false),
bSkeleton (false)
{}
bool bMultiSample;
// SuperSampling has not yet been implemented
bool bSuperSample;
// Display the real material of the object
bool bRenderMats;
// Render the normals
bool bRenderNormals;
// Use 2 directional light sources
bool b3Lights;
// Automatically rotate the light source(s)
bool bLightRotate;
// Automatically rotate the asset around its origin
bool bRotate;
// use standard lambertian lighting
bool bLowQuality;
// disable specular lighting got all elements in the scene
bool bNoSpecular;
// enable stereo view
bool bStereoView;
bool bNoAlphaBlending;
// wireframe or solid rendering?
DrawMode eDrawMode;
bool bCulling,bSkeleton;
};
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#if (!defined AV_RO_H_INCLUDED)
#define AV_RO_H_INCLUDED
//-------------------------------------------------------------------------------
/** \brief Class to manage render options. One global instance
*/
//-------------------------------------------------------------------------------
class RenderOptions
{
public:
// enumerates different drawing modi. POINT is currently
// not supported and probably will never be.
enum DrawMode {NORMAL, WIREFRAME, POINT};
inline RenderOptions (void) :
bMultiSample (true),
bSuperSample (false),
bRenderMats (true),
bRenderNormals (false),
b3Lights (false),
bLightRotate (false),
bRotate (true),
bLowQuality (false),
bNoSpecular (false),
bStereoView (false),
bNoAlphaBlending(false),
eDrawMode (NORMAL),
bCulling (false),
bSkeleton (false)
{}
bool bMultiSample;
// SuperSampling has not yet been implemented
bool bSuperSample;
// Display the real material of the object
bool bRenderMats;
// Render the normals
bool bRenderNormals;
// Use 2 directional light sources
bool b3Lights;
// Automatically rotate the light source(s)
bool bLightRotate;
// Automatically rotate the asset around its origin
bool bRotate;
// use standard lambertian lighting
bool bLowQuality;
// disable specular lighting got all elements in the scene
bool bNoSpecular;
// enable stereo view
bool bStereoView;
bool bNoAlphaBlending;
// wireframe or solid rendering?
DrawMode eDrawMode;
bool bCulling,bSkeleton;
};
#endif // !! IG

View File

@ -1,245 +1,245 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
/** @file SceneAnimator.cpp
* @brief Implementation of the utility class SceneAnimator
*/
#include "assimp_view.h"
using namespace AssimpView;
// ------------------------------------------------------------------------------------------------
// Constructor for a given scene.
SceneAnimator::SceneAnimator( const aiScene* pScene, size_t pAnimIndex)
{
mScene = pScene;
mCurrentAnimIndex = -1;
mAnimEvaluator = NULL;
mRootNode = NULL;
// build the nodes-for-bones table
for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
{
const aiMesh* mesh = pScene->mMeshes[i];
for (unsigned int n = 0; n < mesh->mNumBones;++n)
{
const aiBone* bone = mesh->mBones[n];
mBoneNodesByName[bone->mName.data] = pScene->mRootNode->FindNode(bone->mName);
}
}
// changing the current animation also creates the node tree for this animation
SetAnimIndex( pAnimIndex);
}
// ------------------------------------------------------------------------------------------------
// Destructor
SceneAnimator::~SceneAnimator()
{
delete mRootNode;
delete mAnimEvaluator;
}
// ------------------------------------------------------------------------------------------------
// Sets the animation to use for playback.
void SceneAnimator::SetAnimIndex( size_t pAnimIndex)
{
// no change
if( pAnimIndex == mCurrentAnimIndex)
return;
// kill data of the previous anim
delete mRootNode; mRootNode = NULL;
delete mAnimEvaluator; mAnimEvaluator = NULL;
mNodesByName.clear();
mCurrentAnimIndex = pAnimIndex;
// create the internal node tree. Do this even in case of invalid animation index
// so that the transformation matrices are properly set up to mimic the current scene
mRootNode = CreateNodeTree( mScene->mRootNode, NULL);
// invalid anim index
if( mCurrentAnimIndex >= mScene->mNumAnimations)
return;
// create an evaluator for this animation
mAnimEvaluator = new AnimEvaluator( mScene->mAnimations[mCurrentAnimIndex]);
}
// ------------------------------------------------------------------------------------------------
// Calculates the node transformations for the scene.
void SceneAnimator::Calculate( double pTime)
{
// invalid anim
if( !mAnimEvaluator)
return;
// calculate current local transformations
mAnimEvaluator->Evaluate( pTime);
// and update all node transformations with the results
UpdateTransforms( mRootNode, mAnimEvaluator->GetTransformations());
}
// ------------------------------------------------------------------------------------------------
// Retrieves the most recent local transformation matrix for the given node.
const aiMatrix4x4& SceneAnimator::GetLocalTransform( const aiNode* node) const
{
NodeMap::const_iterator it = mNodesByName.find( node);
if( it == mNodesByName.end())
return mIdentityMatrix;
return it->second->mLocalTransform;
}
// ------------------------------------------------------------------------------------------------
// Retrieves the most recent global transformation matrix for the given node.
const aiMatrix4x4& SceneAnimator::GetGlobalTransform( const aiNode* node) const
{
NodeMap::const_iterator it = mNodesByName.find( node);
if( it == mNodesByName.end())
return mIdentityMatrix;
return it->second->mGlobalTransform;
}
// ------------------------------------------------------------------------------------------------
// Calculates the bone matrices for the given mesh.
const std::vector<aiMatrix4x4>& SceneAnimator::GetBoneMatrices( const aiNode* pNode, size_t pMeshIndex /* = 0 */)
{
ai_assert( pMeshIndex < pNode->mNumMeshes);
size_t meshIndex = pNode->mMeshes[pMeshIndex];
ai_assert( meshIndex < mScene->mNumMeshes);
const aiMesh* mesh = mScene->mMeshes[meshIndex];
// resize array and initialise it with identity matrices
mTransforms.resize( mesh->mNumBones, aiMatrix4x4());
// calculate the mesh's inverse global transform
aiMatrix4x4 globalInverseMeshTransform = GetGlobalTransform( pNode);
globalInverseMeshTransform.Inverse();
// Bone matrices transform from mesh coordinates in bind pose to mesh coordinates in skinned pose
// Therefore the formula is offsetMatrix * currentGlobalTransform * inverseCurrentMeshTransform
for( size_t a = 0; a < mesh->mNumBones; ++a)
{
const aiBone* bone = mesh->mBones[a];
const aiMatrix4x4& currentGlobalTransform = GetGlobalTransform( mBoneNodesByName[ bone->mName.data ]);
mTransforms[a] = globalInverseMeshTransform * currentGlobalTransform * bone->mOffsetMatrix;
}
// and return the result
return mTransforms;
}
// ------------------------------------------------------------------------------------------------
// Recursively creates an internal node structure matching the current scene and animation.
SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode, SceneAnimNode* pParent)
{
// create a node
SceneAnimNode* internalNode = new SceneAnimNode( pNode->mName.data);
internalNode->mParent = pParent;
mNodesByName[pNode] = internalNode;
// copy its transformation
internalNode->mLocalTransform = pNode->mTransformation;
CalculateGlobalTransform( internalNode);
// find the index of the animation track affecting this node, if any
if( mCurrentAnimIndex < mScene->mNumAnimations)
{
internalNode->mChannelIndex = -1;
const aiAnimation* currentAnim = mScene->mAnimations[mCurrentAnimIndex];
for( unsigned int a = 0; a < currentAnim->mNumChannels; a++)
{
if( currentAnim->mChannels[a]->mNodeName.data == internalNode->mName)
{
internalNode->mChannelIndex = a;
break;
}
}
}
// continue for all child nodes and assign the created internal nodes as our children
for( unsigned int a = 0; a < pNode->mNumChildren; a++)
{
SceneAnimNode* childNode = CreateNodeTree( pNode->mChildren[a], internalNode);
internalNode->mChildren.push_back( childNode);
}
return internalNode;
}
// ------------------------------------------------------------------------------------------------
// Recursively updates the internal node transformations from the given matrix array
void SceneAnimator::UpdateTransforms( SceneAnimNode* pNode, const std::vector<aiMatrix4x4>& pTransforms)
{
// update node local transform
if( pNode->mChannelIndex != -1)
{
ai_assert( pNode->mChannelIndex < pTransforms.size());
pNode->mLocalTransform = pTransforms[pNode->mChannelIndex];
}
// update global transform as well
CalculateGlobalTransform( pNode);
// continue for all children
for( std::vector<SceneAnimNode*>::iterator it = pNode->mChildren.begin(); it != pNode->mChildren.end(); ++it)
UpdateTransforms( *it, pTransforms);
}
// ------------------------------------------------------------------------------------------------
// Calculates the global transformation matrix for the given internal node
void SceneAnimator::CalculateGlobalTransform( SceneAnimNode* pInternalNode)
{
// concatenate all parent transforms to get the global transform for this node
pInternalNode->mGlobalTransform = pInternalNode->mLocalTransform;
SceneAnimNode* node = pInternalNode->mParent;
while( node)
{
pInternalNode->mGlobalTransform = node->mLocalTransform * pInternalNode->mGlobalTransform;
node = node->mParent;
}
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2015, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
/** @file SceneAnimator.cpp
* @brief Implementation of the utility class SceneAnimator
*/
#include "assimp_view.h"
using namespace AssimpView;
// ------------------------------------------------------------------------------------------------
// Constructor for a given scene.
SceneAnimator::SceneAnimator( const aiScene* pScene, size_t pAnimIndex)
{
mScene = pScene;
mCurrentAnimIndex = -1;
mAnimEvaluator = NULL;
mRootNode = NULL;
// build the nodes-for-bones table
for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
{
const aiMesh* mesh = pScene->mMeshes[i];
for (unsigned int n = 0; n < mesh->mNumBones;++n)
{
const aiBone* bone = mesh->mBones[n];
mBoneNodesByName[bone->mName.data] = pScene->mRootNode->FindNode(bone->mName);
}
}
// changing the current animation also creates the node tree for this animation
SetAnimIndex( pAnimIndex);
}
// ------------------------------------------------------------------------------------------------
// Destructor
SceneAnimator::~SceneAnimator()
{
delete mRootNode;
delete mAnimEvaluator;
}
// ------------------------------------------------------------------------------------------------
// Sets the animation to use for playback.
void SceneAnimator::SetAnimIndex( size_t pAnimIndex)
{
// no change
if( pAnimIndex == mCurrentAnimIndex)
return;
// kill data of the previous anim
delete mRootNode; mRootNode = NULL;
delete mAnimEvaluator; mAnimEvaluator = NULL;
mNodesByName.clear();
mCurrentAnimIndex = pAnimIndex;
// create the internal node tree. Do this even in case of invalid animation index
// so that the transformation matrices are properly set up to mimic the current scene
mRootNode = CreateNodeTree( mScene->mRootNode, NULL);
// invalid anim index
if( mCurrentAnimIndex >= mScene->mNumAnimations)
return;
// create an evaluator for this animation
mAnimEvaluator = new AnimEvaluator( mScene->mAnimations[mCurrentAnimIndex]);
}
// ------------------------------------------------------------------------------------------------
// Calculates the node transformations for the scene.
void SceneAnimator::Calculate( double pTime)
{
// invalid anim
if( !mAnimEvaluator)
return;
// calculate current local transformations
mAnimEvaluator->Evaluate( pTime);
// and update all node transformations with the results
UpdateTransforms( mRootNode, mAnimEvaluator->GetTransformations());
}
// ------------------------------------------------------------------------------------------------
// Retrieves the most recent local transformation matrix for the given node.
const aiMatrix4x4& SceneAnimator::GetLocalTransform( const aiNode* node) const
{
NodeMap::const_iterator it = mNodesByName.find( node);
if( it == mNodesByName.end())
return mIdentityMatrix;
return it->second->mLocalTransform;
}
// ------------------------------------------------------------------------------------------------
// Retrieves the most recent global transformation matrix for the given node.
const aiMatrix4x4& SceneAnimator::GetGlobalTransform( const aiNode* node) const
{
NodeMap::const_iterator it = mNodesByName.find( node);
if( it == mNodesByName.end())
return mIdentityMatrix;
return it->second->mGlobalTransform;
}
// ------------------------------------------------------------------------------------------------
// Calculates the bone matrices for the given mesh.
const std::vector<aiMatrix4x4>& SceneAnimator::GetBoneMatrices( const aiNode* pNode, size_t pMeshIndex /* = 0 */)
{
ai_assert( pMeshIndex < pNode->mNumMeshes);
size_t meshIndex = pNode->mMeshes[pMeshIndex];
ai_assert( meshIndex < mScene->mNumMeshes);
const aiMesh* mesh = mScene->mMeshes[meshIndex];
// resize array and initialise it with identity matrices
mTransforms.resize( mesh->mNumBones, aiMatrix4x4());
// calculate the mesh's inverse global transform
aiMatrix4x4 globalInverseMeshTransform = GetGlobalTransform( pNode);
globalInverseMeshTransform.Inverse();
// Bone matrices transform from mesh coordinates in bind pose to mesh coordinates in skinned pose
// Therefore the formula is offsetMatrix * currentGlobalTransform * inverseCurrentMeshTransform
for( size_t a = 0; a < mesh->mNumBones; ++a)
{
const aiBone* bone = mesh->mBones[a];
const aiMatrix4x4& currentGlobalTransform = GetGlobalTransform( mBoneNodesByName[ bone->mName.data ]);
mTransforms[a] = globalInverseMeshTransform * currentGlobalTransform * bone->mOffsetMatrix;
}
// and return the result
return mTransforms;
}
// ------------------------------------------------------------------------------------------------
// Recursively creates an internal node structure matching the current scene and animation.
SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode, SceneAnimNode* pParent)
{
// create a node
SceneAnimNode* internalNode = new SceneAnimNode( pNode->mName.data);
internalNode->mParent = pParent;
mNodesByName[pNode] = internalNode;
// copy its transformation
internalNode->mLocalTransform = pNode->mTransformation;
CalculateGlobalTransform( internalNode);
// find the index of the animation track affecting this node, if any
if( mCurrentAnimIndex < mScene->mNumAnimations)
{
internalNode->mChannelIndex = -1;
const aiAnimation* currentAnim = mScene->mAnimations[mCurrentAnimIndex];
for( unsigned int a = 0; a < currentAnim->mNumChannels; a++)
{
if( currentAnim->mChannels[a]->mNodeName.data == internalNode->mName)
{
internalNode->mChannelIndex = a;
break;
}
}
}
// continue for all child nodes and assign the created internal nodes as our children
for( unsigned int a = 0; a < pNode->mNumChildren; a++)
{
SceneAnimNode* childNode = CreateNodeTree( pNode->mChildren[a], internalNode);
internalNode->mChildren.push_back( childNode);
}
return internalNode;
}
// ------------------------------------------------------------------------------------------------
// Recursively updates the internal node transformations from the given matrix array
void SceneAnimator::UpdateTransforms( SceneAnimNode* pNode, const std::vector<aiMatrix4x4>& pTransforms)
{
// update node local transform
if( pNode->mChannelIndex != -1)
{
ai_assert( pNode->mChannelIndex < pTransforms.size());
pNode->mLocalTransform = pTransforms[pNode->mChannelIndex];
}
// update global transform as well
CalculateGlobalTransform( pNode);
// continue for all children
for( std::vector<SceneAnimNode*>::iterator it = pNode->mChildren.begin(); it != pNode->mChildren.end(); ++it)
UpdateTransforms( *it, pTransforms);
}
// ------------------------------------------------------------------------------------------------
// Calculates the global transformation matrix for the given internal node
void SceneAnimator::CalculateGlobalTransform( SceneAnimNode* pInternalNode)
{
// concatenate all parent transforms to get the global transform for this node
pInternalNode->mGlobalTransform = pInternalNode->mLocalTransform;
SceneAnimNode* node = pInternalNode->mParent;
while( node)
{
pInternalNode->mGlobalTransform = node->mLocalTransform * pInternalNode->mGlobalTransform;
node = node->mParent;
}
}

View File

@ -1,243 +1,243 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
/** @file SceneAnimator.h
* Manages animations for a given scene and calculates present
* transformations for all nodes
*/
#ifndef AV_SCENEANIMATOR_H_INCLUDED
#define AV_SCENEANIMATOR_H_INCLUDED
#include <map>
namespace AssimpView {
// ---------------------------------------------------------------------------------
/** A little tree structure to match the scene's node structure, but holding
* additional data. Needs to be public to allow using it in templates at
* certain compilers.
*/
struct SceneAnimNode
{
std::string mName;
SceneAnimNode* mParent;
std::vector<SceneAnimNode*> mChildren;
//! most recently calculated local transform
aiMatrix4x4 mLocalTransform;
//! same, but in world space
aiMatrix4x4 mGlobalTransform;
//! index in the current animation's channel array. -1 if not animated.
size_t mChannelIndex;
//! Default construction
SceneAnimNode() {
mChannelIndex = -1; mParent = NULL;
}
//! Construction from a given name
SceneAnimNode( const std::string& pName)
: mName( pName) {
mChannelIndex = -1; mParent = NULL;
}
//! Destruct all children recursively
~SceneAnimNode() {
for( std::vector<SceneAnimNode*>::iterator it = mChildren.begin(); it != mChildren.end(); ++it)
delete *it;
}
};
// ---------------------------------------------------------------------------------
/** Calculates the animated node transformations for a given scene and timestamp.
*
* Create an instance for a aiScene you want to animate and set the current animation
* to play. You can then have the instance calculate the current pose for all nodes
* by calling Calculate() for a given timestamp. After this you can retrieve the
* present transformation for a given node by calling GetLocalTransform() or
* GetGlobalTransform(). A full set of bone matrices can be retrieved by
* GetBoneMatrices() for a given mesh.
*/
class SceneAnimator
{
public:
// ----------------------------------------------------------------------------
/** Constructor for a given scene.
*
* The object keeps a reference to the scene during its lifetime, but
* ownership stays at the caller.
* @param pScene The scene to animate.
* @param pAnimIndex [optional] Index of the animation to play. Assumed to
* be 0 if not given.
*/
SceneAnimator( const aiScene* pScene, size_t pAnimIndex = 0);
/** Destructor */
~SceneAnimator();
// ----------------------------------------------------------------------------
/** Sets the animation to use for playback. This also recreates the internal
* mapping structures, which might take a few cycles.
* @param pAnimIndex Index of the animation in the scene's animation array
*/
void SetAnimIndex( size_t pAnimIndex);
// ----------------------------------------------------------------------------
/** Calculates the node transformations for the scene. Call this to get
* uptodate results before calling one of the getters.
* @param pTime Current time. Can be an arbitrary range.
*/
void Calculate( double pTime);
// ----------------------------------------------------------------------------
/** Retrieves the most recent local transformation matrix for the given node.
*
* The returned matrix is in the node's parent's local space, just like the
* original node's transformation matrix. If the node is not animated, the
* node's original transformation is returned so that you can safely use or
* assign it to the node itsself. If there is no node with the given name,
* the identity matrix is returned. All transformations are updated whenever
* Calculate() is called.
* @param pNodeName Name of the node
* @return A reference to the node's most recently calculated local
* transformation matrix.
*/
const aiMatrix4x4& GetLocalTransform( const aiNode* node) const;
// ----------------------------------------------------------------------------
/** Retrieves the most recent global transformation matrix for the given node.
*
* The returned matrix is in world space, which is the same coordinate space
* as the transformation of the scene's root node. If the node is not animated,
* the node's original transformation is returned so that you can safely use or
* assign it to the node itsself. If there is no node with the given name, the
* identity matrix is returned. All transformations are updated whenever
* Calculate() is called.
* @param pNodeName Name of the node
* @return A reference to the node's most recently calculated global
* transformation matrix.
*/
const aiMatrix4x4& GetGlobalTransform( const aiNode* node) const;
// ----------------------------------------------------------------------------
/** Calculates the bone matrices for the given mesh.
*
* Each bone matrix transforms from mesh space in bind pose to mesh space in
* skinned pose, it does not contain the mesh's world matrix. Thus the usual
* matrix chain for using in the vertex shader is
* @code
* boneMatrix * worldMatrix * viewMatrix * projMatrix
* @endcode
* @param pNode The node carrying the mesh.
* @param pMeshIndex Index of the mesh in the node's mesh array. The NODE's
* mesh array, not the scene's mesh array! Leave out to use the first mesh
* of the node, which is usually also the only one.
* @return A reference to a vector of bone matrices. Stays stable till the
* next call to GetBoneMatrices();
*/
const std::vector<aiMatrix4x4>& GetBoneMatrices( const aiNode* pNode,
size_t pMeshIndex = 0);
// ----------------------------------------------------------------------------
/** @brief Get the current animation index
*/
size_t CurrentAnimIndex() const {
return mCurrentAnimIndex;
}
// ----------------------------------------------------------------------------
/** @brief Get the current animation or NULL
*/
aiAnimation* CurrentAnim() const {
return mCurrentAnimIndex < mScene->mNumAnimations ? mScene->mAnimations[ mCurrentAnimIndex ] : NULL;
}
protected:
/** Recursively creates an internal node structure matching the
* current scene and animation.
*/
SceneAnimNode* CreateNodeTree( aiNode* pNode, SceneAnimNode* pParent);
/** Recursively updates the internal node transformations from the
* given matrix array
*/
void UpdateTransforms( SceneAnimNode* pNode, const std::vector<aiMatrix4x4>& pTransforms);
/** Calculates the global transformation matrix for the given internal node */
void CalculateGlobalTransform( SceneAnimNode* pInternalNode);
protected:
/** The scene we're operating on */
const aiScene* mScene;
/** Current animation index */
size_t mCurrentAnimIndex;
/** The AnimEvaluator we use to calculate the current pose for the current animation */
AnimEvaluator* mAnimEvaluator;
/** Root node of the internal scene structure */
SceneAnimNode* mRootNode;
/** Name to node map to quickly find nodes by their name */
typedef std::map<const aiNode*, SceneAnimNode*> NodeMap;
NodeMap mNodesByName;
/** Name to node map to quickly find nodes for given bones by their name */
typedef std::map<const char*, const aiNode*> BoneMap;
BoneMap mBoneNodesByName;
/** Array to return transformations results inside. */
std::vector<aiMatrix4x4> mTransforms;
/** Identity matrix to return a reference to in case of error */
aiMatrix4x4 mIdentityMatrix;
};
} // end of namespace AssimpView
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
/** @file SceneAnimator.h
* Manages animations for a given scene and calculates present
* transformations for all nodes
*/
#ifndef AV_SCENEANIMATOR_H_INCLUDED
#define AV_SCENEANIMATOR_H_INCLUDED
#include <map>
namespace AssimpView {
// ---------------------------------------------------------------------------------
/** A little tree structure to match the scene's node structure, but holding
* additional data. Needs to be public to allow using it in templates at
* certain compilers.
*/
struct SceneAnimNode
{
std::string mName;
SceneAnimNode* mParent;
std::vector<SceneAnimNode*> mChildren;
//! most recently calculated local transform
aiMatrix4x4 mLocalTransform;
//! same, but in world space
aiMatrix4x4 mGlobalTransform;
//! index in the current animation's channel array. -1 if not animated.
size_t mChannelIndex;
//! Default construction
SceneAnimNode() {
mChannelIndex = -1; mParent = NULL;
}
//! Construction from a given name
SceneAnimNode( const std::string& pName)
: mName( pName) {
mChannelIndex = -1; mParent = NULL;
}
//! Destruct all children recursively
~SceneAnimNode() {
for( std::vector<SceneAnimNode*>::iterator it = mChildren.begin(); it != mChildren.end(); ++it)
delete *it;
}
};
// ---------------------------------------------------------------------------------
/** Calculates the animated node transformations for a given scene and timestamp.
*
* Create an instance for a aiScene you want to animate and set the current animation
* to play. You can then have the instance calculate the current pose for all nodes
* by calling Calculate() for a given timestamp. After this you can retrieve the
* present transformation for a given node by calling GetLocalTransform() or
* GetGlobalTransform(). A full set of bone matrices can be retrieved by
* GetBoneMatrices() for a given mesh.
*/
class SceneAnimator
{
public:
// ----------------------------------------------------------------------------
/** Constructor for a given scene.
*
* The object keeps a reference to the scene during its lifetime, but
* ownership stays at the caller.
* @param pScene The scene to animate.
* @param pAnimIndex [optional] Index of the animation to play. Assumed to
* be 0 if not given.
*/
SceneAnimator( const aiScene* pScene, size_t pAnimIndex = 0);
/** Destructor */
~SceneAnimator();
// ----------------------------------------------------------------------------
/** Sets the animation to use for playback. This also recreates the internal
* mapping structures, which might take a few cycles.
* @param pAnimIndex Index of the animation in the scene's animation array
*/
void SetAnimIndex( size_t pAnimIndex);
// ----------------------------------------------------------------------------
/** Calculates the node transformations for the scene. Call this to get
* uptodate results before calling one of the getters.
* @param pTime Current time. Can be an arbitrary range.
*/
void Calculate( double pTime);
// ----------------------------------------------------------------------------
/** Retrieves the most recent local transformation matrix for the given node.
*
* The returned matrix is in the node's parent's local space, just like the
* original node's transformation matrix. If the node is not animated, the
* node's original transformation is returned so that you can safely use or
* assign it to the node itsself. If there is no node with the given name,
* the identity matrix is returned. All transformations are updated whenever
* Calculate() is called.
* @param pNodeName Name of the node
* @return A reference to the node's most recently calculated local
* transformation matrix.
*/
const aiMatrix4x4& GetLocalTransform( const aiNode* node) const;
// ----------------------------------------------------------------------------
/** Retrieves the most recent global transformation matrix for the given node.
*
* The returned matrix is in world space, which is the same coordinate space
* as the transformation of the scene's root node. If the node is not animated,
* the node's original transformation is returned so that you can safely use or
* assign it to the node itsself. If there is no node with the given name, the
* identity matrix is returned. All transformations are updated whenever
* Calculate() is called.
* @param pNodeName Name of the node
* @return A reference to the node's most recently calculated global
* transformation matrix.
*/
const aiMatrix4x4& GetGlobalTransform( const aiNode* node) const;
// ----------------------------------------------------------------------------
/** Calculates the bone matrices for the given mesh.
*
* Each bone matrix transforms from mesh space in bind pose to mesh space in
* skinned pose, it does not contain the mesh's world matrix. Thus the usual
* matrix chain for using in the vertex shader is
* @code
* boneMatrix * worldMatrix * viewMatrix * projMatrix
* @endcode
* @param pNode The node carrying the mesh.
* @param pMeshIndex Index of the mesh in the node's mesh array. The NODE's
* mesh array, not the scene's mesh array! Leave out to use the first mesh
* of the node, which is usually also the only one.
* @return A reference to a vector of bone matrices. Stays stable till the
* next call to GetBoneMatrices();
*/
const std::vector<aiMatrix4x4>& GetBoneMatrices( const aiNode* pNode,
size_t pMeshIndex = 0);
// ----------------------------------------------------------------------------
/** @brief Get the current animation index
*/
size_t CurrentAnimIndex() const {
return mCurrentAnimIndex;
}
// ----------------------------------------------------------------------------
/** @brief Get the current animation or NULL
*/
aiAnimation* CurrentAnim() const {
return mCurrentAnimIndex < mScene->mNumAnimations ? mScene->mAnimations[ mCurrentAnimIndex ] : NULL;
}
protected:
/** Recursively creates an internal node structure matching the
* current scene and animation.
*/
SceneAnimNode* CreateNodeTree( aiNode* pNode, SceneAnimNode* pParent);
/** Recursively updates the internal node transformations from the
* given matrix array
*/
void UpdateTransforms( SceneAnimNode* pNode, const std::vector<aiMatrix4x4>& pTransforms);
/** Calculates the global transformation matrix for the given internal node */
void CalculateGlobalTransform( SceneAnimNode* pInternalNode);
protected:
/** The scene we're operating on */
const aiScene* mScene;
/** Current animation index */
size_t mCurrentAnimIndex;
/** The AnimEvaluator we use to calculate the current pose for the current animation */
AnimEvaluator* mAnimEvaluator;
/** Root node of the internal scene structure */
SceneAnimNode* mRootNode;
/** Name to node map to quickly find nodes by their name */
typedef std::map<const aiNode*, SceneAnimNode*> NodeMap;
NodeMap mNodesByName;
/** Name to node map to quickly find nodes for given bones by their name */
typedef std::map<const char*, const aiNode*> BoneMap;
BoneMap mBoneNodesByName;
/** Array to return transformations results inside. */
std::vector<aiMatrix4x4> mTransforms;
/** Identity matrix to return a reference to in case of error */
aiMatrix4x4 mIdentityMatrix;
};
} // end of namespace AssimpView
#endif // AV_SCENEANIMATOR_H_INCLUDED

View File

@ -1,63 +1,63 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#if (!defined AV_SHADERS_H_INCLUDED)
#define AV_SHADERS_H_INCLUDED
// Shader used for rendering a skybox background
extern std::string g_szSkyboxShader;
// Shader used for visualizing normal vectors
extern std::string g_szNormalsShader;
// Default shader
extern std::string g_szDefaultShader;
// Material shader
extern std::string g_szMaterialShader;
// Shader used to draw the yellow circle on top of everything
extern std::string g_szPassThroughShader;
// Shader used to draw the checker pattern background for the texture view
extern std::string g_szCheckerBackgroundShader;
#endif // !! AV_SHADERS_H_INCLUDED
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#if (!defined AV_SHADERS_H_INCLUDED)
#define AV_SHADERS_H_INCLUDED
// Shader used for rendering a skybox background
extern std::string g_szSkyboxShader;
// Shader used for visualizing normal vectors
extern std::string g_szNormalsShader;
// Default shader
extern std::string g_szDefaultShader;
// Material shader
extern std::string g_szMaterialShader;
// Shader used to draw the yellow circle on top of everything
extern std::string g_szPassThroughShader;
// Shader used to draw the checker pattern background for the texture view
extern std::string g_szCheckerBackgroundShader;
#endif // !! AV_SHADERS_H_INCLUDED

View File

@ -1,286 +1,286 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#if (!defined AV_MAIN_H_INCLUDED)
#define AV_MAIN_H_INCLUDED
#define AI_SHADER_COMPILE_FLAGS D3DXSHADER_USE_LEGACY_D3DX9_31_DLL
// include resource definitions
#include "resource.h"
#include <assert.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <stdio.h>
#include <time.h>
// Include ASSIMP headers (XXX: do we really need all of them?)
#include <assimp/cimport.h>
#include <assimp/Importer.hpp>
#include <assimp/ai_assert.h>
#include <assimp/cfileio.h>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#include <assimp/IOSystem.hpp>
#include <assimp/IOStream.hpp>
#include <assimp/LogStream.hpp>
#include <assimp/DefaultLogger.hpp>
#include "../../code/MaterialSystem.h" // aiMaterial class
#include "../../code/StringComparison.h" // ASSIMP_stricmp and ASSIMP_strincmp
// in order for std::min and std::max to behave properly
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif // max
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif // min
#include <time.h>
// default movement speed
#define MOVE_SPEED 3.f
#include "AssetHelper.h"
#include "Camera.h"
#include "RenderOptions.h"
#include "Shaders.h"
#include "Background.h"
#include "LogDisplay.h"
#include "LogWindow.h"
#include "Display.h"
#include "MeshRenderer.h"
#include "MaterialManager.h"
// outside of namespace, to help Intellisense and solve boost::metatype_stuff_miracle
#include "AnimEvaluator.h"
#include "SceneAnimator.h"
namespace AssimpView
{
//-------------------------------------------------------------------------------
// Function prototypes
//-------------------------------------------------------------------------------
int InitD3D(void);
int ShutdownD3D(void);
int CreateDevice (bool p_bMultiSample,bool p_bSuperSample, bool bHW = true);
int CreateDevice (void);
int ShutdownDevice(void);
int GetProjectionMatrix (aiMatrix4x4& p_mOut);
int LoadAsset(void);
int CreateAssetData(void);
int DeleteAssetData(bool bNoMaterials = false);
int ScaleAsset(void);
int DeleteAsset(void);
int SetupFPSView();
aiVector3D GetCameraMatrix (aiMatrix4x4& p_mOut);
int CreateMaterial(AssetHelper::MeshHelper* pcMesh,const aiMesh* pcSource);
void HandleMouseInputFPS( void );
void HandleMouseInputLightRotate( void );
void HandleMouseInputLocal( void );
void HandleKeyboardInputFPS( void );
void HandleMouseInputLightIntensityAndColor( void );
void HandleMouseInputSkyBox( void );
void HandleKeyboardInputTextureView( void );
void HandleMouseInputTextureView( void );
//-------------------------------------------------------------------------------
//
// Dialog procedure for the progress bar window
//
//-------------------------------------------------------------------------------
INT_PTR CALLBACK ProgressMessageProc(HWND hwndDlg,UINT uMsg,
WPARAM wParam,LPARAM lParam);
//-------------------------------------------------------------------------------
// Main message procedure of the application
//
// The function handles all incoming messages for the main window.
// However, if does not directly process input commands.
// NOTE: Due to the impossibility to process WM_CHAR messages in dialogs
// properly the code for all hotkeys has been moved to the WndMain
//-------------------------------------------------------------------------------
INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg,
WPARAM wParam,LPARAM lParam);
//-------------------------------------------------------------------------------
//
// Dialog procedure for the about dialog
//
//-------------------------------------------------------------------------------
INT_PTR CALLBACK AboutMessageProc(HWND hwndDlg,UINT uMsg,
WPARAM wParam,LPARAM lParam);
//-------------------------------------------------------------------------------
//
// Dialog procedure for the help dialog
//
//-------------------------------------------------------------------------------
INT_PTR CALLBACK HelpDialogProc(HWND hwndDlg,UINT uMsg,
WPARAM wParam,LPARAM lParam);
//-------------------------------------------------------------------------------
// Handle command line parameters
//
// The function loads an asset specified on the command line as first argument
// Other command line parameters are not handled
//-------------------------------------------------------------------------------
void HandleCommandLine(char* p_szCommand);
//-------------------------------------------------------------------------------
template <class type, class intype>
type clamp(intype in)
{
// for unsigned types only ...
intype mask = (0x1u << (sizeof(type)*8))-1;
return (type)max((intype)0,min(in,mask));
}
//-------------------------------------------------------------------------------
// Position of the cursor relative to the 3ds max' like control circle
//-------------------------------------------------------------------------------
enum EClickPos
{
// The click was inside the inner circle (x,y axis)
EClickPos_Circle,
// The click was inside one of tghe vertical snap-ins
EClickPos_CircleVert,
// The click was inside onf of the horizontal snap-ins
EClickPos_CircleHor,
// the cklick was outside the circle (z-axis)
EClickPos_Outside
};
#if (!defined AI_VIEW_CAPTION_BASE)
# define AI_VIEW_CAPTION_BASE "Open Asset Import Library : Viewer "
#endif // !! AI_VIEW_CAPTION_BASE
//-------------------------------------------------------------------------------
// Evil globals
//-------------------------------------------------------------------------------
extern HINSTANCE g_hInstance /*= NULL*/;
extern HWND g_hDlg /*= NULL*/;
extern IDirect3D9* g_piD3D /*= NULL*/;
extern IDirect3DDevice9* g_piDevice /*= NULL*/;
extern IDirect3DVertexDeclaration9* gDefaultVertexDecl /*= NULL*/;
extern double g_fFPS /*= 0.0f*/;
extern char g_szFileName[MAX_PATH];
extern ID3DXEffect* g_piDefaultEffect /*= NULL*/;
extern ID3DXEffect* g_piNormalsEffect /*= NULL*/;
extern ID3DXEffect* g_piPassThroughEffect /*= NULL*/;
extern ID3DXEffect* g_piPatternEffect /*= NULL*/;
extern bool g_bMousePressed /*= false*/;
extern bool g_bMousePressedR /*= false*/;
extern bool g_bMousePressedM /*= false*/;
extern bool g_bMousePressedBoth /*= false*/;
extern float g_fElpasedTime /*= 0.0f*/;
extern D3DCAPS9 g_sCaps;
extern bool g_bLoadingFinished /*= false*/;
extern HANDLE g_hThreadHandle /*= NULL*/;
extern float g_fWheelPos /*= -10.0f*/;
extern bool g_bLoadingCanceled /*= false*/;
extern IDirect3DTexture9* g_pcTexture /*= NULL*/;
extern aiMatrix4x4 g_mWorld;
extern aiMatrix4x4 g_mWorldRotate;
extern aiVector3D g_vRotateSpeed /*= aiVector3D(0.5f,0.5f,0.5f)*/;
extern aiVector3D g_avLightDirs[1] /* =
{ aiVector3D(-0.5f,0.6f,0.2f) ,
aiVector3D(-0.5f,0.5f,0.5f)} */;
extern POINT g_mousePos /*= {0,0};*/;
extern POINT g_LastmousePos /*= {0,0}*/;
extern bool g_bFPSView /*= false*/;
extern bool g_bInvert /*= false*/;
extern EClickPos g_eClick;
extern unsigned int g_iCurrentColor /*= 0*/;
// NOTE: The light intensity is separated from the color, it can
// directly be manipulated using the middle mouse button.
// When the user chooses a color from the palette the intensity
// is reset to 1.0
// index[2] is the ambient color
extern float g_fLightIntensity /*=0.0f*/;
extern D3DCOLOR g_avLightColors[3];
extern RenderOptions g_sOptions;
extern Camera g_sCamera;
extern AssetHelper *g_pcAsset /*= NULL*/;
//
// Contains the mask image for the HUD
// (used to determine the position of a click)
//
// The size of the image is identical to the size of the main
// HUD texture
//
extern unsigned char* g_szImageMask /*= NULL*/;
extern float g_fACMR /*= 3.0f*/;
extern IDirect3DQuery9* g_piQuery;
extern bool g_bPlay /*= false*/;
extern double g_dCurrent;
extern float g_smoothAngle /*= 80.f*/;
extern unsigned int ppsteps,ppstepsdefault;
extern bool nopointslines;
}
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#if (!defined AV_MAIN_H_INCLUDED)
#define AV_MAIN_H_INCLUDED
#define AI_SHADER_COMPILE_FLAGS D3DXSHADER_USE_LEGACY_D3DX9_31_DLL
// include resource definitions
#include "resource.h"
#include <assert.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <stdio.h>
#include <time.h>
// Include ASSIMP headers (XXX: do we really need all of them?)
#include <assimp/cimport.h>
#include <assimp/Importer.hpp>
#include <assimp/ai_assert.h>
#include <assimp/cfileio.h>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#include <assimp/IOSystem.hpp>
#include <assimp/IOStream.hpp>
#include <assimp/LogStream.hpp>
#include <assimp/DefaultLogger.hpp>
#include "../../code/MaterialSystem.h" // aiMaterial class
#include "../../code/StringComparison.h" // ASSIMP_stricmp and ASSIMP_strincmp
// in order for std::min and std::max to behave properly
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif // max
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif // min
#include <time.h>
// default movement speed
#define MOVE_SPEED 3.f
#include "AssetHelper.h"
#include "Camera.h"
#include "RenderOptions.h"
#include "Shaders.h"
#include "Background.h"
#include "LogDisplay.h"
#include "LogWindow.h"
#include "Display.h"
#include "MeshRenderer.h"
#include "MaterialManager.h"
// outside of namespace, to help Intellisense and solve boost::metatype_stuff_miracle
#include "AnimEvaluator.h"
#include "SceneAnimator.h"
namespace AssimpView
{
//-------------------------------------------------------------------------------
// Function prototypes
//-------------------------------------------------------------------------------
int InitD3D(void);
int ShutdownD3D(void);
int CreateDevice (bool p_bMultiSample,bool p_bSuperSample, bool bHW = true);
int CreateDevice (void);
int ShutdownDevice(void);
int GetProjectionMatrix (aiMatrix4x4& p_mOut);
int LoadAsset(void);
int CreateAssetData(void);
int DeleteAssetData(bool bNoMaterials = false);
int ScaleAsset(void);
int DeleteAsset(void);
int SetupFPSView();
aiVector3D GetCameraMatrix (aiMatrix4x4& p_mOut);
int CreateMaterial(AssetHelper::MeshHelper* pcMesh,const aiMesh* pcSource);
void HandleMouseInputFPS( void );
void HandleMouseInputLightRotate( void );
void HandleMouseInputLocal( void );
void HandleKeyboardInputFPS( void );
void HandleMouseInputLightIntensityAndColor( void );
void HandleMouseInputSkyBox( void );
void HandleKeyboardInputTextureView( void );
void HandleMouseInputTextureView( void );
//-------------------------------------------------------------------------------
//
// Dialog procedure for the progress bar window
//
//-------------------------------------------------------------------------------
INT_PTR CALLBACK ProgressMessageProc(HWND hwndDlg,UINT uMsg,
WPARAM wParam,LPARAM lParam);
//-------------------------------------------------------------------------------
// Main message procedure of the application
//
// The function handles all incoming messages for the main window.
// However, if does not directly process input commands.
// NOTE: Due to the impossibility to process WM_CHAR messages in dialogs
// properly the code for all hotkeys has been moved to the WndMain
//-------------------------------------------------------------------------------
INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg,
WPARAM wParam,LPARAM lParam);
//-------------------------------------------------------------------------------
//
// Dialog procedure for the about dialog
//
//-------------------------------------------------------------------------------
INT_PTR CALLBACK AboutMessageProc(HWND hwndDlg,UINT uMsg,
WPARAM wParam,LPARAM lParam);
//-------------------------------------------------------------------------------
//
// Dialog procedure for the help dialog
//
//-------------------------------------------------------------------------------
INT_PTR CALLBACK HelpDialogProc(HWND hwndDlg,UINT uMsg,
WPARAM wParam,LPARAM lParam);
//-------------------------------------------------------------------------------
// Handle command line parameters
//
// The function loads an asset specified on the command line as first argument
// Other command line parameters are not handled
//-------------------------------------------------------------------------------
void HandleCommandLine(char* p_szCommand);
//-------------------------------------------------------------------------------
template <class type, class intype>
type clamp(intype in)
{
// for unsigned types only ...
intype mask = (0x1u << (sizeof(type)*8))-1;
return (type)max((intype)0,min(in,mask));
}
//-------------------------------------------------------------------------------
// Position of the cursor relative to the 3ds max' like control circle
//-------------------------------------------------------------------------------
enum EClickPos
{
// The click was inside the inner circle (x,y axis)
EClickPos_Circle,
// The click was inside one of tghe vertical snap-ins
EClickPos_CircleVert,
// The click was inside onf of the horizontal snap-ins
EClickPos_CircleHor,
// the cklick was outside the circle (z-axis)
EClickPos_Outside
};
#if (!defined AI_VIEW_CAPTION_BASE)
# define AI_VIEW_CAPTION_BASE "Open Asset Import Library : Viewer "
#endif // !! AI_VIEW_CAPTION_BASE
//-------------------------------------------------------------------------------
// Evil globals
//-------------------------------------------------------------------------------
extern HINSTANCE g_hInstance /*= NULL*/;
extern HWND g_hDlg /*= NULL*/;
extern IDirect3D9* g_piD3D /*= NULL*/;
extern IDirect3DDevice9* g_piDevice /*= NULL*/;
extern IDirect3DVertexDeclaration9* gDefaultVertexDecl /*= NULL*/;
extern double g_fFPS /*= 0.0f*/;
extern char g_szFileName[MAX_PATH];
extern ID3DXEffect* g_piDefaultEffect /*= NULL*/;
extern ID3DXEffect* g_piNormalsEffect /*= NULL*/;
extern ID3DXEffect* g_piPassThroughEffect /*= NULL*/;
extern ID3DXEffect* g_piPatternEffect /*= NULL*/;
extern bool g_bMousePressed /*= false*/;
extern bool g_bMousePressedR /*= false*/;
extern bool g_bMousePressedM /*= false*/;
extern bool g_bMousePressedBoth /*= false*/;
extern float g_fElpasedTime /*= 0.0f*/;
extern D3DCAPS9 g_sCaps;
extern bool g_bLoadingFinished /*= false*/;
extern HANDLE g_hThreadHandle /*= NULL*/;
extern float g_fWheelPos /*= -10.0f*/;
extern bool g_bLoadingCanceled /*= false*/;
extern IDirect3DTexture9* g_pcTexture /*= NULL*/;
extern aiMatrix4x4 g_mWorld;
extern aiMatrix4x4 g_mWorldRotate;
extern aiVector3D g_vRotateSpeed /*= aiVector3D(0.5f,0.5f,0.5f)*/;
extern aiVector3D g_avLightDirs[1] /* =
{ aiVector3D(-0.5f,0.6f,0.2f) ,
aiVector3D(-0.5f,0.5f,0.5f)} */;
extern POINT g_mousePos /*= {0,0};*/;
extern POINT g_LastmousePos /*= {0,0}*/;
extern bool g_bFPSView /*= false*/;
extern bool g_bInvert /*= false*/;
extern EClickPos g_eClick;
extern unsigned int g_iCurrentColor /*= 0*/;
// NOTE: The light intensity is separated from the color, it can
// directly be manipulated using the middle mouse button.
// When the user chooses a color from the palette the intensity
// is reset to 1.0
// index[2] is the ambient color
extern float g_fLightIntensity /*=0.0f*/;
extern D3DCOLOR g_avLightColors[3];
extern RenderOptions g_sOptions;
extern Camera g_sCamera;
extern AssetHelper *g_pcAsset /*= NULL*/;
//
// Contains the mask image for the HUD
// (used to determine the position of a click)
//
// The size of the image is identical to the size of the main
// HUD texture
//
extern unsigned char* g_szImageMask /*= NULL*/;
extern float g_fACMR /*= 3.0f*/;
extern IDirect3DQuery9* g_piQuery;
extern bool g_bPlay /*= false*/;
extern double g_dCurrent;
extern float g_smoothAngle /*= 80.f*/;
extern unsigned int ppsteps,ppstepsdefault;
extern bool nopointslines;
}
#endif // !! AV_MAIN_H_INCLUDED

View File

@ -1,74 +1,74 @@
// stdafx.h : Includedatei für Standardsystem-Includedateien
// oder häufig verwendete projektspezifische Includedateien,
// die nur in unregelmäßigen Abständen geändert werden.
//
#pragma once
// Ändern Sie folgende Definitionen für Plattformen, die älter als die unten angegebenen sind.
// In MSDN finden Sie die neuesten Informationen über die entsprechenden Werte für die unterschiedlichen Plattformen.
#ifndef WINVER // Lassen Sie die Verwendung spezifischer Features von Windows XP oder später zu.
# define WINVER 0x0501 // Ändern Sie dies in den geeigneten Wert für andere Versionen von Windows.
#endif
#ifndef _WIN32_WINNT // Lassen Sie die Verwendung spezifischer Features von Windows XP oder später zu.
# define _WIN32_WINNT 0x0501 // Ändern Sie dies in den geeigneten Wert für andere Versionen von Windows.
#endif
#ifndef _WIN32_WINDOWS // Lassen Sie die Verwendung spezifischer Features von Windows 98 oder später zu.
# define _WIN32_WINDOWS 0x0410 // Ändern Sie dies in den geeigneten Wert für Windows Me oder höher.
#endif
#ifndef _WIN32_IE // Lassen Sie die Verwendung spezifischer Features von IE 6.0 oder später zu.
#define _WIN32_IE 0x0600 // Ändern Sie dies in den geeigneten Wert für andere Versionen von IE.
#endif
#define WIN32_LEAN_AND_MEAN // Selten verwendete Teile der Windows-Header nicht einbinden.
// Windows-Headerdateien:
#include <windows.h>
// C RunTime-Headerdateien
#include <assert.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <stdio.h>
#include <time.h>
// D3D9 includes
#if (defined _DEBUG)
# define D3D_DEBUG_INFO
#endif
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dx9mesh.h>
// ShellExecute()
#include <shellapi.h>
#include <commctrl.h>
// GetOpenFileName()
#include <commdlg.h>
#include <algorithm>
#include <mmsystem.h>
#include <stdlib.h>
#include <stdio.h>
#include <list>
#include <vector>
#if defined _MSC_VER
// Windows CommonControls 6.0 Manifest Extensions
# if defined _M_IX86
# pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
# elif defined _M_IA64
# pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
# elif defined _M_X64
# pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
# else
# pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
# endif
#endif
// stdafx.h : Includedatei für Standardsystem-Includedateien
// oder häufig verwendete projektspezifische Includedateien,
// die nur in unregelmäßigen Abständen geändert werden.
//
#pragma once
// Ändern Sie folgende Definitionen für Plattformen, die älter als die unten angegebenen sind.
// In MSDN finden Sie die neuesten Informationen über die entsprechenden Werte für die unterschiedlichen Plattformen.
#ifndef WINVER // Lassen Sie die Verwendung spezifischer Features von Windows XP oder später zu.
# define WINVER 0x0501 // Ändern Sie dies in den geeigneten Wert für andere Versionen von Windows.
#endif
#ifndef _WIN32_WINNT // Lassen Sie die Verwendung spezifischer Features von Windows XP oder später zu.
# define _WIN32_WINNT 0x0501 // Ändern Sie dies in den geeigneten Wert für andere Versionen von Windows.
#endif
#ifndef _WIN32_WINDOWS // Lassen Sie die Verwendung spezifischer Features von Windows 98 oder später zu.
# define _WIN32_WINDOWS 0x0410 // Ändern Sie dies in den geeigneten Wert für Windows Me oder höher.
#endif
#ifndef _WIN32_IE // Lassen Sie die Verwendung spezifischer Features von IE 6.0 oder später zu.
#define _WIN32_IE 0x0600 // Ändern Sie dies in den geeigneten Wert für andere Versionen von IE.
#endif
#define WIN32_LEAN_AND_MEAN // Selten verwendete Teile der Windows-Header nicht einbinden.
// Windows-Headerdateien:
#include <windows.h>
// C RunTime-Headerdateien
#include <assert.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <stdio.h>
#include <time.h>
// D3D9 includes
#if (defined _DEBUG)
# define D3D_DEBUG_INFO
#endif
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dx9mesh.h>
// ShellExecute()
#include <shellapi.h>
#include <commctrl.h>
// GetOpenFileName()
#include <commdlg.h>
#include <algorithm>
#include <mmsystem.h>
#include <stdlib.h>
#include <stdio.h>
#include <list>
#include <vector>
#if defined _MSC_VER
// Windows CommonControls 6.0 Manifest Extensions
# if defined _M_IX86
# pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
# elif defined _M_IA64
# pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
# elif defined _M_X64
# pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
# else
# pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
# endif
#endif