Explorar o código

Removed old broken modules, Mesh will not reset indexed setting on clearMesh anymore

Ivan Safrin %!s(int64=12) %!d(string=hai) anos
pai
achega
56956e3054

+ 1 - 1
Core/Contents/Source/PolyMesh.cpp

@@ -86,7 +86,7 @@ void Mesh::clearMesh() {
             renderDataArrays[i] = NULL;
             renderDataArrays[i] = NULL;
         }
         }
     }
     }
-    indexedMesh = false;
+
     useFaceNormals = false;
     useFaceNormals = false;
     meshHasVertexBuffer = false;
     meshHasVertexBuffer = false;
 }
 }

+ 0 - 118
Modules/Contents/CgShading/Include/PolyCGProgram.h

@@ -1,118 +0,0 @@
-/*
-Copyright (C) 2011 by Ivan Safrin
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Polycode.h"
-
-#include "PolyGlobals.h"
-
-#include "PolyLogger.h"
-#include "PolyResource.h"
-#include "PolyVector3.h"
-#include "PolyUtil.h"
-#include <vector>
-#include <CG/cg.h>
-
-using std::vector;
-
-namespace Polycode {
-
-class _PolyExport CGProgramParam {
-	public:
-	
-	CGparameter cgParam;
-	String name;
-	bool isAuto;
-	int autoID;
-	void *defaultData;
-	int paramType;
-	
-	static void *createParamData(int *retType, String type, String value);
-	
-	static const int POLY_MODELVIEWPROJ_MATRIX = 0;
-	static const int POLY_MODELVIEW_MATRIX = 2;
-	static const int POLY_MODELVIEW_INVERSE_MATRIX = 3;
-	static const int POLY_EXPOSURE_LEVEL = 7;
-	static const int POLY_CLEARCOLOR = 10;
-	static const int POLY_AMBIENTCOLOR = 11;	
-	
-	static const int POLY_AREA_LIGHT_POSITION_0 = 12;
-	static const int POLY_AREA_LIGHT_COLOR_0 = 13;	
-	static const int POLY_AREA_LIGHT_POSITION_1 = 14;
-	static const int POLY_AREA_LIGHT_COLOR_1 = 15;	
-	static const int POLY_AREA_LIGHT_POSITION_2 = 16;
-	static const int POLY_AREA_LIGHT_COLOR_2 = 17;	
-	static const int POLY_AREA_LIGHT_POSITION_3 = 18;
-	static const int POLY_AREA_LIGHT_COLOR_3 = 19;	
-	static const int POLY_AREA_LIGHT_POSITION_4 = 20;
-	static const int POLY_AREA_LIGHT_COLOR_4 = 21;	
-	static const int POLY_AREA_LIGHT_POSITION_5 = 22;
-	static const int POLY_AREA_LIGHT_COLOR_5 = 23;	
-	static const int POLY_AREA_LIGHT_POSITION_6 = 24;
-	static const int POLY_AREA_LIGHT_COLOR_6 = 25;	
-	static const int POLY_AREA_LIGHT_POSITION_7 = 26;
-	static const int POLY_AREA_LIGHT_COLOR_7 = 27;	
-
-	static const int POLY_SPOT_LIGHT_POSITION_0 = 30;
-	static const int POLY_SPOT_LIGHT_COLOR_0 = 31;
-	static const int POLY_SPOT_LIGHT_DIRECTION_0 = 32;
-	static const int POLY_SPOT_LIGHT_POSITION_1 = 33;
-	static const int POLY_SPOT_LIGHT_COLOR_1 = 34;
-	static const int POLY_SPOT_LIGHT_DIRECTION_1 = 35;
-	static const int POLY_SPOT_LIGHT_POSITION_2 = 36;
-	static const int POLY_SPOT_LIGHT_COLOR_2 = 37;
-	static const int POLY_SPOT_LIGHT_DIRECTION_2 = 38;
-	static const int POLY_SPOT_LIGHT_POSITION_3 = 39;
-	static const int POLY_SPOT_LIGHT_COLOR_3 = 40;
-	static const int POLY_SPOT_LIGHT_DIRECTION_3 = 41;
-	
-	static const int POLY_SPOT_LIGHT_TEXTUREMATRIX_0 = 42;	
-	static const int POLY_SPOT_LIGHT_TEXTUREMATRIX_1 = 43;
-	static const int POLY_SPOT_LIGHT_TEXTUREMATRIX_2 = 44;
-	static const int POLY_SPOT_LIGHT_TEXTUREMATRIX_3 = 45;
-	
-	static const int PARAM_UNKNOWN = 0;	
-	static const int PARAM_Number = 1;
-	static const int PARAM_Number3 = 2;
-	static const int PARAM_Number4 = 3;
-	
-	};
-
-	class _PolyExport CGProgram : public Resource {
-		public:
-			CGProgram(int type);
-			~CGProgram();
-			
-			void addParam(String name, bool isAuto, int autoID, int paramType, void *defaultData);
-		
-			CGprogram program;
-			CGparameter modelViewProjection;
-	
-			static const int TYPE_VERT = 0;
-			static const int TYPE_FRAG = 1;		
-			
-			int type;
-			
-			vector<CGProgramParam> params;
-	};
-}

+ 0 - 81
Modules/Contents/CgShading/Include/PolyCGShader.h

@@ -1,81 +0,0 @@
-/*
-Copyright (C) 2011 by Ivan Safrin
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "PolyGlobals.h"
-
-#include "PolyLogger.h"
-#include "PolyShader.h"
-#include "PolyCGProgram.h"
-#include "PolyTexture.h"
-#include "PolyCubemap.h"
-#include <vector>
-#include <CG/cg.h>
-
-using std::vector;
-
-namespace Polycode {
-
-	typedef struct {
-		Texture *texture;
-		String name;
-		CGparameter vpParam;
-	} CGTextureBinding;
-
-	typedef struct {
-		Cubemap *cubemap;
-		String name;
-		CGparameter vpParam;
-	} CGCubemapBinding;
-	
-	
-	class _PolyExport CGShader : public Shader {
-		public:
-			CGShader(CGProgram *vp, CGProgram *fp);
-			virtual ~CGShader();
-
-			ShaderBinding *createBinding();
-			
-			CGProgram *vp;
-			CGProgram *fp;			
-			
-		protected:
-			
-	};
-	
-	class _PolyExport CGShaderBinding : public ShaderBinding {
-		public:
-			CGShaderBinding(CGShader *shader);
-			virtual ~CGShaderBinding();
-			
-			void addTexture(String name, Texture *texture); 
-			void addCubemap(String name, Cubemap *cubemap);				
-			void clearTexture(String name);			
-			void addParam(String type, String name, String value);
-			
-			vector<CGTextureBinding> textures;
-			vector<CGCubemapBinding> cubemaps;		
-		
-			CGShader *cgShader;
-	};
-}

+ 0 - 75
Modules/Contents/CgShading/Include/PolyCGShaderModule.h

@@ -1,75 +0,0 @@
-/*
-Copyright (C) 2011 by Ivan Safrin
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Polycode.h"
-#include "PolyCGProgram.h"
-#include "PolyCGShader.h"
-#include "PolyMaterial.h"
-#include "PolyGLTexture.h"
-#include <string>
-#include <vector>
-#include <CG/cgGL.h>
-
-
-using std::vector;
-using std::string;
-
-namespace Polycode {
-	
-	class _PolyExport CGShaderModule : public PolycodeShaderModule {
-		public:
-			CGShaderModule();
-			virtual ~CGShaderModule();
-		
-			bool acceptsExtension(String extension);
-			Resource* createProgramFromFile(String extension, String fullPath);	
-			void reloadPrograms();
-			String getShaderType();
-			Shader *createShader(TiXmlNode *node);
-			bool applyShaderMaterial(Renderer *renderer, Material *material, ShaderBinding *localOptions, unsigned int shaderIndex);	
-			void clearShader();
-		
-	protected:
-
-		void addParamToProgram(CGProgram *program,TiXmlNode *node);		
-		void recreateCGProgram(CGProgram *prog, String fileName, int type);
-		CGProgram *createCGProgram(String fileName, int type);		
-		void updateCGParam(Renderer *renderer, CGProgramParam &param, ShaderBinding *materialOptions, ShaderBinding *localOptions);		
-			
-		void setCGAreaLightPositionParameter(Renderer *renderer, CGProgramParam &param, int lightIndex);
-		void setCGAreaLightColorParameter(Renderer *renderer, CGProgramParam &param, int lightIndex);	
-		
-		void setCGSpotLightPositionParameter(Renderer *renderer, CGProgramParam &param, int lightIndex);
-		void setCGSpotLightDirectionParameter(Renderer *renderer, CGProgramParam &param, int lightIndex);
-		void setCGSpotLightColorParameter(Renderer *renderer, CGProgramParam &param, int lightIndex);	
-		void setCGSpotLightTextureMatrixParameter(Renderer *renderer, CGProgramParam &param, int lightIndex);		
-		
-		CGcontext cgContext;
-		CGprofile vertexProfile;
-		CGprofile fragmentProfile;
-		
-		vector<CGProgram*> programs;
-	};
-	
-}

+ 0 - 71
Modules/Contents/CgShading/Source/PolyCGProgram.cpp

@@ -1,71 +0,0 @@
-/*
-Copyright (C) 2011 by Ivan Safrin
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-
-#include "PolyCGProgram.h"
-
-using namespace Polycode;
-
-CGProgram::CGProgram(int type) : Resource(Resource::RESOURCE_PROGRAM) {
-	this->type = type;
-}
-
-CGProgram::~CGProgram() {
-
-}
-
-void CGProgram::addParam(String name, bool isAuto, int autoID, int paramType, void *defaultData) {
-	CGProgramParam newParam;
-	newParam.name = name;
-	newParam.paramType = paramType;
-	newParam.defaultData = defaultData;
-	newParam.isAuto = isAuto;
-	newParam.autoID = autoID;
-	newParam.cgParam = cgGetNamedParameter(program, name.c_str());
-	params.push_back(newParam);
-}
-
-void *CGProgramParam::createParamData(int *retType, String type, String value) {
-		void *defaultData;
-		if(type == "Number") {
-			*retType = CGProgramParam::PARAM_Number;
-			Number *val = new Number();
-			*val = atof(value.c_str());
-			defaultData = (void*)val;
-			return defaultData;			
-		} else if(type == "Number3") {
-			*retType = CGProgramParam::PARAM_Number3;
-			Vector3 *val = new Vector3();
-			defaultData = (void*)val;
-			vector<String> values = value.split(" ");
-			if(values.size() == 3) {
-				val->set(atof(values[0].c_str()), atof(values[1].c_str()), atof(values[2].c_str()));
-			} else {
-				Logger::log("Error: A Number3 must have 3 values (%d provided)!\n", values.size());
-			}
-			return defaultData;
-		} else {
-			*retType = CGProgramParam::PARAM_UNKNOWN;
-			return NULL;
-		}
-
-}

+ 0 - 82
Modules/Contents/CgShading/Source/PolyCGShader.cpp

@@ -1,82 +0,0 @@
-/*
-Copyright (C) 2011 by Ivan Safrin
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#include "PolyCGShader.h"
-
-using namespace Polycode;
-
-CGShaderBinding::CGShaderBinding(CGShader *shader) : ShaderBinding(shader) {
-	cgShader = shader;
-}
-
-CGShaderBinding::~CGShaderBinding() {
-	
-}
-
-
-void CGShaderBinding::addTexture(String name, Texture *texture) {
-	CGTextureBinding binding;
-	binding.name = name;
-	binding.texture = texture;
-	binding.vpParam = cgGetNamedParameter(cgShader->fp->program, name.c_str());
-	textures.push_back(binding);
-}
-
-void CGShaderBinding::addCubemap(String name, Cubemap *cubemap) {
-	CGCubemapBinding binding;
-	binding.cubemap = cubemap;
-	binding.name = name;
-	binding.vpParam = cgGetNamedParameter(cgShader->fp->program, name.c_str());
-	cubemaps.push_back(binding);
-}
-
-void CGShaderBinding::clearTexture(String name) {
-	for(int i=0; i < textures.size(); i++) {
-		if(textures[i].name == name) {
-			textures.erase(textures.begin()+i);
-			return;
-		}
-	}
-}
-
-
-void CGShaderBinding::addParam(String type, String name, String value) {
-	int paramType;
-	void *defaultData = CGProgramParam::createParamData(&paramType, type, value);
-	LocalShaderParam *newParam = new LocalShaderParam;
-	newParam->data = defaultData;
-	newParam->name = name;
-	localParams.push_back(newParam);
-}
-
-CGShader::CGShader(CGProgram *vp, CGProgram *fp) : Shader(Shader::MODULE_SHADER) {
-	this->vp = vp;
-	this->fp = fp;
-}
-
-CGShader::~CGShader() {
-
-}
-
-ShaderBinding *CGShader::createBinding() {
-	return new CGShaderBinding(this);
-}

+ 0 - 556
Modules/Contents/CgShading/Source/PolyCGShaderModule.cpp

@@ -1,556 +0,0 @@
-/*
-Copyright (C) 2011 by Ivan Safrin
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#include "PolyCGShaderModule.h"
-
-using namespace Polycode;
-
-CGShaderModule::CGShaderModule() : PolycodeShaderModule() {
-    if( cgGLIsProfileSupported(CG_PROFILE_ARBVP1) ) {
-		Logger::log("Using vertex profile CG_PROFILE_ARBVP1\n");
-        vertexProfile = CG_PROFILE_ARBVP1;
-	} else if ( cgGLIsProfileSupported(CG_PROFILE_VP40) ) {
-		Logger::log("Using vertex profile CG_PROFILE_VP40\n");
-        vertexProfile = CG_PROFILE_VP40;
-    } else {
-		Logger::log("Error, no required vertex profiles supported by your card\n");
-    }
-	
-	if( cgGLIsProfileSupported(CG_PROFILE_ARBFP1) ) {
-		Logger::log("Using fragment profile CG_PROFILE_ARBFP1\n");
-        fragmentProfile = CG_PROFILE_ARBFP1;		
-    } else if( cgGLIsProfileSupported(CG_PROFILE_FP30) ) {
-		Logger::log("Using fragment profile CG_PROFILE_FP30\n");
-        fragmentProfile = CG_PROFILE_FP30;
-	} else if( cgGLIsProfileSupported(CG_PROFILE_FP20) ) {
-		Logger::log("Using fragment profile CG_PROFILE_FP20\n");
-        fragmentProfile = CG_PROFILE_FP20;
-    } else {
-		Logger::log("Error, no required fragment profiles supported by your card\n");
-		return;
-    }
-	
-	cgContext = cgCreateContext();		
-}
-
-CGShaderModule::~CGShaderModule() {
-	cgDestroyContext(cgContext);	
-}
-
-bool CGShaderModule::acceptsExtension(String extension) {
-	if(extension == "cgvert" || extension == "cgfrag") {
-		return true;
-	} else {
-		return false;
-	}
-}
-
-String CGShaderModule::getShaderType() {
-	return "cg";
-}
-
-Shader *CGShaderModule::createShader(TiXmlNode *node) {
-	TiXmlNode* pChild, *pChild2, *pChild3;	
-	CGProgram *vp = NULL;
-	CGProgram *fp = NULL;
-	CGShader *retShader = NULL;
-	
-	for (pChild = node->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) {
-		if(strcmp(pChild->Value(), "vp") == 0) {
-			vp = (CGProgram*)CoreServices::getInstance()->getResourceManager()->getResource(Resource::RESOURCE_PROGRAM, pChild->ToElement()->Attribute("source"));
-			if(vp) {
-				for (pChild2 = pChild->FirstChild(); pChild2 != 0; pChild2 = pChild2->NextSibling()) {
-					if(strcmp(pChild2->Value(), "params") == 0) {
-						for (pChild3 = pChild2->FirstChild(); pChild3 != 0; pChild3 = pChild3->NextSibling()) {
-							if(strcmp(pChild3->Value(), "param") == 0) {
-								addParamToProgram(vp,pChild3); 
-							}
-						}
-					}
-				}
-			}
-		}
-		if(strcmp(pChild->Value(), "fp") == 0) {
-			fp = (CGProgram*)CoreServices::getInstance()->getResourceManager()->getResource(Resource::RESOURCE_PROGRAM, pChild->ToElement()->Attribute("source"));
-			if(fp) {
-				for (pChild2 = pChild->FirstChild(); pChild2 != 0; pChild2 = pChild2->NextSibling()) {
-					if(strcmp(pChild2->Value(), "params") == 0) {
-						for (pChild3 = pChild2->FirstChild(); pChild3 != 0; pChild3 = pChild3->NextSibling()) {
-							if(strcmp(pChild3->Value(), "param") == 0) {
-								addParamToProgram(fp,pChild3); 										
-							}
-						}
-					}
-				}
-			}
-		}
-		
-	}
-	if(vp != NULL && fp != NULL) {
-		CGShader *cgShader = new CGShader(vp,fp);
-		cgShader->setName(node->ToElement()->Attribute("name"));
-		retShader = cgShader;
-		shaders.push_back((Shader*)cgShader);
-	}
-	return retShader;
-
-}
-
-void CGShaderModule::clearShader() {
-	cgGLDisableProfile(fragmentProfile);
-	cgGLDisableProfile(vertexProfile);	
-}
-
-void CGShaderModule::setCGAreaLightPositionParameter(Renderer *renderer, CGProgramParam &param, int lightIndex) {
-	if(renderer->getNumAreaLights() > lightIndex) {
-		vector<LightInfo> areaLights = renderer->getAreaLights();			
-		Vector3 lPos(areaLights[lightIndex].position.x,areaLights[lightIndex].position.y,areaLights[lightIndex].position.z);
-		lPos = renderer->getCameraMatrix().Inverse() * lPos;
-		cgGLSetParameter4f(param.cgParam, lPos.x,lPos.y,lPos.z, areaLights[lightIndex].distance);
-	} else {
-		cgGLSetParameter4f(param.cgParam, 0,0,0,0);
-	}	
-}
-
-void CGShaderModule::setCGSpotLightPositionParameter(Renderer *renderer, CGProgramParam &param, int lightIndex) {
-	if(renderer->getNumSpotLights() > lightIndex) {
-		vector<LightInfo> spotLights = renderer->getSpotLights();		
-		Vector3 lPos(spotLights[lightIndex].position.x,spotLights[lightIndex].position.y,spotLights[lightIndex].position.z);
-		lPos = renderer->getCameraMatrix().Inverse() * lPos;
-		cgGLSetParameter4f(param.cgParam, lPos.x,lPos.y,lPos.z, spotLights[lightIndex].distance);
-	} else {
-		cgGLSetParameter4f(param.cgParam, 0,0,0,0);
-	}	
-}
-
-void CGShaderModule::setCGSpotLightDirectionParameter(Renderer *renderer, CGProgramParam &param, int lightIndex) {
-	if(renderer->getNumSpotLights() > lightIndex) {
-		vector<LightInfo> spotLights = renderer->getSpotLights();		
-		Vector3 lPos(spotLights[lightIndex].dir.x,spotLights[lightIndex].dir.y,spotLights[lightIndex].dir.z);
-		lPos = renderer->getCameraMatrix().Inverse().rotateVector(lPos);
-		cgGLSetParameter3f(param.cgParam, lPos.x,lPos.y,lPos.z);
-	} else {
-		cgGLSetParameter3f(param.cgParam, 0.0f,0.0f,0.0f);
-	}				
-}
-
-void CGShaderModule::setCGAreaLightColorParameter(Renderer *renderer, CGProgramParam &param, int lightIndex) {
-	if(renderer->getNumAreaLights() > lightIndex) {
-		vector<LightInfo> areaLights = renderer->getAreaLights();		
-		cgGLSetParameter4f(param.cgParam, areaLights[lightIndex].color.x,areaLights[lightIndex].color.y,areaLights[lightIndex].color.z, areaLights[lightIndex].intensity);
-	} else {
-		cgGLSetParameter4f(param.cgParam, 0,0,0,0);
-	}
-}
-
-void CGShaderModule::setCGSpotLightColorParameter(Renderer *renderer, CGProgramParam &param, int lightIndex) {
-	if(renderer->getNumSpotLights() > lightIndex) {
-		vector<LightInfo> spotLights = renderer->getSpotLights();			
-		cgGLSetParameter4f(param.cgParam, spotLights[lightIndex].color.x,spotLights[lightIndex].color.y,spotLights[lightIndex].color.z, spotLights[lightIndex].intensity);
-	} else {
-		cgGLSetParameter4f(param.cgParam, 0,0,0,0);
-	}
-}
-
-void CGShaderModule::setCGSpotLightTextureMatrixParameter(Renderer *renderer, CGProgramParam &param, int lightIndex) {
-	if(renderer->getNumLights() > lightIndex) {
-		vector<LightInfo> spotLights = renderer->getSpotLights();			
-		glMatrixMode(GL_MODELVIEW);
-		glPushMatrix();
-		glLoadMatrixf((GLfloat*)spotLights[lightIndex].textureMatrix.ml);				
-		cgGLSetStateMatrixParameter(param.cgParam, CG_GL_MODELVIEW_MATRIX,CG_GL_MATRIX_IDENTITY);
-		glPopMatrix();
-	}					
-}
-
-
-
-void CGShaderModule::updateCGParam(Renderer *renderer, CGProgramParam &param, ShaderBinding *materialOptions, ShaderBinding *localOptions) {
-	if(param.isAuto) {
-		switch(param.autoID) {
-			case CGProgramParam::POLY_MODELVIEWPROJ_MATRIX:
-				cgGLSetStateMatrixParameter(param.cgParam, CG_GL_MODELVIEW_PROJECTION_MATRIX,CG_GL_MATRIX_IDENTITY);
-				break;
-				
-			case CGProgramParam::POLY_SPOT_LIGHT_TEXTUREMATRIX_0:
-				setCGSpotLightTextureMatrixParameter(renderer, param, 0);					
-				break;
-			case CGProgramParam::POLY_SPOT_LIGHT_TEXTUREMATRIX_1:
-				setCGSpotLightTextureMatrixParameter(renderer, param, 1);					
-				break;
-			case CGProgramParam::POLY_SPOT_LIGHT_TEXTUREMATRIX_2:
-				setCGSpotLightTextureMatrixParameter(renderer, param, 2);					
-				break;
-			case CGProgramParam::POLY_SPOT_LIGHT_TEXTUREMATRIX_3:
-				setCGSpotLightTextureMatrixParameter(renderer, param, 3);					
-				break;
-				
-				
-			case CGProgramParam::POLY_AMBIENTCOLOR:
-				cgGLSetParameter3f(param.cgParam, renderer->ambientColor.r,renderer->ambientColor.g,renderer->ambientColor.b);
-				break;
-			case CGProgramParam::POLY_CLEARCOLOR:
-				cgGLSetParameter3f(param.cgParam, renderer->clearColor.r,renderer->clearColor.g,renderer->clearColor.b);				
-				break;				
-				
-			case CGProgramParam::POLY_SPOT_LIGHT_DIRECTION_0:
-				setCGSpotLightDirectionParameter(renderer, param, 0);
-				break;
-			case CGProgramParam::POLY_SPOT_LIGHT_DIRECTION_1:
-				setCGSpotLightDirectionParameter(renderer, param, 1);
-				break;
-			case CGProgramParam::POLY_SPOT_LIGHT_DIRECTION_2:
-				setCGSpotLightDirectionParameter(renderer, param, 2);
-				break;
-			case CGProgramParam::POLY_SPOT_LIGHT_DIRECTION_3:
-				setCGSpotLightDirectionParameter(renderer, param, 3);
-				break;
-				
-			case CGProgramParam::POLY_AREA_LIGHT_POSITION_0:
-				setCGAreaLightPositionParameter(renderer, param, 0);
-				break;
-			case CGProgramParam::POLY_AREA_LIGHT_POSITION_1:
-				setCGAreaLightPositionParameter(renderer, param, 1);
-				break;
-			case CGProgramParam::POLY_AREA_LIGHT_POSITION_2:
-				setCGAreaLightPositionParameter(renderer, param, 2);
-				break;
-			case CGProgramParam::POLY_AREA_LIGHT_POSITION_3:
-				setCGAreaLightPositionParameter(renderer, param, 3);
-				break;
-			case CGProgramParam::POLY_AREA_LIGHT_POSITION_4:
-				setCGAreaLightPositionParameter(renderer, param, 4);
-				break;
-			case CGProgramParam::POLY_AREA_LIGHT_POSITION_5:
-				setCGAreaLightPositionParameter(renderer, param, 5);
-				break;
-			case CGProgramParam::POLY_AREA_LIGHT_POSITION_6:
-				setCGAreaLightPositionParameter(renderer, param, 6);
-				break;
-			case CGProgramParam::POLY_AREA_LIGHT_POSITION_7:
-				setCGAreaLightPositionParameter(renderer, param, 7);
-				break;				
-				
-			case CGProgramParam::POLY_SPOT_LIGHT_POSITION_0:
-				setCGSpotLightPositionParameter(renderer, param, 0);
-				break;				
-			case CGProgramParam::POLY_SPOT_LIGHT_POSITION_1:
-				setCGSpotLightPositionParameter(renderer, param, 1);
-				break;				
-			case CGProgramParam::POLY_SPOT_LIGHT_POSITION_2:
-				setCGSpotLightPositionParameter(renderer, param, 2);
-				break;				
-			case CGProgramParam::POLY_SPOT_LIGHT_POSITION_3:
-				setCGSpotLightPositionParameter(renderer, param, 3);
-				break;				
-				
-			case CGProgramParam::POLY_AREA_LIGHT_COLOR_0:
-				setCGAreaLightColorParameter(renderer, param, 0);
-				break;
-			case CGProgramParam::POLY_AREA_LIGHT_COLOR_1:
-				setCGAreaLightColorParameter(renderer, param, 1);
-				break;
-			case CGProgramParam::POLY_AREA_LIGHT_COLOR_2:
-				setCGAreaLightColorParameter(renderer, param, 2);
-				break;
-			case CGProgramParam::POLY_AREA_LIGHT_COLOR_3:
-				setCGAreaLightColorParameter(renderer, param, 3);
-				break;
-			case CGProgramParam::POLY_AREA_LIGHT_COLOR_4:
-				setCGAreaLightColorParameter(renderer, param, 4);
-				break;
-			case CGProgramParam::POLY_AREA_LIGHT_COLOR_5:
-				setCGAreaLightColorParameter(renderer, param, 5);
-				break;
-			case CGProgramParam::POLY_AREA_LIGHT_COLOR_6:
-				setCGAreaLightColorParameter(renderer, param, 6);
-				break;
-			case CGProgramParam::POLY_AREA_LIGHT_COLOR_7:
-				setCGAreaLightColorParameter(renderer, param, 7);
-				break;
-				
-			case CGProgramParam::POLY_SPOT_LIGHT_COLOR_0:
-				setCGSpotLightColorParameter(renderer, param, 0);
-				break;
-			case CGProgramParam::POLY_SPOT_LIGHT_COLOR_1:
-				setCGSpotLightColorParameter(renderer, param, 1);
-				break;
-			case CGProgramParam::POLY_SPOT_LIGHT_COLOR_2:
-				setCGSpotLightColorParameter(renderer, param, 2);
-				break;
-			case CGProgramParam::POLY_SPOT_LIGHT_COLOR_3:
-				setCGSpotLightColorParameter(renderer, param, 3);
-				break;				
-				
-			case CGProgramParam::POLY_MODELVIEW_MATRIX: {
-				cgGLSetStateMatrixParameter(param.cgParam, CG_GL_MODELVIEW_MATRIX,CG_GL_MATRIX_IDENTITY); }
-				break;
-			case CGProgramParam::POLY_MODELVIEW_INVERSE_MATRIX:
-				cgGLSetStateMatrixParameter(param.cgParam, CG_GL_MODELVIEW_MATRIX,CG_GL_MATRIX_INVERSE_TRANSPOSE);
-				break;
-			case CGProgramParam::POLY_EXPOSURE_LEVEL:
-				cgGLSetParameter1f(param.cgParam, renderer->exposureLevel);
-				break;
-		}
-	} else {
-		void *paramData = param.defaultData;
-		LocalShaderParam *localParam = materialOptions->getLocalParamByName(param.name);
-		if(localParam)
-			paramData = localParam->data;
-		localParam = localOptions->getLocalParamByName(param.name);
-		if(localParam)
-			paramData = localParam->data;
-		
-		Number *fval;
-		
-		switch(param.paramType) {
-			case CGProgramParam::PARAM_Number:
-				fval = (Number*)paramData;
-				cgGLSetParameter1f(param.cgParam, *fval);
-				break;
-			case CGProgramParam::PARAM_Number3:
-				Vector3 *fval3 = (Vector3*)paramData;
-				cgGLSetParameter3f(param.cgParam, fval3->x,fval3->y,fval3->z);
-				break;
-		}
-	}
-}
-
-bool CGShaderModule::applyShaderMaterial(Renderer *renderer, Material *material, ShaderBinding *localOptions, unsigned int shaderIndex) {	
-	
-	glEnable(GL_TEXTURE_2D);
-	CGShader *cgShader = (CGShader*)material->getShader(shaderIndex);
-	CGShaderBinding *cgBinding = (CGShaderBinding*)material->getShaderBinding(shaderIndex);
-	
-	//			Logger::log("applying %s (%s %s)\n", material->getShader()->getName().c_str(), cgShader->vp->getResourceName().c_str(), cgShader->fp->getResourceName().c_str());
-	
-	for(int i=0; i < cgBinding->textures.size(); i++) {
-		cgGLSetTextureParameter(cgBinding->textures[i].vpParam, ((OpenGLTexture*)cgBinding->textures[i].texture)->getTextureID());
-		cgGLEnableTextureParameter(cgBinding->textures[i].vpParam);
-	}
-	
-	for(int i=0; i < cgBinding->cubemaps.size(); i++) {
-		cgGLSetTextureParameter(cgBinding->cubemaps[i].vpParam, ((OpenGLCubemap*)cgBinding->cubemaps[i].cubemap)->getTextureID());
-		cgGLEnableTextureParameter(cgBinding->cubemaps[i].vpParam);
-	}
-	
-	cgBinding = (CGShaderBinding*)localOptions;
-	for(int i=0; i < cgBinding->textures.size(); i++) {
-		cgGLSetTextureParameter(cgBinding->textures[i].vpParam, ((OpenGLTexture*)cgBinding->textures[i].texture)->getTextureID());
-		cgGLEnableTextureParameter(cgBinding->textures[i].vpParam);
-	}			
-	
-	vector<Texture*> shadowMapTextures = renderer->getShadowMapTextures();
-	char texName[32];
-	for(int i=0; i< 4; i++) {
-		if(i < shadowMapTextures.size()) {
-			switch(i) {
-				case 0:
-					strcpy(texName, "shadowMap0");
-					break;
-				case 1:
-					strcpy(texName, "shadowMap1");
-					break;
-				case 2:
-					strcpy(texName, "shadowMap2");
-					break;
-				case 3:
-					strcpy(texName, "shadowMap3");
-					break;							
-			}
-			cgGLSetTextureParameter(cgGetNamedParameter(cgShader->fp->program, texName), ((OpenGLTexture*)shadowMapTextures[i])->getTextureID());
-			cgGLEnableTextureParameter(cgGetNamedParameter(cgShader->fp->program, texName));					
-		}
-	}
-	
-	cgGLEnableProfile(vertexProfile);
-	cgGLBindProgram(cgShader->vp->program);
-	
-	cgGLEnableProfile(fragmentProfile);
-	cgGLBindProgram(cgShader->fp->program);
-	
-	
-	for(int i=0; i < cgShader->vp->params.size(); i++) {
-		CGProgramParam param = cgShader->vp->params[i];
-		updateCGParam(renderer, param, material->getShaderBinding(shaderIndex), localOptions);
-	}
-	
-	for(int i=0; i < cgShader->fp->params.size(); i++) {
-		CGProgramParam param = cgShader->fp->params[i];
-		updateCGParam(renderer, param, material->getShaderBinding(shaderIndex), localOptions);
-	}
-}
-
-void CGShaderModule::addParamToProgram(CGProgram *program,TiXmlNode *node) {
-		bool isAuto = false;
-		int autoID = 0;
-		int paramType = CGProgramParam::PARAM_UNKNOWN;
-		void *defaultData = NULL;
-		
-		if(strcmp(node->ToElement()->Attribute("type"), "auto") == 0) {
-			isAuto = true;
-			String pid = node->ToElement()->Attribute("id");
-			if(pid == "POLY_MODELVIEWPROJ_MATRIX")
-				autoID = CGProgramParam::POLY_MODELVIEWPROJ_MATRIX;
-			else if(pid == "POLY_AREA_LIGHT_POSITION_0")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_POSITION_0;
-			else if(pid == "POLY_AREA_LIGHT_POSITION_1")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_POSITION_1;
-			else if(pid == "POLY_AREA_LIGHT_POSITION_2")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_POSITION_2;
-			else if(pid == "POLY_AREA_LIGHT_POSITION_3")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_POSITION_3;
-			else if(pid == "POLY_AREA_LIGHT_POSITION_4")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_POSITION_4;
-			else if(pid == "POLY_AREA_LIGHT_POSITION_5")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_POSITION_5;
-			else if(pid == "POLY_AREA_LIGHT_POSITION_6")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_POSITION_6;
-			else if(pid == "POLY_AREA_LIGHT_POSITION_7")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_POSITION_7;
-			
-			else if(pid == "POLY_SPOT_LIGHT_POSITION_0")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_POSITION_0;
-			else if(pid == "POLY_SPOT_LIGHT_POSITION_1")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_POSITION_1;
-			else if(pid == "POLY_SPOT_LIGHT_POSITION_2")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_POSITION_2;
-			else if(pid == "POLY_SPOT_LIGHT_POSITION_3")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_POSITION_3;
-			
-			
-			else if(pid == "POLY_AREA_LIGHT_COLOR_0")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_COLOR_0;
-			else if(pid == "POLY_AREA_LIGHT_COLOR_1")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_COLOR_1;
-			else if(pid == "POLY_AREA_LIGHT_COLOR_2")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_COLOR_2;
-			else if(pid == "POLY_AREA_LIGHT_COLOR_3")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_COLOR_3;
-			else if(pid == "POLY_AREA_LIGHT_COLOR_4")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_COLOR_4;
-			else if(pid == "POLY_AREA_LIGHT_COLOR_5")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_COLOR_5;
-			else if(pid == "POLY_AREA_LIGHT_COLOR_6")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_COLOR_6;
-			else if(pid == "POLY_AREA_LIGHT_COLOR_7")
-				autoID = CGProgramParam::POLY_AREA_LIGHT_COLOR_7;
-			
-			else if(pid == "POLY_SPOT_LIGHT_COLOR_0")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_COLOR_0;
-			else if(pid == "POLY_SPOT_LIGHT_COLOR_1")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_COLOR_1;
-			else if(pid == "POLY_SPOT_LIGHT_COLOR_2")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_COLOR_2;
-			else if(pid == "POLY_SPOT_LIGHT_COLOR_3")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_COLOR_3;
-			
-			else if(pid == "POLY_SPOT_LIGHT_DIRECTION_0")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_DIRECTION_0;		
-			else if(pid == "POLY_SPOT_LIGHT_DIRECTION_1")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_DIRECTION_1;		
-			else if(pid == "POLY_SPOT_LIGHT_DIRECTION_2")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_DIRECTION_2;		
-			else if(pid == "POLY_SPOT_LIGHT_DIRECTION_3")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_DIRECTION_3;
-			
-			else if(pid == "POLY_SPOT_LIGHT_TEXTUREMATRIX_0")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_TEXTUREMATRIX_0;
-			else if(pid == "POLY_SPOT_LIGHT_TEXTUREMATRIX_1")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_TEXTUREMATRIX_1;
-			else if(pid == "POLY_SPOT_LIGHT_TEXTUREMATRIX_2")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_TEXTUREMATRIX_2;
-			else if(pid == "POLY_SPOT_LIGHT_TEXTUREMATRIX_3")
-				autoID = CGProgramParam::POLY_SPOT_LIGHT_TEXTUREMATRIX_3;		
-			
-			else if(pid == "POLY_MODELVIEW_MATRIX")
-				autoID = CGProgramParam::POLY_MODELVIEW_MATRIX;
-			else if(pid == "POLY_MODELVIEW_INVERSE_MATRIX")
-				autoID = CGProgramParam::POLY_MODELVIEW_INVERSE_MATRIX;
-			else if(pid == "POLY_EXPOSURE_LEVEL")
-				autoID = CGProgramParam::POLY_EXPOSURE_LEVEL;
-			else if(pid == "POLY_CLEARCOLOR")
-				autoID = CGProgramParam::POLY_CLEARCOLOR;		
-			else if(pid == "POLY_AMBIENTCOLOR")
-				autoID = CGProgramParam::POLY_AMBIENTCOLOR;				
-			else
-				isAuto = false;
-		} else {
-			defaultData = CGProgramParam::createParamData(&paramType, node->ToElement()->Attribute("type"), node->ToElement()->Attribute("default"));
-		}
-		
-		program->addParam(node->ToElement()->Attribute("name"), isAuto, autoID, paramType, defaultData);
-}
-
-void CGShaderModule::reloadPrograms() {
-	for(int i=0; i < programs.size(); i++) {
-		CGProgram *program = programs[i];
-		recreateCGProgram(program, program->getResourcePath(), program->type);	
-	}	
-}
-
-void CGShaderModule::recreateCGProgram(CGProgram *prog, String fileName, int type) {
-	
-	OSFILE *file = OSBasics::open(fileName, "r");
-	OSBasics::seek(file, 0, SEEK_END);	
-	long progsize = OSBasics::tell(file);
-	OSBasics::seek(file, 0, SEEK_SET);
-	char *buffer = (char*)malloc(progsize+1);
-	memset(buffer, 0, progsize+1);
-	OSBasics::read(buffer, progsize, 1, file);
-	
-	if(type == CGProgram::TYPE_VERT) {
-		prog->program = cgCreateProgram(cgContext, CG_SOURCE, buffer, vertexProfile, NULL, NULL);
-	} else {
-		prog->program = cgCreateProgram(cgContext, CG_SOURCE, buffer, fragmentProfile, NULL, NULL);		
-	}
-	
-	free(buffer);	
-	
-	if(prog->program == NULL) {
-		Logger::log("SHADER ERROR!\n");
-		Logger::log("%s\n",cgGetErrorString(cgGetError()));
-		Logger::log("%s\n",cgGetLastListing(cgContext));
-	}
-	
-	cgGLLoadProgram(prog->program);	
-	
-}
-
-CGProgram *CGShaderModule::createCGProgram(String fileName, int type) {
-	CGProgram *prog = new CGProgram(type);	
-	recreateCGProgram(prog, fileName, type);	
-	programs.push_back(prog);
-	return prog;
-}
-
-Resource* CGShaderModule::createProgramFromFile(String extension, String fullPath) {
-	if(extension == "cgvert") {
-		Logger::log("Adding CG vertex program %s\n", fullPath.c_str());				
-		return createCGProgram(fullPath, CGProgram::TYPE_VERT);
-	}
-	if(extension == "cgfrag") {
-		Logger::log("Adding CG fragment program %s\n", fullPath.c_str());
-		return createCGProgram(fullPath, CGProgram::TYPE_FRAG);								
-	}
-	return NULL;
-}

+ 0 - 111
Modules/Contents/Lightmaps/Include/PolyLightmapPacker.h

@@ -1,111 +0,0 @@
-/*
- *  PolyLightmapPacker.h
- *  Poly
- *
- *  Created by Ivan Safrin on 9/24/08.
- *  Copyright 2008 __MyCompanyName__. All rights reserved.
- *
- */
-
-// @package Scene
-
-#pragma once
-
-#include "PolyGlobals.h"
-#include "PolyGenericScene.h"
-#include <vector>
-#include <string>
-#include <sstream>
-
-using std::vector;
-using std::string;
-
-namespace Polycode {
-	
-	class GenericScene;
-	struct LightmapFace;
-	
-	struct Lumel {
-		float u;
-		float v;
-		Vector3 worldPos;
-		Vector3 normal;
-		Vector3 rEnergy;
-		float lumelScale;
-		LightmapFace *face;
-	};
-
-	struct LightmapFace {
-		Polygon *meshPolygon;
-		Polygon *flatPolygon;
-		Polygon *flatUnscaledPolygon;
-		Rectangle area;
-		Rectangle actualArea;
-		Rectangle pixelArea;
-		vector<Lumel*> lumels;
-		int numLumels;
-		int imageID;
-		int projectionAxis;
-		static const int X_PROJECTION = 0;
-		static const int Y_PROJECTION = 1;
-		static const int Z_PROJECTION = 2;		
-	};
-	
-	struct LightmapMesh {
-		SceneMesh *mesh;
-		int imageID;
-		bool processed;
-		vector<LightmapFace*> faces;
-	};
-	
-	class _PolyExport PackNode {
-	public:
-		PackNode() { child[0] = NULL; child[1] = NULL; face = NULL;}
-		~PackNode(){}
-		
-		PackNode *clone();
-		int rootRes;
-		PackNode *Insert(LightmapFace *img);
-		void createRoot(int res);
-		PackNode* child[2];
-		Rectangle rc;
-		LightmapFace *face;
-	};
-	
-	class _PolyExport LightmapPacker {
-	public:
-		LightmapPacker(GenericScene *targetScene);
-		~LightmapPacker();
-		
-		void generateTextures(int resolution, int quality);
-		void unwrapScene();
-		void bindTextures();
-		void buildTextures();
-		
-		Vector3 getLumelPos(Lumel *lumel, LightmapFace *face);
-		
-		void saveLightmaps(string folder);
-
-		vector<LightmapMesh*> lightmapMeshes;
-		vector<Texture*> textures;
-		vector<Image*> images;
-		vector<Lumel*> lumels;
-				
-		float lightMapRes;
-		float lightMapQuality;
-
-		
-	private:
-		
-		void packMesh(LightmapMesh *mesh);
-		void generateNewImage();
-		bool hasRoomForMesh(LightmapMesh *mesh);
-		
-		PackNode *cNode;
-		Image *currentImage;
-		int currentImageID;
-		
-		GenericScene *targetScene;
-	};
-	
-}

