Add ortho camera.
parent
66e5765387
commit
d91eebf347
|
@ -55,7 +55,8 @@ namespace glTF {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
inline Value& MakeValue(Value& val, float(&r)[N], MemoryPoolAllocator<>& al) {
|
inline
|
||||||
|
Value& MakeValue(Value& val, float(&r)[N], MemoryPoolAllocator<>& al) {
|
||||||
val.SetArray();
|
val.SetArray();
|
||||||
val.Reserve(N, al);
|
val.Reserve(N, al);
|
||||||
for (decltype(N) i = 0; i < N; ++i) {
|
for (decltype(N) i = 0; i < N; ++i) {
|
||||||
|
@ -64,7 +65,8 @@ namespace glTF {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value& MakeValue(Value& val, const std::vector<float> & r, MemoryPoolAllocator<>& al) {
|
inline
|
||||||
|
Value& MakeValue(Value& val, const std::vector<float> & r, MemoryPoolAllocator<>& al) {
|
||||||
val.SetArray();
|
val.SetArray();
|
||||||
val.Reserve(static_cast<rapidjson::SizeType>(r.size()), al);
|
val.Reserve(static_cast<rapidjson::SizeType>(r.size()), al);
|
||||||
for (unsigned int i = 0; i < r.size(); ++i) {
|
for (unsigned int i = 0; i < r.size(); ++i) {
|
||||||
|
|
|
@ -82,7 +82,7 @@ glTFImporter::glTFImporter()
|
||||||
: BaseImporter()
|
: BaseImporter()
|
||||||
, meshOffsets()
|
, meshOffsets()
|
||||||
, embeddedTexIdxs()
|
, embeddedTexIdxs()
|
||||||
, mScene( NULL ) {
|
, mScene( nullptr ) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,17 +90,16 @@ glTFImporter::~glTFImporter() {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
const aiImporterDesc* glTFImporter::GetInfo() const
|
const aiImporterDesc* glTFImporter::GetInfo() const {
|
||||||
{
|
|
||||||
return &desc;
|
return &desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool glTFImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool /* checkSig */) const
|
bool glTFImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool /* checkSig */) const {
|
||||||
{
|
|
||||||
const std::string &extension = GetExtension(pFile);
|
const std::string &extension = GetExtension(pFile);
|
||||||
|
|
||||||
if (extension != "gltf" && extension != "glb")
|
if (extension != "gltf" && extension != "glb") {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (pIOHandler) {
|
if (pIOHandler) {
|
||||||
glTF::Asset asset(pIOHandler);
|
glTF::Asset asset(pIOHandler);
|
||||||
|
@ -116,44 +115,42 @@ bool glTFImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void CopyValue(const glTF::vec4& v, aiColor4D& out) {
|
||||||
|
out.r = v[0];
|
||||||
//static void CopyValue(const glTF::vec3& v, aiColor3D& out)
|
out.g = v[1];
|
||||||
//{
|
out.b = v[2];
|
||||||
// out.r = v[0]; out.g = v[1]; out.b = v[2];
|
out.a = v[3];
|
||||||
//}
|
|
||||||
|
|
||||||
static void CopyValue(const glTF::vec4& v, aiColor4D& out)
|
|
||||||
{
|
|
||||||
out.r = v[0]; out.g = v[1]; out.b = v[2]; out.a = v[3];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CopyValue(const glTF::vec4& v, aiColor3D& out)
|
static void CopyValue(const glTF::vec4& v, aiColor3D& out) {
|
||||||
{
|
out.r = v[0];
|
||||||
out.r = v[0]; out.g = v[1]; out.b = v[2];
|
out.g = v[1];
|
||||||
|
out.b = v[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CopyValue(const glTF::vec3& v, aiVector3D& out)
|
static void CopyValue(const glTF::vec3& v, aiVector3D& out) {
|
||||||
{
|
out.x = v[0];
|
||||||
out.x = v[0]; out.y = v[1]; out.z = v[2];
|
out.y = v[1];
|
||||||
|
out.z = v[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CopyValue(const glTF::vec4& v, aiQuaternion& out)
|
static void CopyValue(const glTF::vec4& v, aiQuaternion& out) {
|
||||||
{
|
out.x = v[0];
|
||||||
out.x = v[0]; out.y = v[1]; out.z = v[2]; out.w = v[3];
|
out.y = v[1];
|
||||||
|
out.z = v[2];
|
||||||
|
out.w = v[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CopyValue(const glTF::mat4& v, aiMatrix4x4& o)
|
static void CopyValue(const glTF::mat4& v, aiMatrix4x4& o) {
|
||||||
{
|
|
||||||
o.a1 = v[ 0]; o.b1 = v[ 1]; o.c1 = v[ 2]; o.d1 = v[ 3];
|
o.a1 = v[ 0]; o.b1 = v[ 1]; o.c1 = v[ 2]; o.d1 = v[ 3];
|
||||||
o.a2 = v[ 4]; o.b2 = v[ 5]; o.c2 = v[ 6]; o.d2 = v[ 7];
|
o.a2 = v[ 4]; o.b2 = v[ 5]; o.c2 = v[ 6]; o.d2 = v[ 7];
|
||||||
o.a3 = v[ 8]; o.b3 = v[ 9]; o.c3 = v[10]; o.d3 = v[11];
|
o.a3 = v[ 8]; o.b3 = v[ 9]; o.c3 = v[10]; o.d3 = v[11];
|
||||||
o.a4 = v[12]; o.b4 = v[13]; o.c4 = v[14]; o.d4 = v[15];
|
o.a4 = v[12]; o.b4 = v[13]; o.c4 = v[14]; o.d4 = v[15];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SetMaterialColorProperty(std::vector<int>& embeddedTexIdxs, Asset& /*r*/, glTF::TexProperty prop, aiMaterial* mat,
|
inline
|
||||||
aiTextureType texType, const char* pKey, unsigned int type, unsigned int idx)
|
void SetMaterialColorProperty(std::vector<int>& embeddedTexIdxs, Asset& /*r*/, glTF::TexProperty prop, aiMaterial* mat,
|
||||||
{
|
aiTextureType texType, const char* pKey, unsigned int type, unsigned int idx) {
|
||||||
if (prop.texture) {
|
if (prop.texture) {
|
||||||
if (prop.texture->source) {
|
if (prop.texture->source) {
|
||||||
aiString uri(prop.texture->source->uri);
|
aiString uri(prop.texture->source->uri);
|
||||||
|
@ -167,16 +164,14 @@ inline void SetMaterialColorProperty(std::vector<int>& embeddedTexIdxs, Asset& /
|
||||||
|
|
||||||
mat->AddProperty(&uri, _AI_MATKEY_TEXTURE_BASE, texType, 0);
|
mat->AddProperty(&uri, _AI_MATKEY_TEXTURE_BASE, texType, 0);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
aiColor4D col;
|
aiColor4D col;
|
||||||
CopyValue(prop.color, col);
|
CopyValue(prop.color, col);
|
||||||
mat->AddProperty(&col, 1, pKey, type, idx);
|
mat->AddProperty(&col, 1, pKey, type, idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void glTFImporter::ImportMaterials(glTF::Asset& r)
|
void glTFImporter::ImportMaterials(glTF::Asset& r) {
|
||||||
{
|
|
||||||
mScene->mNumMaterials = unsigned(r.materials.Size());
|
mScene->mNumMaterials = unsigned(r.materials.Size());
|
||||||
mScene->mMaterials = new aiMaterial*[mScene->mNumMaterials];
|
mScene->mMaterials = new aiMaterial*[mScene->mNumMaterials];
|
||||||
|
|
||||||
|
@ -499,27 +494,28 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
|
||||||
CopyVector(meshes, mScene->mMeshes, mScene->mNumMeshes);
|
CopyVector(meshes, mScene->mMeshes, mScene->mNumMeshes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void glTFImporter::ImportCameras(glTF::Asset& r)
|
void glTFImporter::ImportCameras(glTF::Asset& r) {
|
||||||
{
|
if (!r.cameras.Size()) {
|
||||||
if (!r.cameras.Size()) return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mScene->mNumCameras = r.cameras.Size();
|
mScene->mNumCameras = r.cameras.Size();
|
||||||
mScene->mCameras = new aiCamera*[r.cameras.Size()];
|
mScene->mCameras = new aiCamera*[r.cameras.Size()];
|
||||||
|
|
||||||
for (size_t i = 0; i < r.cameras.Size(); ++i) {
|
for (size_t i = 0; i < r.cameras.Size(); ++i) {
|
||||||
Camera& cam = r.cameras[i];
|
Camera& cam = r.cameras[i];
|
||||||
|
|
||||||
aiCamera* aicam = mScene->mCameras[i] = new aiCamera();
|
aiCamera* aicam = mScene->mCameras[i] = new aiCamera();
|
||||||
|
|
||||||
if (cam.type == Camera::Perspective) {
|
if (cam.type == Camera::Perspective) {
|
||||||
|
|
||||||
aicam->mAspect = cam.perspective.aspectRatio;
|
aicam->mAspect = cam.perspective.aspectRatio;
|
||||||
aicam->mHorizontalFOV = cam.perspective.yfov * aicam->mAspect;
|
aicam->mHorizontalFOV = cam.perspective.yfov * aicam->mAspect;
|
||||||
aicam->mClipPlaneFar = cam.perspective.zfar;
|
aicam->mClipPlaneFar = cam.perspective.zfar;
|
||||||
aicam->mClipPlaneNear = cam.perspective.znear;
|
aicam->mClipPlaneNear = cam.perspective.znear;
|
||||||
}
|
} else {
|
||||||
else {
|
aicam->mClipPlaneFar = cam.ortographic.zfar;
|
||||||
// assimp does not support orthographic cameras
|
aicam->mClipPlaneNear = cam.ortographic.znear;
|
||||||
|
aicam->mHorizontalFOV = 0.0;
|
||||||
|
aicam->mAspect = cam.ortographic.xmag / cam.ortographic.ymag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,6 @@ struct aiCamera
|
||||||
*/
|
*/
|
||||||
C_STRUCT aiVector3D mPosition;
|
C_STRUCT aiVector3D mPosition;
|
||||||
|
|
||||||
|
|
||||||
/** 'Up' - vector of the camera coordinate system relative to
|
/** 'Up' - vector of the camera coordinate system relative to
|
||||||
* the coordinate space defined by the corresponding node.
|
* the coordinate space defined by the corresponding node.
|
||||||
*
|
*
|
||||||
|
@ -134,7 +133,6 @@ struct aiCamera
|
||||||
*/
|
*/
|
||||||
C_STRUCT aiVector3D mLookAt;
|
C_STRUCT aiVector3D mLookAt;
|
||||||
|
|
||||||
|
|
||||||
/** Half horizontal field of view angle, in radians.
|
/** Half horizontal field of view angle, in radians.
|
||||||
*
|
*
|
||||||
* The field of view angle is the angle between the center
|
* The field of view angle is the angle between the center
|
||||||
|
|
Loading…
Reference in New Issue