Native Blender file format support in progress
Changed material colour parameters from separate float values to KRVector3's --HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4056
This commit is contained in:
@@ -30,6 +30,8 @@
|
||||
E461A176152E5C5600F2044A /* KRPointLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A157152E555400F2044A /* KRPointLight.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
E461A177152E5C6600F2044A /* KRMat4.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017613C99BDC0098455B /* KRMat4.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
E461A17A152E5C9100F2044A /* KRMat4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017713C99BDC0098455B /* KRMat4.cpp */; };
|
||||
E46A6B6D1559E97D000DBD37 /* KRResource+blend.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46A6B6C1559E97D000DBD37 /* KRResource+blend.cpp */; };
|
||||
E46A6B701559EF0A000DBD37 /* KRResource+blend.h in Headers */ = {isa = PBXBuildFile; fileRef = E46A6B6F1559EF0A000DBD37 /* KRResource+blend.h */; };
|
||||
E46C214515364BC8009CABF3 /* tinyxml2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46C214215364BC8009CABF3 /* tinyxml2.cpp */; };
|
||||
E46C214615364BC8009CABF3 /* tinyxml2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46C214215364BC8009CABF3 /* tinyxml2.cpp */; };
|
||||
E46C214715364BC8009CABF3 /* tinyxml2.h in Headers */ = {isa = PBXBuildFile; fileRef = E46C214315364BC8009CABF3 /* tinyxml2.h */; };
|
||||
@@ -159,6 +161,8 @@
|
||||
E461A15E152E565700F2044A /* KRDirectionalLight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRDirectionalLight.cpp; path = Classes/KRDirectionalLight.cpp; sourceTree = "<group>"; };
|
||||
E461A164152E56C000F2044A /* KRSpotLight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRSpotLight.cpp; path = Classes/KRSpotLight.cpp; sourceTree = "<group>"; };
|
||||
E461A167152E570500F2044A /* KRSpotLight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRSpotLight.h; path = Classes/KRSpotLight.h; sourceTree = "<group>"; };
|
||||
E46A6B6C1559E97D000DBD37 /* KRResource+blend.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "KRResource+blend.cpp"; path = "Classes/KRResource+blend.cpp"; sourceTree = "<group>"; };
|
||||
E46A6B6F1559EF0A000DBD37 /* KRResource+blend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "KRResource+blend.h"; path = "Classes/KRResource+blend.h"; sourceTree = "<group>"; };
|
||||
E46C214115364BC8009CABF3 /* tinyxml2_readme.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = tinyxml2_readme.txt; path = KREngine/Classes/tinyxml2_readme.txt; sourceTree = "<group>"; };
|
||||
E46C214215364BC8009CABF3 /* tinyxml2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tinyxml2.cpp; path = KREngine/Classes/tinyxml2.cpp; sourceTree = "<group>"; };
|
||||
E46C214315364BC8009CABF3 /* tinyxml2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = tinyxml2.h; path = KREngine/Classes/tinyxml2.h; sourceTree = "<group>"; };
|
||||
@@ -279,6 +283,8 @@
|
||||
E497B949151BCEE900D3DC67 /* KRResource.h */,
|
||||
E497B94C151BCF2500D3DC67 /* KRResource.cpp */,
|
||||
E497B94F151BD2CE00D3DC67 /* KRResource+obj.cpp */,
|
||||
E46A6B6C1559E97D000DBD37 /* KRResource+blend.cpp */,
|
||||
E46A6B6F1559EF0A000DBD37 /* KRResource+blend.h */,
|
||||
E497B952151BEDA600D3DC67 /* KRResource+fbx.cpp */,
|
||||
);
|
||||
name = Resources;
|
||||
@@ -542,6 +548,7 @@
|
||||
E461A15D152E563100F2044A /* KRDirectionalLight.h in Headers */,
|
||||
E461A169152E570700F2044A /* KRSpotLight.h in Headers */,
|
||||
E46C214815364BC8009CABF3 /* tinyxml2.h in Headers */,
|
||||
E46A6B701559EF0A000DBD37 /* KRResource+blend.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -692,6 +699,7 @@
|
||||
E4D13364153767ED0070068C /* KRShaderManager.cpp in Sources */,
|
||||
E46C214C15364DEC009CABF3 /* KRSceneManager.cpp in Sources */,
|
||||
E48C697315374F7E00232E28 /* KRContext.cpp in Sources */,
|
||||
E46A6B6D1559E97D000DBD37 /* KRResource+blend.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -121,7 +121,6 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
||||
// Disable z-buffer write
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
//if(view_space_light_position.GetMagnitude() > influence_radius) {
|
||||
// Render sphere of light's influence
|
||||
generateMesh();
|
||||
|
||||
@@ -134,30 +133,6 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, m_sphereVertices);
|
||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
||||
glDrawArrays(GL_TRIANGLES, 0, m_cVertices);
|
||||
/*
|
||||
} else {
|
||||
// Sphere would be clipped against view frustrum. Fall back to a full screen quad
|
||||
|
||||
// Disable z-buffer test
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
// Render a full screen quad
|
||||
static const GLfloat squareVertices[] = {
|
||||
-1.0f, -1.0f, 0.0f,
|
||||
1.0f, -1.0f, 0.0f,
|
||||
-1.0f, 1.0f, 0.0f,
|
||||
1.0f, 1.0f, 0.0f,
|
||||
};
|
||||
|
||||
KRMat4 matIdentity;
|
||||
glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MVP], 1, GL_FALSE, matIdentity.getPointer());
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, squareVertices);
|
||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
175
KREngine/KREngine/Classes/KRResource+blend.cpp
Normal file
175
KREngine/KREngine/Classes/KRResource+blend.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
//
|
||||
// KRResource+blend.cpp
|
||||
// KREngine
|
||||
//
|
||||
// Created by Kearwood Gilbert on 12-05-08.
|
||||
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <stdint.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "KRResource.h"
|
||||
#include "KRMesh.h"
|
||||
#include "KRScene.h"
|
||||
#include "KRResource+blend.h"
|
||||
|
||||
|
||||
std::vector<KRResource *> KRResource::LoadBlenderScene(const std::string& path) {
|
||||
std::vector<KRResource *> resources;
|
||||
KRScene *pScene = new KRScene(KRResource::GetFileBase(path));
|
||||
resources.push_back(pScene);
|
||||
|
||||
int fdFile = 0;
|
||||
int fileSize = 0;
|
||||
void *pFile = NULL;
|
||||
|
||||
struct stat statbuf;
|
||||
fdFile = open(path.c_str(), O_RDONLY);
|
||||
if(fdFile >= 0) {
|
||||
if(fstat(fdFile, &statbuf) >= 0) {
|
||||
if ((pFile = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, fdFile, 0)) == (caddr_t) -1) {
|
||||
} else {
|
||||
fileSize = statbuf.st_size;
|
||||
|
||||
|
||||
KRBlendFile blend_file = KRBlendFile(pFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(pFile != NULL) {
|
||||
munmap(pFile, fileSize);
|
||||
}
|
||||
|
||||
if(fdFile != 0) {
|
||||
close(fdFile);
|
||||
}
|
||||
|
||||
|
||||
return resources;
|
||||
}
|
||||
|
||||
|
||||
KRBlendFile::KRBlendFile(const void *pFile) {
|
||||
unsigned char *scan = (unsigned char *)pFile;
|
||||
readHeader(scan);
|
||||
std::string block_code = "";
|
||||
while(block_code != "ENDB") {
|
||||
Block b = Block(this, scan);
|
||||
block_code = b.getCode();
|
||||
m_blocks.push_back(b);
|
||||
|
||||
printf("Loaded block: %s - %i bytes\n", b.getCode().c_str(), b.getDataSize());
|
||||
}
|
||||
}
|
||||
|
||||
void KRBlendFile::readHeader(unsigned char *&scan) {
|
||||
if(strncmp((char *)scan, "BLENDER", 7) != 0) {
|
||||
// TODO throw exception
|
||||
}
|
||||
scan += 7;
|
||||
if(scan[0] == '_' && scan[1] == 'v') {
|
||||
// 32-bit, little-endian
|
||||
m_file_type = KRBLEND_LITTLEENDIAN_32BIT;
|
||||
} else if(scan[0] == '_' && scan[1] == 'V') {
|
||||
// 32-bit, bit-endian
|
||||
m_file_type = KRBLEND_BIGENDIAN_32BIT;
|
||||
} else if(scan[0] == '-' && scan[1] == 'v') {
|
||||
// 64-bit, little-endian
|
||||
m_file_type = KRBLEND_LITTLEENDIAN_64BIT;
|
||||
} else if(scan[0] == '-' && scan[1] == 'V') {
|
||||
// 64-bit, big-endian
|
||||
m_file_type = KRBLEND_BIGENDIAN_64BIT;
|
||||
} else {
|
||||
// TODO - throw exception
|
||||
}
|
||||
scan += 5; // Skip and ignore version
|
||||
}
|
||||
|
||||
__int32_t KRBlendFile::readInt(unsigned char *&scan) {
|
||||
__int32_t ret = 0;
|
||||
// read a 32-bit integer and increment scan
|
||||
|
||||
switch (m_file_type) {
|
||||
case KRBLEND_BIGENDIAN_32BIT:
|
||||
case KRBLEND_BIGENDIAN_64BIT:
|
||||
ret = (__int32_t)scan[3] + (__int32_t)scan[2] * 0x100 + (__int32_t)scan[1] * 0x10000 + (__int32_t)scan[0] * 0x1000000;
|
||||
break;
|
||||
case KRBLEND_LITTLEENDIAN_32BIT:
|
||||
case KRBLEND_LITTLEENDIAN_64BIT:
|
||||
ret = (__int32_t)scan[0] + (__int32_t)scan[1] * 0x100 + (__int32_t)scan[2] * 0x10000 + (__int32_t)scan[3] * 0x1000000;
|
||||
break;
|
||||
}
|
||||
|
||||
scan += 4;
|
||||
return ret;
|
||||
}
|
||||
|
||||
__int64_t KRBlendFile::readPointer(unsigned char *&scan) {
|
||||
__int64_t ret = 0;
|
||||
// read a 32-bit integer and increment scan
|
||||
switch (m_file_type) {
|
||||
case KRBLEND_BIGENDIAN_32BIT:
|
||||
ret = scan[3] + scan[2] * 0x100 + scan[1] * 0x10000 + scan[0] * 0x1000000;
|
||||
scan += 4;
|
||||
break;
|
||||
case KRBLEND_LITTLEENDIAN_32BIT:
|
||||
ret = scan[0] + scan[1] * 0x100 + scan[2] * 0x10000 + scan[3] * 0x1000000;
|
||||
scan += 4;
|
||||
break;
|
||||
|
||||
case KRBLEND_BIGENDIAN_64BIT:
|
||||
ret = scan[7] + scan[6] * 0x100 + scan[5] * 0x10000 + scan[4] * 0x1000000 + scan[3] * 0x100000000 + scan[2] * 0x10000000000 + scan[1] * 0x1000000000000 + scan[0] * 0x100000000000000;
|
||||
scan += 8;
|
||||
break;
|
||||
case KRBLEND_LITTLEENDIAN_64BIT:
|
||||
ret = scan[0] + scan[1] * 0x100 + scan[2] * 0x10000 + scan[3] * 0x1000000 + scan[4] * 0x100000000 + scan[5] * 0x10000000000 + scan[6] * 0x1000000000000 + scan[7] * 0x100000000000000;
|
||||
scan += 8;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
KRBlendFile::~KRBlendFile() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
KRBlendFile::Block::Block(KRBlendFile *blendFile, unsigned char *&scan) {
|
||||
scan += (__int64_t)scan % 4; // Scan forward until the next 4-byte boundary
|
||||
char szBlock[5];
|
||||
szBlock[0] = *scan++;
|
||||
szBlock[1] = *scan++;
|
||||
szBlock[2] = *scan++;
|
||||
szBlock[3] = *scan++;
|
||||
szBlock[4] = '\0';
|
||||
m_code = szBlock;
|
||||
m_dataSize = blendFile->readInt(scan);
|
||||
m_prev_pointer = blendFile->readPointer(scan);
|
||||
m_sdna_index = blendFile->readInt(scan);
|
||||
m_structure_count = blendFile->readInt(scan);
|
||||
m_data = scan;
|
||||
scan += m_dataSize;
|
||||
}
|
||||
KRBlendFile::Block::~Block() {
|
||||
|
||||
}
|
||||
|
||||
std::string KRBlendFile::Block::getCode() {
|
||||
return m_code;
|
||||
}
|
||||
|
||||
int KRBlendFile::Block::getDataSize() {
|
||||
return m_dataSize;
|
||||
}
|
||||
|
||||
50
KREngine/KREngine/Classes/KRResource+blend.h
Normal file
50
KREngine/KREngine/Classes/KRResource+blend.h
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// KRResource+blend.h
|
||||
// KREngine
|
||||
//
|
||||
// Created by Kearwood Gilbert on 12-05-08.
|
||||
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef KREngine_KRResource_blend_h
|
||||
#define KREngine_KRResource_blend_h
|
||||
|
||||
class KRBlendFile {
|
||||
public:
|
||||
KRBlendFile(const void *pFile);
|
||||
~KRBlendFile();
|
||||
|
||||
class Block {
|
||||
public:
|
||||
Block(KRBlendFile *blendFile, unsigned char *&scan);
|
||||
~Block();
|
||||
|
||||
std::string getCode();
|
||||
int getDataSize();
|
||||
private:
|
||||
std::string m_code;
|
||||
__int32_t m_dataSize;
|
||||
__int32_t m_sdna_index;
|
||||
__int32_t m_structure_count;
|
||||
__int64_t m_prev_pointer;
|
||||
unsigned char *m_data;
|
||||
};
|
||||
|
||||
private:
|
||||
enum file_type {
|
||||
KRBLEND_LITTLEENDIAN_32BIT,
|
||||
KRBLEND_LITTLEENDIAN_64BIT,
|
||||
KRBLEND_BIGENDIAN_32BIT,
|
||||
KRBLEND_BIGENDIAN_64BIT
|
||||
} m_file_type;
|
||||
void readHeader(unsigned char *&scan);
|
||||
|
||||
__int32_t readInt(unsigned char *&scan);
|
||||
__int64_t readPointer(unsigned char *&scan);
|
||||
|
||||
std::vector<Block> m_blocks;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -433,15 +433,15 @@ void LoadMesh(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxGeo
|
||||
|
||||
// Ambient Color
|
||||
lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Ambient;
|
||||
new_material->setAmbient(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);
|
||||
new_material->setAmbient(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]));
|
||||
|
||||
// Diffuse Color
|
||||
lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Diffuse;
|
||||
new_material->setDiffuse(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);
|
||||
new_material->setDiffuse(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]));
|
||||
|
||||
// Specular Color (unique to Phong materials)
|
||||
lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Specular;
|
||||
new_material->setSpecular(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);
|
||||
new_material->setSpecular(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]));
|
||||
|
||||
// Emissive Color
|
||||
//lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Emissive;
|
||||
@@ -468,11 +468,11 @@ void LoadMesh(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxGeo
|
||||
|
||||
// Ambient Color
|
||||
lKFbxDouble3=((KFbxSurfaceLambert *)pMaterial)->Ambient;
|
||||
new_material->setAmbient(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);
|
||||
new_material->setAmbient(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]));
|
||||
|
||||
// Diffuse Color
|
||||
lKFbxDouble3 =((KFbxSurfaceLambert *)pMaterial)->Diffuse;
|
||||
new_material->setDiffuse(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);
|
||||
new_material->setDiffuse(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]));
|
||||
|
||||
// Emissive
|
||||
//lKFbxDouble3 =((KFbxSurfaceLambert *)pMaterial)->Emissive;
|
||||
|
||||
@@ -64,6 +64,8 @@ std::vector<KRResource *> KRResource::Load(const std::string& path)
|
||||
return LoadObj(path);
|
||||
} else if(extension.compare("fbx") == 0) {
|
||||
return LoadFbx(path);
|
||||
} else if(extension.compare("blend") == 0) {
|
||||
return LoadBlenderScene(path);
|
||||
}
|
||||
|
||||
return resources;
|
||||
|
||||
@@ -40,6 +40,7 @@ private:
|
||||
|
||||
static std::vector<KRResource *> LoadObj(const std::string& path);
|
||||
static std::vector<KRResource *> LoadFbx(const std::string& path);
|
||||
static std::vector<KRResource *> LoadBlenderScene(const std::string& path);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -246,8 +246,8 @@ void KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix
|
||||
|
||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_FRAME], 6);
|
||||
|
||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_DEPTH], 7);
|
||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_REFLECTIONTEXTURE], 7);
|
||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_DEPTH], 7); // Texture unit 7 is used for reading the depth buffer in gBuffer pass #2 and in post-processing pass
|
||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_REFLECTIONTEXTURE], 7); // Texture unit 7 is used for the reflection map textures in gBuffer pass #3 and when using forward rendering
|
||||
|
||||
#if defined(DEBUG)
|
||||
GLint logLength;
|
||||
|
||||
Reference in New Issue
Block a user