+ 0 - 47
Modules/Contents/Lightmaps/Include/PolyRadTool.h

@@ -1,47 +0,0 @@
-/*
- *  PolyRadTool.h
- *  Poly
- *
- *  Created by Ivan Safrin on 9/25/08.
- *  Copyright 2008 __MyCompanyName__. All rights reserved.
- *
- */
-
-// @package Scene
-
-#pragma once
-#include "PolyGlobals.h"
-#include "PolyGenericScene.h"
-#include "PolyLightmapPacker.h"
-#include "PolyPolygon.h"
-
-namespace Polycode {
-
-	class GenericScene;
-	class LightmapPacker;
-	class LightmapFace;
-	struct Lumel;
-	class Polygon;
-	
-	class _PolyExport RadTool {
-		public:
-			RadTool(GenericScene *scene, LightmapPacker *packer);
-			~RadTool();
-			
-			void fiatLux(int radPasses);
-			
-		private:
-		
-			void applyLight(SceneLight *light);
-			void lightLumel(SceneLight *light,Image *image, Lumel *lumel);
-			
-			void doRadiosityPass();
-			void radLumel(Lumel *lumel,Image *image);
-					
-			bool worldRayTest(Vector3 origin, Vector3 destination, Polygon *hitPolygon);
-			static bool rayTriangleIntersect(Vector3 ray_origin, Vector3 ray_direction, Vector3 vert0, Vector3 vert1, Vector3 vert2, Vector3 *hitPoint);
-		
-			GenericScene *scene;
-			LightmapPacker *packer;
-	};
-}

