فهرست منبع

Fixed vertical plane primitive not generating tangents, added a way to enable and disable particle emitters, fixed a number of crashes in the IDE, memory cleanup in the IDE, shaders now reload again if program files are changed and reload resources is activated, asset browser now clears asset list if asset browsing mode is changed, material options now update if you change a mesh material in the entity editor.

Ivan Safrin 12 سال پیش
والد
کامیت
eb7251a394

+ 3 - 0
Core/Contents/Include/PolyParticleEmitter.h

@@ -67,6 +67,8 @@ namespace Polycode {
             void updateParticles();
             void rebuildParticles();
         
+            void enableParticleSystem(bool val);
+        
             void setUseFloorPlane(bool val);
             void setFloorPlaneOffset(Number floorPlaneOffset);
             void setFloorDamping(Number floorDamping);
@@ -136,6 +138,7 @@ namespace Polycode {
         
             void resetParticle(unsigned int index);
         
+            bool systemEnabled;
             Core *core;
             unsigned int particleCount;
             std::vector<SceneParticle> particles;

+ 30 - 28
Core/Contents/Source/PolyGLSLShaderModule.cpp

@@ -428,33 +428,35 @@ bool GLSLShaderModule::applyShaderMaterial(Renderer *renderer, Material *materia
 	}
 		
 	for(int i=0; i < cgBinding->textures.size(); i++) {
-		OpenGLTexture *glTexture = (OpenGLTexture*)cgBinding->textures[i].texture;	
-		if(glTexture) {		
-			int texture_location = glGetUniformLocation(glslShader->shader_id, cgBinding->textures[i].name.c_str());
-			glUniform1i(texture_location, textureIndex);
-			glActiveTexture(GL_TEXTURE0 + textureIndex);		
-			glBindTexture(GL_TEXTURE_2D, glTexture->getTextureID());
-			textureIndex++;
-		}
-	}	
-	
-		
+        if(!localOptions->getTexture(cgBinding->textures[i].name)) {
+            OpenGLTexture *glTexture = (OpenGLTexture*)cgBinding->textures[i].texture;
+            if(glTexture) {		
+                int texture_location = glGetUniformLocation(glslShader->shader_id, cgBinding->textures[i].name.c_str());
+                glUniform1i(texture_location, textureIndex);
+                glActiveTexture(GL_TEXTURE0 + textureIndex);		
+                glBindTexture(GL_TEXTURE_2D, glTexture->getTextureID());
+                textureIndex++;
+            }
+        }
+	}
+			
 	for(int i=0; i < cgBinding->cubemaps.size(); i++) {
-		OpenGLCubemap *glCubemap = (OpenGLCubemap*)cgBinding->cubemaps[i].cubemap;
-		if(glCubemap) {
-			int texture_location = glGetUniformLocation(glslShader->shader_id, cgBinding->cubemaps[i].name.c_str());
-			glUniform1i(texture_location, textureIndex);		
-			glActiveTexture(GL_TEXTURE0 + textureIndex);				
-			glBindTexture(GL_TEXTURE_CUBE_MAP, glCubemap->getTextureID());
-			textureIndex++;
-		}
-	}	
+        if(!localOptions->getCubemap(cgBinding->cubemaps[i].name)) {
+            OpenGLCubemap *glCubemap = (OpenGLCubemap*)cgBinding->cubemaps[i].cubemap;
+            if(glCubemap) {
+                int texture_location = glGetUniformLocation(glslShader->shader_id, cgBinding->cubemaps[i].name.c_str());
+                glUniform1i(texture_location, textureIndex);		
+                glActiveTexture(GL_TEXTURE0 + textureIndex);				
+                glBindTexture(GL_TEXTURE_CUBE_MAP, glCubemap->getTextureID());
+                textureIndex++;
+            }
+        }
+	}
 	