+ 0 - 423
Modules/Contents/Lightmaps/Source/PolyLightmapPacker.cpp

@@ -1,423 +0,0 @@
-/*
- *  LightmapPacker.cpp
- *  Poly
- *
- *  Created by Ivan Safrin on 9/24/08.
- *  Copyright 2008 __MyCompanyName__. All rights reserved.
- *
- */
-
-
-#include "PolyLightmapPacker.h"
-
-using namespace Polycode;
-
-LightmapPacker::LightmapPacker(GenericScene *targetScene) {
-	this->targetScene = targetScene;
-	currentImageID = -1;
-}
-
-LightmapPacker::~LightmapPacker() {
-	
-}
-
-void LightmapPacker::unwrapScene() {
-	for(int i=0; i < targetScene->getNumStaticGeometry(); i++) {
-		LightmapMesh *newLMesh = new LightmapMesh;
-		newLMesh->processed = false;
-		newLMesh->mesh = targetScene->getStaticGeometry(i);
-		lightmapMeshes.push_back(newLMesh);
-		
-		for(int j=0; j < targetScene->getStaticGeometry(i)->getMesh()->getPolygonCount(); j++) {
-			Polygon *poly = targetScene->getStaticGeometry(i)->getMesh()->getPolygon(j);
-			Vector3 fnormal = poly->getFaceNormal();
-			Polygon *flatPoly = new Polygon();
-			Polygon *flatUnscaled = new Polygon();
-			LightmapFace *newFace = new LightmapFace;
-			fnormal.x = fabsf(fnormal.x);
-			fnormal.y = fabsf(fnormal.y);
-			fnormal.z = fabsf(fnormal.z);
-			//			Logger::log("fnormal: %f %f %f\n", fnormal.x, fnormal.y, fnormal.z);
-			if(fnormal.x > fnormal.y && fnormal.x > fnormal.z) {
-				for(int k=0; k < poly->getVertexCount(); k++) {
-					flatPoly->addVertex((poly->getVertex(k)->y*lightMapQuality)/lightMapRes, (poly->getVertex(k)->z*lightMapQuality)/lightMapRes, 0);
-					flatUnscaled->addVertex(poly->getVertex(k)->y, poly->getVertex(k)->z, 0);
-				}
-				newFace->projectionAxis = LightmapFace::X_PROJECTION;
-			} else if (fnormal.y > fnormal.x && fnormal.y > fnormal.z) {
-				for(int k=0; k < poly->getVertexCount(); k++) {
-					flatPoly->addVertex((poly->getVertex(k)->x*lightMapQuality)/lightMapRes, (poly->getVertex(k)->z*lightMapQuality)/lightMapRes, 0);
-					flatUnscaled->addVertex(poly->getVertex(k)->x, poly->getVertex(k)->z, 0);
-				}	
-				newFace->projectionAxis = LightmapFace::Y_PROJECTION;						
-			} else {
-				for(int k=0; k < poly->getVertexCount(); k++) {
-					flatPoly->addVertex((poly->getVertex(k)->x*lightMapQuality)/lightMapRes, (poly->getVertex(k)->y*lightMapQuality)/lightMapRes, 0);
-					flatUnscaled->addVertex(poly->getVertex(k)->x, poly->getVertex(k)->y, 0);
-				}
-				newFace->projectionAxis = LightmapFace::Z_PROJECTION;							
-			}
-			
-			newFace->area = flatPoly->getBounds2D();
-			float offx = newFace->area.x;
-			float offy = newFace->area.y;
-			newFace->area.x = 0;
-			newFace->area.y = 0;
-			
-			// now align the flat face to 0,0
-			for(int k=0; k < flatPoly->getVertexCount(); k++) {
-				flatPoly->getVertex(k)->x -= offx;
-				flatPoly->getVertex(k)->y -= offy;
-//				flatPoly->getVertex(k)->x *= 1.1;
-//				flatPoly->getVertex(k)->y *= 1.2;
-			}
-			
-			
-			newFace->meshPolygon = poly;
-			newFace->flatPolygon = flatPoly;
-			newFace->flatUnscaledPolygon = flatUnscaled;
-			
-			newFace->actualArea.w = (newFace->area.w * lightMapRes) / lightMapQuality;
-			newFace->actualArea.h = (newFace->area.h * lightMapRes) / lightMapQuality;
-			
-			float lumelScale = 1.0f;
-			float maxSize = 0.4f;
-			
-			if(newFace->area.w > maxSize || newFace->area.h > maxSize) {
-				//		Logger::log("WARNING, NORMALIZING FACE AREA (%f %f)\n", newFace->area.w, newFace->area.h);
-				float tmp;
-				if(newFace->area.w > newFace->area.h) {
-					tmp = newFace->area.w;
-					newFace->area.w = maxSize;
-					newFace->area.h = newFace->area.h * (maxSize/tmp);
-				} else {
-					tmp = newFace->area.h;
-					newFace->area.h = maxSize;
-					newFace->area.w = newFace->area.w * (maxSize/tmp);			
-				}
-				lumelScale = (1.0f / (maxSize/tmp)) * 100;
-				for(int v=0; v < newFace->flatPolygon->getVertexCount(); v++) {
-					newFace->flatPolygon->getVertex(v)->x = newFace->flatPolygon->getVertex(v)->x * (maxSize/tmp);
-					newFace->flatPolygon->getVertex(v)->y = newFace->flatPolygon->getVertex(v)->y * (maxSize/tmp);
-				}
-			}
-
-
-//			newFace->area.w += (4.0f/lightMapRes);
-//			newFace->area.h += (4.0f/lightMapRes);
-			
-			newFace->pixelArea.w = (newFace->area.w * lightMapRes)+2;
-			newFace->pixelArea.h = (newFace->area.h * lightMapRes)+2;
-
-//			newFace->area.w = newFace->pixelArea.w / lightMapRes;
-//			newFace->area.h = newFace->pixelArea.h / lightMapRes;
-						
-			newFace->numLumels = 0;
-			for(float pw =-2 ;pw < newFace->pixelArea.w+3; pw++) {
-				for(float ph =-2 ;ph < newFace->pixelArea.h+3; ph++) {
-					Lumel *newLumel = new Lumel;
-					newLumel->face = newFace;
-					newLumel->lumelScale = lumelScale;
-					newLumel->u = pw/lightMapRes;
-					newLumel->v = ph/lightMapRes;
-					newLumel->normal = newFace->meshPolygon->getFaceNormal();
-					newFace->lumels.push_back(newLumel);
-					lumels.push_back(newLumel);
-					newFace->numLumels++;
-				}
-			}
-			
-			newLMesh->faces.push_back(newFace);
-		}
-	}
-}
-
-Vector3 LightmapPacker::getLumelPos(Lumel *lumel, LightmapFace *face) {
-	
-	Vector3 poly_normal = face->meshPolygon->getFaceNormal();
-	
-	Vector3 pointonplane = *face->meshPolygon->getVertex(0) ;
-//	Vector3 pointonplane = (*face->meshPolygon->getVertex(0) + *face->meshPolygon->getVertex(1) + *face->meshPolygon->getVertex(2)) / 3.0f;		
-	
-	float Distance = -(poly_normal.x * pointonplane.x + poly_normal.y * pointonplane.y + poly_normal.z * pointonplane.z);
-	
-	float X,Y,Z;
-	Vector3 UVVector, Vect1, Vect2;
-	
-	float	Min_U = face->flatUnscaledPolygon->getVertex(0)->x;
-	float   Min_V = face->flatUnscaledPolygon->getVertex(0)->y;
-	float   Max_U = face->flatUnscaledPolygon->getVertex(0)->x;
-	float   Max_V = face->flatUnscaledPolygon->getVertex(0)->y;
-
-        for (int i = 0; i < 3; i++)
-        {
-            if (face->flatUnscaledPolygon->getVertex(i)->x < Min_U )
-                Min_U = face->flatUnscaledPolygon->getVertex(i)->x;
-            if (face->flatUnscaledPolygon->getVertex(i)->y < Min_V )
-                Min_V = face->flatUnscaledPolygon->getVertex(i)->y;
-            if (face->flatUnscaledPolygon->getVertex(i)->x > Max_U )
-                Max_U = face->flatUnscaledPolygon->getVertex(i)->x;
-            if (face->flatUnscaledPolygon->getVertex(i)->y > Max_V )
-                Max_V = face->flatUnscaledPolygon->getVertex(i)->y;
-        }	
-
-	switch(face->projectionAxis) {
-		case LightmapFace::X_PROJECTION:
-			X = - ( (poly_normal.y * Min_U) + (poly_normal.z * Min_V) + Distance )
-			/ poly_normal.x;
-			UVVector.x = X;
-			UVVector.y = Min_U;
-			UVVector.z = Min_V;
-			X = - ( (poly_normal.y * Max_U) + (poly_normal.z) * Min_V + Distance )
-			/ poly_normal.x;
-			Vect1.x = X;
-			Vect1.y = Max_U;
-			Vect1.z = Min_V;
-			X = - ( (poly_normal.y * Min_U) + (poly_normal.z * Max_V) + Distance )
-			/ poly_normal.x;
-			Vect2.x = X;
-			Vect2.y = Min_U;
-			Vect2.z = Max_V;
-			break;
-		case LightmapFace::Y_PROJECTION:
-			Y = - ( poly_normal.x * Min_U + poly_normal.z * Min_V + Distance )
-			/ poly_normal.y;
-			UVVector.x = Min_U;
-			UVVector.y = Y;
-			UVVector.z = Min_V;
-			Y = - ( poly_normal.x * Max_U + poly_normal.z * Min_V + Distance )
-			/ poly_normal.y;
-			Vect1.x = Max_U;
-			Vect1.y = Y;
-			Vect1.z = Min_V;
-			Y = - ( poly_normal.x * Min_U + poly_normal.z * Max_V + Distance )
-			/ poly_normal.y;
-			Vect2.x = Min_U;
-			Vect2.y = Y;
-			Vect2.z = Max_V;		
-			break;
-		case LightmapFace::Z_PROJECTION:
-			Z = - ( poly_normal.x * Min_U + poly_normal.y * Min_V + Distance )
-			/ poly_normal.z;
-			UVVector.x = Min_U;
-			UVVector.y = Min_V;
-			UVVector.z = Z;
-			Z = - ( poly_normal.x * Max_U + poly_normal.y * Min_V + Distance )
-			/ poly_normal.z;
-			Vect1.x = Max_U;
-			Vect1.y = Min_V;
-			Vect1.z = Z;
-			Z = - ( poly_normal.x * Min_U + poly_normal.y * Max_V + Distance )
-			/ poly_normal.z;
-			Vect2.x = Min_U;
-			Vect2.y = Max_V;
-			Vect2.z = Z;
-			break;
-	}
-	
-	Vector3 edge1,edge2,newedge1,newedge2;
-	
-	edge1.x = Vect1.x - UVVector.x;
-    edge1.y = Vect1.y - UVVector.y;
-    edge1.z = Vect1.z - UVVector.z;
-    edge2.x = Vect2.x - UVVector.x;
-    edge2.y = Vect2.y - UVVector.y;
-    edge2.z = Vect2.z - UVVector.z;
-	
-	float ufactor = lumel->u/(face->area.w+(0.0f/lightMapRes));
-	float vfactor = lumel->v/(face->area.h+(0.0f/lightMapRes));
-
-//	Logger::log("edge1: %f %f %f", edge1.x, edge1.y,edge1.z);
-	
-	newedge1.x = edge1.x * ufactor;
-	newedge1.y = edge1.y * ufactor;
-	newedge1.z = edge1.z * ufactor;
-	newedge2.x = edge2.x * vfactor;
-	newedge2.y = edge2.y * vfactor;
-	newedge2.z = edge2.z * vfactor;
-		
-	Vector3 retVec(UVVector.x + newedge2.x + newedge1.x,
-				   UVVector.y + newedge2.y + newedge1.y,
-				   UVVector.z + newedge2.z + newedge1.z);
-	
-	return retVec;
-}
-
-void LightmapPacker::packMesh(LightmapMesh *mesh) {
-	Color col;
-	mesh->imageID = currentImageID;
-	mesh->mesh->lightmapIndex = currentImageID;
-	for(int n=0; n < mesh->faces.size(); n++) {
-		PackNode *pNode = cNode->Insert(mesh->faces[n]);
-		if(pNode != NULL) {
-			col.Random();
-			currentImage->drawRect(pNode->rc.x-1, pNode->rc.y-1, pNode->rc.w+2, pNode->rc.h+2, col);
-			pNode->face = mesh->faces[n];
-			for(int i=0; i < mesh->faces[n]->flatPolygon->getVertexCount(); i++) {
-				Vertex *vert = mesh->faces[n]->flatPolygon->getVertex(i);				
-				vert->x += (pNode->rc.x/lightMapRes);//-(1.0f/lightMapRes);
-				vert->y += (pNode->rc.y/lightMapRes);//-(1.0f/lightMapRes);
-				mesh->faces[n]->meshPolygon->addTexCoord2(vert->x,vert->y);
-				mesh->mesh->getMesh()->numUVs = 2;
-			}
-			
-			for(int nl = 0; nl < mesh->faces[n]->numLumels; nl++) {
-				mesh->faces[n]->lumels[nl]->worldPos = mesh->mesh->getConcatenatedMatrix() * getLumelPos(mesh->faces[n]->lumels[nl], mesh->faces[n]);
-				mesh->faces[n]->lumels[nl]->u += (pNode->rc.x/lightMapRes);
-				mesh->faces[n]->lumels[nl]->v += (pNode->rc.y/lightMapRes);				
-			}
-			
-			mesh->faces[n]->imageID = currentImageID;
-			mesh->faces[n]->pixelArea.x = pNode->rc.x;
-			mesh->faces[n]->pixelArea.y = pNode->rc.y;
-		} else {
-			Logger::log("WARNING MESH DOES NOT FIT! %d of %d completed \n", n, mesh->faces.size());
-			return;
-			//generateNewImage();
-		}
-	}	
-}
-
-void LightmapPacker::generateNewImage() {
-	cNode = new PackNode();
-	cNode->createRoot(lightMapRes);
-	currentImage = new Image(lightMapRes,lightMapRes);
-	currentImage->fill(0,0,0,1);
-	images.push_back(currentImage);
-	currentImageID++;
-}
-
-bool LightmapPacker::hasRoomForMesh(LightmapMesh *mesh) {
-	PackNode *copyNode = cNode->clone();
-	for(int n=0; n < mesh->faces.size(); n++) {
-		PackNode *pNode = copyNode->Insert(mesh->faces[n]);
-		if(pNode != NULL) {
-			pNode->face = mesh->faces[n];
-		} else {
-			delete copyNode;
-			return false;
-		} 
-	}	
-	delete copyNode;
-	return true;
-}
-
-void LightmapPacker::buildTextures() {
-	generateNewImage();
-	
-	// TODO: sort meshes by size
-	
-	for(int m=0; m < lightmapMeshes.size(); m++) {
-		if(hasRoomForMesh(lightmapMeshes[m])) {
-			Logger::log("packing mesh %d\n", m);
-			packMesh(lightmapMeshes[m]);
-		} else {
-			Logger::log("mesh %d doesnt fit, generating new image and packing\n", m);
-			generateNewImage();
-			packMesh(lightmapMeshes[m]);
-		}
-	}
-}
-
-void LightmapPacker::generateTextures(int resolution, int quality) {
-	lightMapRes = resolution;
-	lightMapQuality = quality;
-	unwrapScene();
-	buildTextures();
-}
-
-void LightmapPacker::bindTextures() {
-	// create textures and bind them for preview
-	for(int i=0; i < images.size(); i++) {	
-		images[i]->fastBlur(1);
-		Texture* newTex = CoreServices::getInstance()->getMaterialManager()->createTextureFromImage(images[i]);
-		textures.push_back(newTex);
-	}
-	
-	for(int i=0; i < targetScene->getNumStaticGeometry(); i++) {
-		Material *meshMaterial = targetScene->getStaticGeometry(i)->getMaterial();
-		if(meshMaterial) {
-			targetScene->getStaticGeometry(i)->getLocalShaderOptions()->addTexture("diffuse2", textures[targetScene->getStaticGeometry(i)->lightmapIndex]);
-		}
-	}
-	
-
-/* old way
-	for(int i=0; i < lightmapMeshes.size(); i++) {
-		Material *meshMaterial = lightmapMeshes[i]->mesh->getMaterial();
-		if(meshMaterial) {
-			lightmapMeshes[i]->mesh->getLocalShaderOptions()->addTexture("diffuse2", textures[lightmapMeshes[i]->imageID]);
-		}
-	}
-*/
-
-}
-
-void LightmapPacker::saveLightmaps(string folder) {
-	for(int i=0; i < images.size(); i++) {	
-		std::ostringstream fileName;
-		fileName << folder << "/" << "lm" << i << ".bmp";
-		images[i]->writeBMP(fileName.str());
-	}
-}
-
-void PackNode::createRoot(int res) {
-	rc.w = res-4;
-	rc.h = res-4;
-	rootRes = res-4;
-	rc.x = 1;
-	rc.y = 1;
-	
-}
-
-PackNode *PackNode::clone() {
-	PackNode *cloneNode = new PackNode();
-	cloneNode->rc.x = rc.x;
-	cloneNode->rc.y  = rc.y;
-	cloneNode->rc.w = rc.w;
-	cloneNode->rc.h  = rc.h;
-	
-	cloneNode->face = face;
-	if(child[0]) {
-		cloneNode->child[0] = child[0]->clone();
-	}
-	if(child[1]) {
-		cloneNode->child[1] = child[1]->clone();
-	}	
-	return cloneNode;
-}
-
-PackNode *PackNode::Insert(LightmapFace *img) {
-	PackNode *newNode;	
-	if(child[0]) {
-		newNode = child[0]->Insert(img);
-        if(newNode != NULL)
-			return newNode;
-        return child[1]->Insert(img);
-	} else {
-		if(face != NULL)
-			return NULL;
-		
-        //(if we're too small, return)
-		if(img->pixelArea.w > rc.w || img->pixelArea.h > rc.h)
-            return NULL;
-		
-        if(img->pixelArea.w == rc.w && img->pixelArea.h == rc.h)
-            return this;
-        
-        child[0] = new PackNode();
-        child[1] = new PackNode();
-        
-		float dw = rc.w - img->pixelArea.w;
-		float dh = rc.h - img->pixelArea.h;
-        
-        if(dw > dh) {
-            child[0]->rc = Rectangle(rc.x, rc.y, img->pixelArea.w, rc.h);
-            child[1]->rc = Rectangle(rc.x+img->pixelArea.w+4, rc.y, rc.w-img->pixelArea.w-3, rc.h);
-        } else {
-            child[0]->rc = Rectangle(rc.x, rc.y, rc.w, img->pixelArea.h);
-            child[1]->rc = Rectangle(rc.x, rc.y+img->pixelArea.h+4, rc.w, rc.h-img->pixelArea.h-3);
-        }
-        return child[0]->Insert(img);	
-	}
-}

+ 0 - 228
Modules/Contents/Lightmaps/Source/PolyRadTool.cpp

@@ -1,228 +0,0 @@
-/*
- *  PolyRadTool.cpp
- *  Poly
- *
- *  Created by Ivan Safrin on 9/25/08.
- *  Copyright 2008 __MyCompanyName__. All rights reserved.
- *
- */
-
-
-#include "PolyRadTool.h"
-
-using namespace Polycode;
-
-RadTool::RadTool(GenericScene *scene, LightmapPacker *packer) {
-	this->scene = scene;
-	this->packer = packer;
-}
-
-void RadTool::fiatLux(int radPasses) {
-
-	Vector3 baseAmbient(0.033f, 0.033f, 0.033f);
-	
-	Color col;	
-	for(int i=0; i < packer->lumels.size(); i++) {
-		packer->lumels[i]->rEnergy.set(baseAmbient.x, baseAmbient.y, baseAmbient.z);
-		packer->images[packer->lumels[i]->face->imageID]->setPixel(packer->lumels[i]->u*packer->lightMapRes, packer->lumels[i]->v*packer->lightMapRes, Color(baseAmbient.x, baseAmbient.y, baseAmbient.z, 1.0f));		
-	}
-
-//	applyLight(scene->getLight(1));
-	for(int i =0; i < scene->getNumLights(); i++) {
-		applyLight(scene->getLight(i));
-	}
-
-	for(int i=0; i < radPasses; i++) {
-		Logger::log("doing radiosity pass %d\n", i);
-		doRadiosityPass();
-	}
-	
-}
-
-void RadTool::doRadiosityPass() {
-	for(int i=0; i < packer->lumels.size(); i+=1) {
-		radLumel(packer->lumels[i], packer->images[packer->lumels[i]->face->imageID]);
-	}
-}
-
-void RadTool::applyLight(SceneLight *light) {
-	for(int i=0; i < packer->lumels.size(); i++) {
-		lightLumel(light, packer->images[packer->lumels[i]->face->imageID], packer->lumels[i]);
-	}
-}
-
-bool RadTool::rayTriangleIntersect(Vector3 ray_origin, Vector3 ray_direction, Vector3 vert0, Vector3 vert1, Vector3 vert2, Vector3 *hitPoint)
-{
-	float t,u,v;
-	 t = 0; u = 0; v = 0;
-	 
-	 Vector3 edge1 = vert1 - vert0;
-	 Vector3 edge2 = vert2 - vert0;
-	 
-	 Vector3 tvec, pvec, qvec;
-	 float det, inv_det;
-	 
-	 
-	 pvec = ray_direction.crossProduct(edge2);
-	 det = edge1.dot(pvec);
-	 
-	 if (det > -0.00001f)
-		return false;
-	 
-	 inv_det = 1.0f / det;
-	 
-	 tvec = ray_origin - vert0;
-
-//	 hitPoint = tvec;
-	 
-	 u = tvec.dot(pvec) * inv_det;
-	 if (u < -0.001f || u > 1.001f)
-		return false;
-	 
-	 qvec = tvec.crossProduct(edge1);
-	 
-	 v = ray_direction.dot(qvec) * inv_det;
-	 if (v < -0.001f || u + v > 1.001f)
-		return false;
-	 
-	 t = edge2.dot(qvec) * inv_det;
-	 
-	 if (t <= 0)
-		return false;
-
-	hitPoint->x = ray_origin.x+t*ray_direction.x;
-	hitPoint->y = ray_origin.y+t*ray_direction.y;
-	hitPoint->z = ray_origin.z+t*ray_direction.z;	
-
-	 
-	 return true;
-
-}
-
-
-bool RadTool::worldRayTest(Vector3 origin, Vector3 destination,Poly::Polygon *hitPolygon) {
-	Vector3 hitPoint,dirVec;
-	dirVec = destination-origin;
-	
-	for(int i= 0; i < packer->lightmapMeshes.size(); i++) {
-		Matrix4 meshMatrix = packer->lightmapMeshes[i]->mesh->getConcatenatedMatrix();
-		for(int j=0; j < packer->lightmapMeshes[i]->faces.size(); j++) {
-			if(rayTriangleIntersect(origin, dirVec,
-				meshMatrix*(*packer->lightmapMeshes[i]->faces[j]->meshPolygon->getVertex(0)),
-				meshMatrix*(*packer->lightmapMeshes[i]->faces[j]->meshPolygon->getVertex(1)),
-				meshMatrix*(*packer->lightmapMeshes[i]->faces[j]->meshPolygon->getVertex(2)),
-				&hitPoint)) {
-					float dist =  hitPoint.distance(origin);
-					if(dist < destination.distance(origin) && dist > 1.3f) {
-						hitPolygon = packer->lightmapMeshes[i]->faces[j]->meshPolygon;
-						return true;
-					}
-			}
-		}
-		
-	}
-	return false;
-}
-
-
-void RadTool::radLumel(Lumel *lumel, Image *image) {
-	Lumel *lumel2;
-	float numSeen = 0;
-	float totalVal_r = 0;
-	float totalVal_g = 0;
-	float totalVal_b = 0;
-	
-	for(int i=0; i < packer->lumels.size(); i+=1000) {
-		lumel2 = packer->lumels[i];
-	//	if(!worldRayTest(lumel->worldPos, lumel2->worldPos, hitPoly)) {		
-			float dist = lumel2->worldPos.distance(lumel->worldPos);
-			Vector3 lightVector = lumel2->worldPos-lumel->worldPos;
-			lightVector.Normalize();
-			float diffuse = lumel->normal.dot(lightVector);
-			float pwr = 1.3f; 
-			float val = 1.0f - (dist/45.0f);
-			val = val * pwr * diffuse * lumel2->lumelScale;
-			totalVal_r += lumel2->rEnergy.x * val;
-			totalVal_g += lumel2->rEnergy.y * val;
-			totalVal_b += lumel2->rEnergy.z * val;			
-			numSeen++;
-	//	}
-	}
-	
-	totalVal_r = totalVal_r / numSeen;
-	totalVal_g = totalVal_g / numSeen;
-	totalVal_b = totalVal_b / numSeen;
-		
-	if(totalVal_r < 0)
-		totalVal_r = 0;
-	if(totalVal_g < 0)
-		totalVal_g = 0;
-	if(totalVal_b < 0)
-		totalVal_b = 0;
-	
-	Color col;
-	lumel->rEnergy.x += totalVal_r;
-	lumel->rEnergy.y += totalVal_g;
-	lumel->rEnergy.z += totalVal_b;
-	
-	if(lumel->rEnergy.x > 1.0f)
-		lumel->rEnergy.x = 1.0f;
-	if(lumel->rEnergy.y > 1.0f)
-		lumel->rEnergy.y = 1.0f;
-	if(lumel->rEnergy.z > 1.0f)
-		lumel->rEnergy.z = 1.0f;
-	
-	
-	col.setColor(lumel->rEnergy.x,lumel->rEnergy.y,lumel->rEnergy.z,1.0f);
-	image->setPixel(lumel->u*packer->lightMapRes, lumel->v*packer->lightMapRes, col);
-				
-}
-
-void RadTool::lightLumel(SceneLight *light, Image *image, Lumel *lumel) {
-	
-	float dist = light->getPosition()->distance(lumel->worldPos);
-	
-	Vector3 lightVector = (*light->getPosition())-lumel->worldPos;
-	lightVector.Normalize();
-	float diffuse = lumel->normal.dot(lightVector);
-	//float diffuse = 1;
-	Polygon *hitPoly;
-
-
-	if(worldRayTest(lumel->worldPos, *light->getPosition(), hitPoly))
-		return;
-
-	float val = ((light->getDistance()) /(dist*dist));
-	if(val > 1.0f)
-		val = 1.0f;
-		
-	float pwr = light->getIntensity();
-
-	val = val * pwr * diffuse;
-	if(val < 0)
-		val = 0;
-		
-	Color col;
-	
-	lumel->rEnergy.x += light->lightColor.r*val;
-	lumel->rEnergy.y += light->lightColor.g*val;
-	lumel->rEnergy.z += light->lightColor.b*val;
-	
-	if(lumel->rEnergy.x > 1.0f)
-		lumel->rEnergy.x = 1.0f;
-	if(lumel->rEnergy.y > 1.0f)
-		lumel->rEnergy.y = 1.0f;
-	if(lumel->rEnergy.z > 1.0f)
-		lumel->rEnergy.z = 1.0f;
-
-	
-	//lumel->rEnergy.Normalize();
-	
-	col.setColor(lumel->rEnergy.x,lumel->rEnergy.y,lumel->rEnergy.z,1.0f);
-		
-	image->setPixel(lumel->u*packer->lightMapRes, lumel->v*packer->lightMapRes, col);
-}
-
-RadTool::~RadTool() {
-	
-}