-	cgBinding = localOptions;
-	for(int i=0; i < cgBinding->textures.size(); i++) {
-		OpenGLTexture *glTexture = (OpenGLTexture*)cgBinding->textures[i].texture;
+	for(int i=0; i < localOptions->textures.size(); i++) {
+		OpenGLTexture *glTexture = (OpenGLTexture*)localOptions->textures[i].texture;
 		if(glTexture) {		
-			int texture_location = glGetUniformLocation(glslShader->shader_id, cgBinding->textures[i].name.c_str());
+			int texture_location = glGetUniformLocation(glslShader->shader_id, localOptions->textures[i].name.c_str());
 			glUniform1i(texture_location, textureIndex);
 			glActiveTexture(GL_TEXTURE0 + textureIndex);		
 			glBindTexture(GL_TEXTURE_2D, glTexture->getTextureID());	
@@ -462,11 +464,11 @@ bool GLSLShaderModule::applyShaderMaterial(Renderer *renderer, Material *materia
 		}
 	}		
 
-	for(int i=0; i < cgBinding->cubemaps.size(); i++) {
-		OpenGLCubemap *glCubemap = (OpenGLCubemap*)cgBinding->cubemaps[i].cubemap;	
+	for(int i=0; i < localOptions->cubemaps.size(); i++) {
+		OpenGLCubemap *glCubemap = (OpenGLCubemap*)localOptions->cubemaps[i].cubemap;
 		if(glCubemap) {
-			int texture_location = glGetUniformLocation(glslShader->shader_id, cgBinding->cubemaps[i].name.c_str());
-			glUniform1i(texture_location, textureIndex);		
+			int texture_location = glGetUniformLocation(glslShader->shader_id, localOptions->cubemaps[i].name.c_str());
+			glUniform1i(texture_location, textureIndex);
 			glActiveTexture(GL_TEXTURE0 + textureIndex);				
 			glBindTexture(GL_TEXTURE_CUBE_MAP, glCubemap->getTextureID());
 			textureIndex++;

+ 1 - 0
Core/Contents/Source/PolyMaterialManager.cpp

@@ -81,6 +81,7 @@ void MaterialManager::reloadPrograms() {
 }
 
 void MaterialManager::loadMaterialLibraryIntoPool(ResourcePool *pool, const String &materialFile) {
+    printf("LOADING [%s] into pool [%s]\n", materialFile.c_str(), pool->getName().c_str());
     std::vector<Shader*> shaders =loadShadersFromFile(pool, materialFile);
 
     for(int s=0; s < shaders.size(); s++) {

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

@@ -461,10 +461,13 @@ void Mesh::createVPlane(Number w, Number h) {
             vertices[i]->y = vertices[i]->y - (h/2.0f);
     }
 
+    calculateNormals();
+    calculateTangents();
+    
     arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;
     arrayDirtyMap[RenderDataArray::COLOR_DATA_ARRAY] = true;				
     arrayDirtyMap[RenderDataArray::TEXCOORD_DATA_ARRAY] = true;						
-    arrayDirtyMap[RenderDataArray::NORMAL_DATA_ARRAY] = true;										
+    arrayDirtyMap[RenderDataArray::NORMAL_DATA_ARRAY] = true;				
     arrayDirtyMap[RenderDataArray::TANGENT_DATA_ARRAY] = true;		
 }	
 

+ 21 - 7
Core/Contents/Source/PolyParticleEmitter.cpp

@@ -34,6 +34,7 @@ SceneParticleEmitter::SceneParticleEmitter(unsigned int particleCount, Number li
     motionPerlin = new Perlin(3,5,1.0,RANDOM_NUMBER);
     mesh->useVertexColors = true;
     depthWrite = false;
+    systemEnabled = true;
     setParticleCount(particleCount);
 }
 
@@ -101,7 +102,7 @@ void SceneParticleEmitter::setParticleCount(unsigned int newParticleCount) {
     particles.resize(particleCount);
     for(int i=0; i < particles.size(); i++) {
         resetParticle(i);
-        particles[i].lifetime = RANDOM_NUMBER * lifetime;
+        particles[i].lifetime = RANDOM_NUMBER * -lifetime;
         particles[i].perlinPos = Vector3(RANDOM_NUMBER, RANDOM_NUMBER, RANDOM_NUMBER);
         particles[i].brightnessDeviation = 1.0;
         particles[i].scale = 1.0;
@@ -132,7 +133,7 @@ void SceneParticleEmitter::setParticleRotationSpeed(const Vector3 &rotationSpeed
     particleRotationSpeed = rotationSpeed;
     for(int i=0; i < particles.size(); i++) {
         resetParticle(i);
-        particles[i].lifetime = RANDOM_NUMBER * lifetime;
+        particles[i].lifetime = RANDOM_NUMBER * -lifetime;
     }
 }
 
@@ -140,7 +141,7 @@ void SceneParticleEmitter::setLoopParticles(bool val) {
     loopParticles = val;
     for(int i=0; i < particles.size(); i++) {
         resetParticle(i);
-        particles[i].lifetime = RANDOM_NUMBER * lifetime;
+        particles[i].lifetime = RANDOM_NUMBER * -lifetime;
     }
 }
 
@@ -148,6 +149,15 @@ bool SceneParticleEmitter::getLoopParticles() const {
     return loopParticles;
 }
 
+void SceneParticleEmitter::enableParticleSystem(bool val) {
+    systemEnabled = val;
+    if(val) {
+        for(int i=0; i < particles.size(); i++) {
+            resetParticle(i);
+            particles[i].lifetime = RANDOM_NUMBER * -lifetime;
+        }
+    }
+}
 
 void SceneParticleEmitter::rebuildParticles() {
     mesh->clearMesh();
@@ -158,7 +168,7 @@ void SceneParticleEmitter::rebuildParticles() {
             mesh->setMeshType(Mesh::POINT_MESH);
             Matrix4 inverseMatrix = systemTrasnformMatrix.Inverse();
             for(int i=0; i < particles.size(); i++) {
-                if(particles[i].lifetime > lifetime) {
+                if(particles[i].lifetime > lifetime || particles[i].lifetime < 0.0) {
                     continue;
                 }
                 Vector3 vertexPosition = particles[i].position;
@@ -179,7 +189,7 @@ void SceneParticleEmitter::rebuildParticles() {
             Color vertexColor;
             Number finalParticleSize;
             for(int i=0; i < particles.size(); i++) {
-                if(particles[i].lifetime > lifetime) {
+                if(particles[i].lifetime > lifetime || particles[i].lifetime < 0.0) {
                     continue;
                 }
                 q.fromAxes(particles[i].rotation.x, particles[i].rotation.y, particles[i].rotation.z);
@@ -242,7 +252,7 @@ void SceneParticleEmitter::setParticleLifetime(Number lifetime) {
     this->lifetime = lifetime;
     for(int i=0; i < particles.size(); i++) {
         resetParticle(i);
-        particles[i].lifetime = RANDOM_NUMBER * lifetime;
+        particles[i].lifetime = RANDOM_NUMBER * -lifetime;
     }
 }
 
@@ -320,11 +330,15 @@ void SceneParticleEmitter::updateParticles() {
     for(int i=0; i < particles.size(); i++) {
         particles[i].lifetime += timeStep;
         if(particles[i].lifetime > lifetime) {
-            if(loopParticles) {
+            if(loopParticles && systemEnabled) {
                 resetParticle(i);
             }
         }
         
+        if(particles[i].lifetime < 0.0) {
+            continue;
+        }
+        
         normLife = particles[i].lifetime / lifetime;
         if(useColorCurves) {
             particles[i].color.setColor(colorCurveR.getHeightAt(normLife)*particles[i].brightnessDeviation,

+ 7 - 2
Core/Contents/Source/PolySceneEntityInstance.cpp

@@ -524,8 +524,13 @@ bool SceneEntityInstance::loadFromFile(const String& fileName) {
             if(matFile) {
                 ObjectEntry *path = (*matFile)["path"];
                 if(path) {
-                    ResourcePool *newPool = new ResourcePool(path->stringVal,  CoreServices::getInstance()->getResourceManager()->getGlobalPool());
-                    CoreServices::getInstance()->getMaterialManager()->loadMaterialLibraryIntoPool(newPool, path->stringVal);
+                    ResourcePool *newPool = CoreServices::getInstance()->getResourceManager()->getResourcePoolByName(path->stringVal);
+                    if(!newPool) {
+                        newPool = new ResourcePool(path->stringVal,  CoreServices::getInstance()->getResourceManager()->getGlobalPool());
+                        CoreServices::getInstance()->getMaterialManager()->loadMaterialLibraryIntoPool(newPool, path->stringVal);
+                        CoreServices::getInstance()->getResourceManager()->addResourcePool(newPool);
+                    }
+                    
                     linkResourcePool(newPool);
                 }
             }

+ 2 - 0
IDE/Contents/Include/TextureBrowser.h

@@ -57,6 +57,8 @@ class AssetList : public UIElement {
 		void handleEvent(Event *event);
 		
 		bool hasExtension(String extension);
+    
+        void clearList();
 		
 		void showFolder(String folderPath);
         void showResourcePool(ResourcePool *pool, int resourceFilter);

+ 1 - 0
IDE/Contents/Source/EntityEditorPropertyView.cpp

@@ -37,6 +37,7 @@ EntityEditorPropertyView::EntityEditorPropertyView() : UIElement() {
     materialSheet = new MaterialPropSheet();
     entityProps->addPropSheet(materialSheet);
     materialSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
+    materialSheet->addEventListener(this, Event::CHANGE_EVENT);
     
     shaderTexturesSheet = new ShaderTexturesSheet();
     entityProps->addPropSheet(shaderTexturesSheet);

+ 2 - 1
IDE/Contents/Source/PolycodeEditor.cpp

@@ -80,7 +80,8 @@ EditorHolder *PolycodeEditor::getEditorHolder() {
 }
 
 
-void PolycodeEditor::handleEvent(Event *event) {
+void PolycodeEditor::handleEvent(Event *event) {    
+    
 	if(event->getDispatcher() == CoreServices::getInstance()->getCore() && enabled) {
 		switch(event->getEventCode()) {
 

+ 12 - 3
IDE/Contents/Source/PolycodeEntityEditor.cpp

@@ -604,6 +604,7 @@ void EntityEditorMainView::addEntityFromMenu(String command) {
         sceneObjectRoot->addChild(newPrimitive);
         setEditorProps(newPrimitive);
         newPrimitive->setPosition(cursorPosition);
+        newPrimitive->setMaterialByName("Default");
         didPlaceEntity(newPrimitive);
         selectEntity(newPrimitive, false, false);
         return;
@@ -728,9 +729,8 @@ void EntityEditorMainView::addEntityFromMenu(String command) {
         newEmitter->colorCurveA.addControlPoint2dWithHandles(0.9, 0.5, 1.0, 0.5, 1.1, 0.5);
         
         selectEntity(newEmitter, false, false);
-        didPlaceEntity(newEmitter);        
+        didPlaceEntity(newEmitter);
         return;
-        
     }
 }
 
@@ -886,6 +886,7 @@ void EntityEditorMainView::handleEvent(Event *event) {
                 newMesh->cacheToVertexBuffer(true);
                 sceneObjectRoot->addChild(newMesh);
                 setEditorProps(newMesh);
+                newMesh->setMaterialByName("Default");
                 newMesh->setPosition(cursorPosition);
                 didPlaceEntity(newMesh);
                 selectEntity(newMesh, false, false);
@@ -1159,7 +1160,14 @@ void EntityEditorMainView::setObjectRoot(SceneEntityInstance *entity) {
 }
 
 EntityEditorMainView::~EntityEditorMainView() {
-	
+    delete mainScene;
+    delete renderTexture;
+    delete transformGizmo;
+    delete transformGizmoMenu;
+    delete trackballCamera;
+    delete grid;
+    delete cameraPreview;
+    input->removeAllHandlersForListener(this);
 }
 
 void EntityEditorMainView::Resize(Number width, Number height) {
@@ -1285,6 +1293,7 @@ void PolycodeEntityEditor::doAction(String actionName, PolycodeEditorActionData
 }
 
 PolycodeEntityEditor::~PolycodeEntityEditor() {
+    delete mainView;
 }
 
 bool PolycodeEntityEditor::openFile(OSFileEntry filePath) {	

+ 1 - 1
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -32,7 +32,7 @@ PolycodeEditorManager *globalEditorManager;
 Scene *globalScene;
 
 PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
-	core = new POLYCODE_CORE(view, 1100, 700,false,true, 0, 0,60, -1, true);
+	core = new POLYCODE_CORE(view, 1100, 700,false,false, 0, 0,60, -1, true);
 //	core->pauseOnLoseFocus = true;
     
 	printf("DIR: %s\n", core->getDefaultWorkingDirectory().c_str());

+ 2 - 0
IDE/Contents/Source/PolycodeMaterialEditor.cpp

@@ -1107,6 +1107,8 @@ void MaterialBrowser::Resize(Number width, Number height) {
 
 PolycodeMaterialEditor::PolycodeMaterialEditor() : PolycodeEditor(true){
     resourcePool = new ResourcePool("Local",     CoreServices::getInstance()->getResourceManager()->getGlobalPool());
+    resourcePool->reloadResourcesOnModify = true;
+    
     CoreServices::getInstance()->getResourceManager()->addResourcePool(resourcePool);
 	selectedMaterialNode = NULL;
 }

+ 1 - 0
IDE/Contents/Source/PolycodeMeshEditor.cpp

@@ -123,6 +123,7 @@ void PolycodeMeshEditor::handleEvent(Event *event) {
 }
 
 PolycodeMeshEditor::~PolycodeMeshEditor() {
+    printf("CALLED IT!\n");
     CoreServices::getInstance()->getResourceManager()->removeAllHandlersForListener(this);
 }
 

+ 5 - 4
IDE/Contents/Source/PolycodeProps.cpp

@@ -1162,7 +1162,8 @@ TextureProp::TextureProp(String caption) : PropProp(caption, "Texture"){
 	textureLabel->setPosition(-100, 32);
 	textureLabel->color.a = 1.0;
 		
-	setHeight(60);	
+	setHeight(60);
+    ownsChildren = true;
 }
 
 void TextureProp::setPropWidth(Number width) {
@@ -1171,7 +1172,7 @@ void TextureProp::setPropWidth(Number width) {
 }
 
 TextureProp::~TextureProp() {
-
+    
 }
 
 void TextureProp::setPropData(PolycodeEditorPropActionData* data) {
@@ -2903,6 +2904,7 @@ void MaterialPropSheet::handleEvent(Event *event) {
         Material *newMaterial = materialProp->get();
         if(sceneMesh->getMaterial() != newMaterial) {
             sceneMesh->setMaterial(newMaterial);
+            dispatchEvent(new Event(), Event::CHANGE_EVENT);
         }
     }
     PropSheet::handleEvent(event);
@@ -3424,8 +3426,7 @@ void LinkedMaterialsSheet::handleEvent(Event *event) {
 		String materialPath = globalFrame->assetBrowser->getSelectedAssetPath();
 
 		String fullMaterialPath = globalFrame->assetBrowser->getFullSelectedAssetPath();
-		
-        
+		        
         globalFrame->assetBrowser->removeAllHandlersForListener(this);
         globalFrame->hideModal();
         

+ 15 - 15
IDE/Contents/Source/TextureBrowser.cpp

@@ -118,16 +118,9 @@ bool AssetList::hasExtension(String extension) {
 }
 
 void AssetList::showResourcePool(ResourcePool *pool, int resourceFilter) {
-	for(int i=0; i < assetEntries.size(); i++) {
-		removeChild(assetEntries[i]);
-		delete assetEntries[i];
-	}
-	assetEntries.clear();
-
-    selectedResource = NULL;
-    
-	currentEntry = NULL;
 	
+    clearList();
+    
 	Number xPos = 20;
 	Number yPos = 30;
 	
@@ -161,17 +154,21 @@ void AssetList::showResourcePool(ResourcePool *pool, int resourceFilter) {
 	}
 }
 
-void AssetList::showFolder(String folderPath) {
-
-	currentFolderPath = folderPath;
-
+void AssetList::clearList() {
 	for(int i=0; i < assetEntries.size(); i++) {
 		removeChild(assetEntries[i]);
 		delete assetEntries[i];
 	}
 	assetEntries.clear();
-	
 	currentEntry = NULL;
+    selectedResource = NULL;
+}
+
+void AssetList::showFolder(String folderPath) {
+
+	currentFolderPath = folderPath;
+
+    clearList();
 	
 	vector<OSFileEntry> assets = OSBasics::parseFolder(folderPath, false);	
 	
@@ -289,7 +286,10 @@ void AssetBrowser::setResourcePools(std::vector<ResourcePool*> pools, int resour
 }
 
 void AssetBrowser::setBrowseMode(unsigned int newBrowseMode) {
-    browseMode = newBrowseMode;
+    if(browseMode != newBrowseMode) {
+        assetList->clearList();
+        browseMode = newBrowseMode;
+    }
 }
 
 void AssetBrowser::setProject(PolycodeProject *project) {

+ 1 - 1
IDE/Contents/Source/TransformGizmo.cpp

@@ -840,7 +840,7 @@ void TransformGizmo::dispatchEndEvent() {
 }
 
 TransformGizmo::~TransformGizmo() {
-
+    coreInput->removeAllHandlersForListener(this);
 }
 
 void TransformGizmo::updateOrientationForEntity(Entity *entity) {