+ 0 - 40
Modules/Contents/Terrain/Include/PolyTerrain.h

@@ -1,40 +0,0 @@
-/*
- *  PolyTerrain.h
- *  Poly
- *
- *  Created by Ivan Safrin on 2/20/09.
- *  Copyright 2009 __MyCompanyName__. All rights reserved.
- *
- */
-
-// @package Scene
-
-#pragma once
-#include "PolyGlobals.h"
-#include "PolySceneMesh.h"
-#include "PolyCoreServices.h"
-
-#include <string>
-using std::string;
-
-namespace Polycode {
-	
-	class _PolyExport Terrain : public SceneMesh {
-	public:
-		
-		Terrain(int type, string heightmapFile, bool smooth, float tileAmt, float xDensity, float zDensity, float sx, float sz, float height);
-		~Terrain();
-		Vector3 getTerrainDataScale() { return terrainDataScale; }		
-		
-		static const int BASIC = 0;
-		
-		
-	private:
-		
-		void createBasic(string heightmapFile, bool smooth, float tileAmt, float xDensity, float zDensity, float sx, float sz, float height);
-		
-		Vector3 terrainDataScale;
-	};
-	
-	
-}

+ 0 - 87
Modules/Contents/Terrain/Source/PolyTerrain.cpp

@@ -1,87 +0,0 @@
-/*
- *  PolyTerrain.cpp
- *  Poly
- *
- *  Created by Ivan Safrin on 2/20/09.
- *  Copyright 2009 __MyCompanyName__. All rights reserved.
- *
- */
-
-#include "PolyTerrain.h"
-
-using namespace Polycode;
-
-Terrain::Terrain(int type, string heightmapFile, bool smooth, float tileAmt, float xDensity, float zDensity, float sx, float sz, float height) : SceneMesh(Mesh::TRI_MESH) {
-
-	switch(type) {
-		case BASIC:
-			createBasic(heightmapFile, smooth, tileAmt,xDensity,zDensity,sx,sz,height);
-			break;
-	}
-}
-
-void Terrain::createBasic(string heightmapFile, bool smooth, float tileAmt, float xDensity, float zDensity, float sx, float sz, float height) {
-	
-	float xStep = sx/xDensity;
-	float zStep = sz/zDensity;
-	
-	float uStep = 1.0f / xDensity * tileAmt;
-	float vStep = 1.0f / zDensity * tileAmt;
-	
-	
-	float xOffset = -sx/2.0f;
-	float zOffset = -sz/2.0f;
-	
-	Image *heightImage = new Image(heightmapFile);
-	
-	terrainDataScale.x = sx / (float)heightImage->getWidth();
-	terrainDataScale.z = sz / (float)heightImage->getHeight();
-	
-	Polygon *poly;
-	float hpos;
-	
-	float imageStepX = floor( (float)heightImage->getWidth()/xDensity);
-	float imageStepY = floor((float)heightImage->getHeight()/zDensity);
-	
-	for(float i=0; i < xDensity; i+=1) {
-		for(float j=0; j < zDensity; j+=1) {
-			poly = new Polygon();
-			
-			hpos = height * heightImage->getPixel((imageStepX*i)+imageStepX, imageStepY*j).getBrightness();
-			poly->addVertex((xStep*i)+xStep+xOffset, hpos, (zStep * j)+zOffset, (uStep*i) + uStep, vStep*j)->setNormal(0,1,0);
-			
-			hpos = height * heightImage->getPixel((imageStepX*i), (imageStepY*j)).getBrightness();
-			poly->addVertex((xStep*i)+xOffset, hpos, (zStep * j)+zOffset, uStep*i, vStep*j)->setNormal(0,1,0);
-			
-			hpos = height * heightImage->getPixel(imageStepX*i, (imageStepY*j)+imageStepY).getBrightness();			
-			poly->addVertex((xStep*i)+xOffset, hpos, ((zStep*j)+zStep)+zOffset, uStep*i, (vStep*j)+vStep)->setNormal(0,1,0);								
-			
-			mesh->addPolygon(poly);
-			if(!smooth) {
-				poly->calculateNormal();
-				poly->useVertexNormals = true;
-			}
-			
-			poly = new Polygon();			
-			
-			hpos = height * heightImage->getPixel(imageStepX*i, (imageStepY*j)+imageStepY).getBrightness();			
-			poly->addVertex((xStep*i)+xOffset, hpos, (zStep*j)+zStep+zOffset, uStep*i, (vStep*j)+vStep)->setNormal(0,1,0);
-			
-			hpos = height * heightImage->getPixel((imageStepX*i)+imageStepX, (imageStepY*j)+imageStepY).getBrightness();						
-			poly->addVertex((xStep*i)+xStep+xOffset, hpos, (zStep*j)+zStep+zOffset, (uStep*i) + uStep, (vStep*j)+vStep)->setNormal(0,1,0);			
-			
-			hpos = height * heightImage->getPixel((imageStepX*i)+imageStepX, (imageStepY*j)).getBrightness();			
-			poly->addVertex((xStep*i)+xStep+xOffset, hpos, (zStep * j)+zOffset, (uStep*i) + uStep, vStep*j)->setNormal(0,1,0);
-			
-			mesh->addPolygon(poly);
-			if(!smooth) {
-				poly->calculateNormal();
-				poly->useVertexNormals = true;
-			}
-		}
-	}	
-}
-
-Terrain::~Terrain() {
-	
-}