Просмотр исходного кода

Fixed scene primitives to all use triangles, added ScenePrimitive property sheet to entity editor, fixed ray-polygon intersect, added a new primitive type for line only circles

Ivan Safrin 12 лет назад
Родитель
Сommit
a0e54ada27

+ 8 - 0
Core/Contents/Include/PolyMesh.h

@@ -205,6 +205,14 @@ namespace Polycode {
 			*/ 
 			void createCircle(Number w, Number h, unsigned int numSegments);
 
+            /**
+             * Creates a 2D circle with normals pointing outwards from vertices.
+             * @param w Width of circle.
+             * @param h Height of plane.
+             * @param numSegments Number of segments
+             */
+            void createLineCircle(Number w, Number h, unsigned int numSegments);
+
 			/**
 			* Creates a torus.
 			* @param radius Radius of the torus.

+ 45 - 32
Core/Contents/Include/PolyScenePrimitive.h

@@ -65,14 +65,13 @@ namespace Polycode {
 			*/			
 			static const int TYPE_PLANE = 1;			
 
-			/**
-			* A sphere.
-			* v1 - Sphere radius
-			* v2 - Lat segments				
-			* v3 - Long segments			
-			*/						
-			static const int TYPE_SPHERE = 2;
-
+            /**
+             * A vertical plane.
+             * v1 - X size
+             * v2 - Y size
+             */
+            static const int TYPE_VPLANE = 2;
+        
 			/**
 			* A cylinder.
 			* v1 - Cylinder length			
@@ -81,20 +80,21 @@ namespace Polycode {
 			*/			
 			static const int TYPE_CYLINDER = 3;
 
-			/**
-			* A cone.
-			* v1 - Cone length.
-			* v2 - Cone raidus.
-			* v3 - Number of segments.
-			*/			
-			static const int TYPE_CONE = 4;
-
-			/**
-			* A vertical plane.
-			* v1 - X size
-			* v2 - Y size						
-			*/			
-			static const int TYPE_VPLANE = 5;			
+            /**
+             * A cylinder.
+             * v1 - Cylinder length
+             * v2 - Cylinder radius
+             * v3 - Number of segments.
+             */
+            static const int TYPE_UNCAPPED_CYLINDER = 4;
+
+            /**
+             * A sphere.
+             * v1 - Sphere radius
+             * v2 - Lat segments
+             * v3 - Long segments
+             */
+            static const int TYPE_SPHERE = 5;
 
 			/**
 			* A torus.
@@ -104,15 +104,14 @@ namespace Polycode {
 			* v4- Number of pipe segments.
 			*/			
 			static const int TYPE_TORUS = 6;	
-			
-
-			/**
-			* A cylinder.
-			* v1 - Cylinder length			
-			* v2 - Cylinder radius
-			* v3 - Number of segments.
-			*/			
-			static const int TYPE_UNCAPPED_CYLINDER = 7;
+			     
+            /**
+             * A cone.
+             * v1 - Cone length.
+             * v2 - Cone raidus.
+             * v3 - Number of segments.
+             */
+            static const int TYPE_CONE = 7;
 
 			/**
 			* A 2D circle.
@@ -122,7 +121,21 @@ namespace Polycode {
 			*/			
 			static const int TYPE_CIRCLE = 8;			
 
-							
+            /**
+             * A 2D line circle.
+             * v1 - X size
+             * v2 - Y size
+             * v3 - Number of segments
+             */
+            static const int TYPE_LINE_CIRCLE = 9;
+
+            int getPrimitiveType() const;
+        
+            Number getPrimitiveParameter1() const;
+            Number getPrimitiveParameter2() const;
+            Number getPrimitiveParameter3() const;
+            Number getPrimitiveParameter4() const;
+            Number getPrimitiveParameter5() const;
 		
 		protected:
 

+ 2 - 1
Core/Contents/Source/PolyMaterial.cpp

@@ -47,7 +47,8 @@ Material::~Material() {
 
 void Material::setName(const String &name) {
 	this->name = name;
-	dispatchEvent(new Event(), Event::RESOURCE_CHANGE_EVENT);	
+    setResourceName(name);
+	dispatchEvent(new Event(), Event::RESOURCE_CHANGE_EVENT);
 }
 
 void Material::clearShaders() {

+ 109 - 34
Core/Contents/Source/PolyMesh.cpp

@@ -267,68 +267,111 @@ namespace Polycode {
 	}
 
 	void Mesh::createCircle(Number w, Number h, unsigned int numSegments) {
+		setMeshType(Mesh::TRI_MESH);
+
+        Number lastx = 0;
+		Number lasty = 0;
+		Number lastv = 0;
+
+        Polycode::Polygon *polygon;
+		for (int i=0 ; i < numSegments+1; i++) {
+			Number v = ((Number)i)/((Number)numSegments);
+			Number pos = ((PI*2.0)/((Number)numSegments)) * i;
+			Number x = sin(pos) * w;
+			Number y = cos(pos) * h;
+			
+			if(i > 0) {
+                polygon = new Polygon();
+                polygon->addVertex(0,0,0,0.5,0.5)->setNormal(0.0, 0.0, 1.0);
+                polygon->addVertex(x,y,0, 0.5+(y/h*0.5), 0.5+(x/w*0.5))->setNormal(0.0, 0.0, 1.0);
+                polygon->addVertex(lastx,lasty,0, 0.5+(lasty/h*0.5), 0.5+(lastx/w*0.5))->setNormal(0.0, 0.0, 1.0);
+                addPolygon(polygon);
+            }
+			lastx = x;
+			lastv = v;
+			lasty = y;
+        }
+        
+        
+		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::TANGENT_DATA_ARRAY] = true;			
+	}
+
+    void Mesh::createLineCircle(Number w, Number h, unsigned int numSegments) {
 		setMeshType(Mesh::TRIFAN_MESH);
+     
 		Polygon *poly = new Polygon();
 		int step;
 		if(numSegments > 0) {
-				step = ceil(360/numSegments);
+            step = ceil(360/numSegments);
 		} else {
-				step = 1;
+            step = 1;
 		}
 		
-  
-		poly->addVertex(cosf(0)*(w/2),sinf(0)*(h/2), 0, (cosf(0)*0.5) + 0.5,(sinf(0) * 0.5)+ 0.5);		
+        
+		poly->addVertex(cosf(0)*(w/2),sinf(0)*(h/2), 0, (cosf(0)*0.5) + 0.5,(sinf(0) * 0.5)+ 0.5);
 		for (int i=0; i < 361; i+= step) {
-				Number degInRad = i*TORADIANS;
-				Vertex *v = poly->addVertex(cos(degInRad)*(w/2),sin(degInRad)*(h/2), 0, (cos(degInRad) * 0.5)+ 0.5 , 1.0- ((sin(degInRad) * 0.5)+ 0.5));
-				Vector3 normal = *v; 
-				normal.Normalize();
-				v->normal = normal;
+            Number degInRad = i*TORADIANS;
+            Vertex *v = poly->addVertex(cos(degInRad)*(w/2),sin(degInRad)*(h/2), 0, (cos(degInRad) * 0.5)+ 0.5 , 1.0- ((sin(degInRad) * 0.5)+ 0.5));
+            Vector3 normal = *v;
+            normal.Normalize();
+            v->normal = normal;
 		}
 		
 		addPolygon(poly);
-		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::TANGENT_DATA_ARRAY] = true;			
-	}
-	
-	
-	void Mesh::createVPlane(Number w, Number h) { 
-		Polygon *imagePolygon = new Polygon();
-		
-		imagePolygon->addVertex(0,0,0,0,0);
-		imagePolygon->addVertex(w,0,0, 1, 0);		
-		imagePolygon->addVertex(w,h,0, 1, 1);									
-		imagePolygon->addVertex(0,h,0,0,1);	
-
-
-		addPolygon(imagePolygon);
+        
+		arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;
+		arrayDirtyMap[RenderDataArray::COLOR_DATA_ARRAY] = true;
+		arrayDirtyMap[RenderDataArray::TEXCOORD_DATA_ARRAY] = true;
+		arrayDirtyMap[RenderDataArray::NORMAL_DATA_ARRAY] = true;
+    }
+	
+	void Mesh::createVPlane(Number w, Number h) {
+        setMeshType(Mesh::TRI_MESH);
+        
+        Polycode::Polygon *polygon = new Polygon();
+		polygon->addVertex(0,0,0,0,0)->setNormal(0.0, 0.0, 1.0);
+		polygon->addVertex(w,0,0, 1, 0)->setNormal(0.0, 0.0, 1.0);
+		polygon->addVertex(w,h,0, 1, 1)->setNormal(0.0, 0.0, 1.0);
+		addPolygon(polygon);
+        
+        polygon = new Polygon();
+		polygon->addVertex(0,0,0,0,0)->setNormal(0.0, 0.0, 1.0);
+		polygon->addVertex(w,h,0, 1, 1)->setNormal(0.0, 0.0, 1.0);
+		polygon->addVertex(0,h,0,0,1)->setNormal(0.0, 0.0, 1.0);
+		addPolygon(polygon);
 		
 		for(int i=0; i < polygons.size(); i++) {
 			for(int j=0; j < polygons[i]->getVertexCount(); j++) {
 				polygons[i]->getVertex(j)->x = polygons[i]->getVertex(j)->x - (w/2.0f);
 				polygons[i]->getVertex(j)->y = polygons[i]->getVertex(j)->y - (h/2.0f);
+                
 			}
 		}
 
-		calculateNormals();
-		calculateTangents();
-		arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;		
+		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::TANGENT_DATA_ARRAY] = true;		
 	}	
 	
-	void Mesh::createPlane(Number w, Number h) { 
+	void Mesh::createPlane(Number w, Number h) {
+        setMeshType(Mesh::TRI_MESH);
+        
 		Polygon *imagePolygon = new Polygon();
 		imagePolygon->addVertex(0,0,h,0,0);	
 		imagePolygon->addVertex(w,0,h, 1, 0);			
-		imagePolygon->addVertex(w,0,0, 1, 1);		
+		imagePolygon->addVertex(w,0,0, 1, 1);
+		addPolygon(imagePolygon);
+        
+        imagePolygon = new Polygon();
+        imagePolygon->addVertex(0,0,h,0,0);
+		imagePolygon->addVertex(w,0,0, 1, 1);
 		imagePolygon->addVertex(0,0,0,0,1);
-
 		addPolygon(imagePolygon);
 		
 		for(int i=0; i < polygons.size(); i++) {
@@ -695,9 +738,16 @@ namespace Polycode {
 	}
 
 	void Mesh::createBox(Number w, Number d, Number h) {
+        setMeshType(Mesh::TRI_MESH);
+        
 		Polygon *polygon = new Polygon();
 		polygon->addVertex(w,0,h, 1, 1);
 		polygon->addVertex(0,0,h, 1, 0);
+		polygon->addVertex(0,0,0,0,0);
+		addPolygon(polygon);
+        
+        polygon = new Polygon();
+        polygon->addVertex(w,0,h, 1, 1);
 		polygon->addVertex(0,0,0,0,0);
 		polygon->addVertex(w,0,0,0,1);
 		addPolygon(polygon);
@@ -706,6 +756,11 @@ namespace Polycode {
 		polygon->addVertex(w,d,h, 1, 1);
 		polygon->addVertex(w,d,0, 1, 0);
 		polygon->addVertex(0,d,0,0,0);
+        addPolygon(polygon);
+        
+		polygon = new Polygon();
+		polygon->addVertex(w,d,h, 1, 1);
+		polygon->addVertex(0,d,0,0,0);
 		polygon->addVertex(0,d,h,0,1);
 		addPolygon(polygon);
 
@@ -713,6 +768,11 @@ namespace Polycode {
 		polygon->addVertex(0,d,0,0,1);
 		polygon->addVertex(w,d,0, 1, 1);
 		polygon->addVertex(w,0,0, 1, 0);
+		addPolygon(polygon);
+
+        polygon = new Polygon();
+		polygon->addVertex(0,d,0,0,1);
+		polygon->addVertex(w,0,0, 1, 0);
 		polygon->addVertex(0,0,0,0,0);
 		addPolygon(polygon);
 
@@ -720,6 +780,11 @@ namespace Polycode {
 		polygon->addVertex(0,0,h,0,0);
 		polygon->addVertex(w,0,h, 1, 0);
 		polygon->addVertex(w,d,h, 1, 1);
+		addPolygon(polygon);
+
+        polygon = new Polygon();
+		polygon->addVertex(0,0,h,0,0);
+		polygon->addVertex(w,d,h, 1, 1);
 		polygon->addVertex(0,d,h,0,1);
 		addPolygon(polygon);
 
@@ -727,6 +792,11 @@ namespace Polycode {
 		polygon->addVertex(0,0,h,0,1);
 		polygon->addVertex(0,d,h, 1, 1);
 		polygon->addVertex(0,d,0, 1, 0);
+		addPolygon(polygon);
+        
+		polygon = new Polygon();
+		polygon->addVertex(0,0,h,0,1);
+		polygon->addVertex(0,d,0, 1, 0);
 		polygon->addVertex(0,0,0,0,0);
 		addPolygon(polygon);
 
@@ -734,6 +804,11 @@ namespace Polycode {
 		polygon->addVertex(w,0,h,0,1);
 		polygon->addVertex(w,0,0, 1, 1);
 		polygon->addVertex(w,d,0, 1, 0);
+        addPolygon(polygon);
+        
+        polygon = new Polygon();
+		polygon->addVertex(w,0,h,0,1);
+		polygon->addVertex(w,d,0, 1, 0);
 		polygon->addVertex(w,d,h,0,0);
 		addPolygon(polygon);
 
@@ -745,7 +820,7 @@ namespace Polycode {
 			}
 		}
 
-		calculateNormals();
+		calculateNormals(false);
 		calculateTangents();
 		arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;		
 		arrayDirtyMap[RenderDataArray::COLOR_DATA_ARRAY] = true;				

+ 5 - 5
Core/Contents/Source/PolyRay.cpp

@@ -57,15 +57,15 @@ Vector3 Ray::planeIntersectPoint(const Vector3 &planeNormal, Number planeDistanc
 
 bool Ray::polygonIntersect(Polycode::Polygon *polygon) const {
 
-	if(polygon->getVertexCount() < 3) {
+	if(polygon->getVertexCount() != 3) {
 		return false;
 	}
-	
+    
 	Number t,u,v;
 	t = 0; u = 0; v = 0;
 
-	Vector3 edge1 = (*(Vector3*)polygon->getVertex(1)) - (*(Vector3*)polygon->getVertex(0));
-	Vector3 edge2 = (*(Vector3*)polygon->getVertex(2)) - (*(Vector3*)polygon->getVertex(0));
+	Vector3 edge1 = (*(Vector3*)polygon->getVertex(1)) - (*(Vector3*)polygon->getVertex(2));
+	Vector3 edge2 = (*(Vector3*)polygon->getVertex(0)) - (*(Vector3*)polygon->getVertex(2));
 
 	Vector3 tvec, pvec, qvec;
 	Number det, inv_det;
@@ -78,7 +78,7 @@ bool Ray::polygonIntersect(Polycode::Polygon *polygon) const {
 
 	inv_det = 1.0f / det;
 
-	tvec = origin - (*(Vector3*)polygon->getVertex(0));
+	tvec = origin - (*(Vector3*)polygon->getVertex(2));
 
 	u = tvec.dot(pvec) * inv_det;
 	if (u < -0.001f || u > 1.001f)

+ 31 - 1
Core/Contents/Source/PolyScenePrimitive.cpp

@@ -37,7 +37,31 @@ ScenePrimitive::ScenePrimitive(int type, Number v1, Number v2, Number v3,Number
 	recreatePrimitive();
 }
 
-void ScenePrimitive::recreatePrimitive() {	
+int ScenePrimitive::getPrimitiveType() const {
+    return type;
+}
+
+Number ScenePrimitive::getPrimitiveParameter1() const {
+    return v1;
+}
+
+Number ScenePrimitive::getPrimitiveParameter2() const {
+    return v2;
+}
+    
+Number ScenePrimitive::getPrimitiveParameter3() const {
+    return v3;
+}
+
+Number ScenePrimitive::getPrimitiveParameter4() const {
+    return v4;
+}
+
+Number ScenePrimitive::getPrimitiveParameter5() const {
+    return v5;
+}
+
+void ScenePrimitive::recreatePrimitive() {
 	mesh->clearMesh();
 	switch(type) {
 		case TYPE_PLANE:
@@ -94,6 +118,12 @@ void ScenePrimitive::recreatePrimitive() {
 			bBox.y = v2;
 			bBox.z = 0.001;
 		break;
+		case TYPE_LINE_CIRCLE:
+			mesh->createLineCircle(v1, v2, v3);
+			bBox.x = v1;
+			bBox.y = v2;
+			bBox.z = 0.001;
+        break;
 	}
 }
 

+ 1 - 0
IDE/Contents/Include/EntityEditorPropertyView.h

@@ -44,5 +44,6 @@ class EntityEditorPropertyView : public UIElement {
         PropList *entityProps;
         EntitySheet *entitySheet;
         MaterialPropSheet *materialSheet;
+        ScenePrimitiveSheet *primitiveSheet;
 };
 

+ 0 - 5
IDE/Contents/Include/PolycodeImageEditor.h

@@ -40,11 +40,6 @@ class PolycodeImageEditor : public PolycodeEditor {
 	
 		UIRect *editorImage;
 		
-		UIRect *leftShape;		
-		UIRect *rightShape;		
-		UIRect *topShape;		
-		UIRect *bottomShape;								
-		
 		Number aspectRatio;
 };
 

+ 34 - 1
IDE/Contents/Include/PolycodeProps.h

@@ -42,7 +42,8 @@ class PropProp : public UIElement {
 		virtual void setPropData(PolycodeEditorPropActionData* data) {}
 		
 		virtual void setPropWidth(Number width) {}
-		
+        void setPropName(String newName);
+    
 		String propType;
 		UILabel *label;
 		Entity *propContents;				
@@ -508,6 +509,38 @@ class RenderTargetsSheet : public PropSheet {
 		UIButton *addButton;		
 		int removeIndex;
 };
+/*
+class TransformSheet : public PropSheet {
+    public:
+        TransformSheet();
+        ~TransformSheet();
+    
+        void setEntity(Entity *entity);
+    protected:
+        Entity *entity;
+};
+*/
+class ScenePrimitiveSheet : public PropSheet {
+public:
+    ScenePrimitiveSheet();
+    ~ScenePrimitiveSheet();
+    
+    void setScenePrimitive(ScenePrimitive *primitive);
+    void handleEvent(Event *event);
+    
+protected:
+    
+    void updatePrimitiveLabels();
+    
+    ScenePrimitive *primitive;
+    ComboProp *typeProp;
+    
+    NumberProp *option1Prop;
+    NumberProp *option2Prop;
+    NumberProp *option3Prop;
+    NumberProp *option4Prop;
+    NumberProp *option5Prop;
+};
 
 class MaterialPropSheet : public PropSheet {
     public:

+ 1 - 0
IDE/Contents/Include/TransformGizmo.h

@@ -61,6 +61,7 @@ class TransformGizmo : public Entity {
 	
 		Scene *targetScene;
 		Camera *targetCamera;
+    
 	
 		CoreInput *coreInput;
 		int mode;

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

@@ -31,6 +31,9 @@ EntityEditorPropertyView::EntityEditorPropertyView() : UIElement() {
     entityProps->addPropSheet(materialSheet);
     materialSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
     
+    primitiveSheet = new ScenePrimitiveSheet();
+    entityProps->addPropSheet(primitiveSheet);
+    primitiveSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
     
     entitySheet = new EntitySheet();
     entityProps->addPropSheet(entitySheet);
@@ -47,7 +50,10 @@ void EntityEditorPropertyView::setEntity(Entity *entity) {
     
     SceneMesh *sceneMesh = dynamic_cast<SceneMesh*>(entity);
     materialSheet->setSceneMesh(sceneMesh);
-    
+
+    ScenePrimitive *scenePrimitive = dynamic_cast<ScenePrimitive*>(entity);
+    primitiveSheet->setScenePrimitive(scenePrimitive);
+
     entitySheet->setEntity(entity);
     Resize(getWidth(), getHeight());
 }

+ 29 - 0
IDE/Contents/Source/PolycodeEntityEditor.cpp

@@ -176,6 +176,27 @@ void EntityEditorMainView::addEntityFromMenu(String command) {
         return;
     }
 
+    if(command == "add_primitive") {
+        ScenePrimitive  *newPrimitive = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 1.0, 1.0, 1.0);
+        sceneObjectRoot->addChild(newPrimitive);
+        setEditorProps(newPrimitive);
+        newPrimitive->setPosition(cursorPosition);
+        selectEntity(newPrimitive);
+        newPrimitive->getMesh()->calculateNormals(false);
+        return;
+    }
+    
+    
+    if(command == "add_image") {
+        assetSelectType = "image";
+        globalFrame->assetBrowser->addEventListener(this, UIEvent::OK_EVENT);
+        std::vector<String> extensions;
+        extensions.push_back("png");
+        globalFrame->showAssetBrowser(extensions);
+        return;
+    }
+    
+    
     if(command == "add_light") {
         SceneLight *newLight = new SceneLight(SceneLight::AREA_LIGHT, mainScene, 50);
         
@@ -212,6 +233,12 @@ void EntityEditorMainView::handleEvent(Event *event) {
                 setEditorProps(newMesh);
                 newMesh->setPosition(cursorPosition);
                 selectEntity(newMesh);
+            } else if(assetSelectType == "image") {
+                SceneImage *newImage = new SceneImage(globalFrame->assetBrowser->getFullSelectedAssetPath());
+                sceneObjectRoot->addChild(newImage);
+                setEditorProps(newImage);
+                newImage->setPosition(cursorPosition);
+                selectEntity(newImage);
             }
             
             globalFrame->assetBrowser->removeAllHandlersForListener(this);
@@ -227,7 +254,9 @@ void EntityEditorMainView::handleEvent(Event *event) {
         addEntityMenu->addOption("Add Primitive", "add_primitive");
         addEntityMenu->addOption("Add Mesh", "add_mesh");
         addEntityMenu->addOption("Add Entity", "add_entity");
+        addEntityMenu->addDivider();
         addEntityMenu->addOption("Add Sprite", "add_sprite");
+        addEntityMenu->addOption("Add Image", "add_image");
         addEntityMenu->addOption("Add Label", "add_label");
         addEntityMenu->addDivider();
         addEntityMenu->addOption("Add Light", "add_light");

+ 5 - 1
IDE/Contents/Source/PolycodeFrame.cpp

@@ -735,6 +735,7 @@ void EditorHolder::makeVSplit() {
 		firstChildHolder->setEditor(currentEditor);
 		currentEditor = NULL;
 	}
+    Resize(getWidth(), getHeight());
 }
 
 void EditorHolder::makeHSplit() {
@@ -762,6 +763,7 @@ void EditorHolder::makeHSplit() {
 		firstChildHolder->setEditor(currentEditor);
 		currentEditor = NULL;
 	}
+    Resize(getWidth(), getHeight());    
 }
 
 void EditorHolder::handleEvent(Event *event) {
@@ -778,11 +780,13 @@ void EditorHolder::handleEvent(Event *event) {
 		PolycodeEditor *editor = (PolycodeEditor*) currentFileSelector->getSelectedItem()->data;
 		if(currentEditor != editor) {
 			setEditor(editor);
+            Resize(getWidth(), getHeight());
 		}
 	
 	} else if(event->getDispatcher() == mergeSplitButton) {
 		if(parentHolder) {
 			parentHolder->mergeSides(this);
+            Resize(getWidth(), getHeight());
 		}
 	} else if(event->getDispatcher() == closeFileButton) {
 		dispatchEvent(new UIEvent(), UIEvent::CLOSE_EVENT);
@@ -790,9 +794,9 @@ void EditorHolder::handleEvent(Event *event) {
 		if(event->getEventCode() == UIEvent::CLOSE_EVENT) {
 			dispatchEvent(new UIEvent(), UIEvent::CLOSE_EVENT);		
 		}
+        Resize(getWidth(), getHeight());
 	}
 	
-	Resize(getWidth(), getHeight());
 	UIElement::handleEvent(event);
 }
 

+ 3 - 39
IDE/Contents/Source/PolycodeImageEditor.cpp

@@ -28,40 +28,15 @@ PolycodeImageEditor::PolycodeImageEditor() : PolycodeEditor(true){
 
 PolycodeImageEditor::~PolycodeImageEditor() {
 	delete editorImage;
-	delete leftShape;
-	delete rightShape;
-	delete topShape;
-	delete bottomShape;
 }
 
 bool PolycodeImageEditor::openFile(OSFileEntry filePath) {
-	
-	
-	leftShape = new UIRect(10,10);
-	leftShape->setColor(0.0, 0.0, 0.0, 0.3);
-	leftShape->setAnchorPoint(-1.0, -1.0, 0.0);
-	addChild(leftShape);
-
-	rightShape = new UIRect(10,10);
-	rightShape->setColor(0.0, 0.0, 0.0, 0.3);
-	rightShape->setAnchorPoint(-1.0, -1.0, 0.0);
-	addChild(rightShape);
-
-	topShape = new UIRect(10,10);
-	topShape->setColor(0.0, 0.0, 0.0, 0.3);
-	topShape->setAnchorPoint(-1.0, -1.0, 0.0);
-	addChild(topShape);
-
-	bottomShape = new UIRect(10,10);
-	bottomShape->setColor(0.0, 0.0, 0.0, 0.3);
-	bottomShape->setAnchorPoint(-1.0, -1.0, 0.0);
-	addChild(bottomShape);
-			
+		
 	editorImage = new UIRect(filePath.fullPath);
 	aspectRatio = ((Number)editorImage->getWidth()) / ((Number)editorImage->getHeight());
 	editorImage->setAnchorPoint(0.0, 0.0, 0.0);
 	addChild(editorImage);
-	
+	editorImage->setBlendingMode(Renderer::BLEND_MODE_NORMAL);
 	PolycodeEditor::openFile(filePath);
 	
 	return true;
@@ -76,18 +51,7 @@ void PolycodeImageEditor::Resize(int x, int y) {
 	} else {
 		editorImage->Resize((y * 0.8) * aspectRatio, (y * 0.8));
 	}
-	
-	leftShape->Resize((x - editorImage->getWidth())/2.0, y);	
-	rightShape->Resize((x - editorImage->getWidth())/2.0, y);	
-	rightShape->setPosition(leftShape->getWidth() + editorImage->getWidth(), 0);
-		
-	topShape->Resize(editorImage->getWidth(), (y - editorImage->getHeight())/2.0);
-	topShape->setPosition(leftShape->getWidth(),0);
-
-	bottomShape->Resize(editorImage->getWidth(), (y - editorImage->getHeight())/2.0);
-	bottomShape->setPosition(leftShape->getWidth(),y-bottomShape->getHeight());
-
-		
+			
 	PolycodeEditor::Resize(x,y);
 }
 

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

@@ -914,7 +914,7 @@ void MaterialEditorPane::handleEvent(Event *event) {
 			dispatchEvent(new Event(), Event::CHANGE_EVENT);
 		}
 	} else if(event->getDispatcher() == nameProp) {
-		currentMaterial->setName(nameProp->get());
+		currentMaterial->setName(nameProp->get());        
 		if(!changingMaterial) {
 			dispatchEvent(new Event(), Event::CHANGE_EVENT);
 		}

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

@@ -123,6 +123,7 @@ void PolycodeMeshEditor::handleEvent(Event *event) {
 }
 
 PolycodeMeshEditor::~PolycodeMeshEditor() {
+    CoreServices::getInstance()->getResourceManager()->removeAllHandlersForListener(this);
 }
 
 bool PolycodeMeshEditor::openFile(OSFileEntry filePath) {

+ 219 - 0
IDE/Contents/Source/PolycodeProps.cpp

@@ -317,6 +317,9 @@ void PropSheet::applyPropActionData(PolycodeEditorPropActionData *data) {
 	data->prop->setPropData(data);
 }
 
+void PropProp::setPropName(String newName) {
+    label->setText(newName);
+}
 
 PropProp::PropProp(String caption, String type) : UIElement() {
 
@@ -2038,6 +2041,222 @@ void ShaderTexturesSheet::setShader(Shader *shader, Material *material, ShaderBi
 	Resize(getWidth(), getHeight());
 }
 
+ScenePrimitiveSheet::ScenePrimitiveSheet() : PropSheet("PRIMITIVE", "scene_primitive") {
+    typeProp = new ComboProp("Type");
+    typeProp->comboEntry->addComboItem("Box");
+    typeProp->comboEntry->addComboItem("Plane");
+    typeProp->comboEntry->addComboItem("Vert. Plane");
+    typeProp->comboEntry->addComboItem("Cylinder");
+    typeProp->comboEntry->addComboItem("Uncapped Cylinder");
+    typeProp->comboEntry->addComboItem("Sphere");
+    typeProp->comboEntry->addComboItem("Torus");
+    typeProp->comboEntry->addComboItem("Cone");
+    typeProp->comboEntry->addComboItem("Circle");
+    
+    addProp(typeProp);
+    
+    option1Prop = new NumberProp("");
+    addProp(option1Prop);
+    
+    option2Prop = new NumberProp("");
+    addProp(option2Prop);
+    
+    option3Prop = new NumberProp("");
+    addProp(option3Prop);
+    
+    option4Prop = new NumberProp("");
+    addProp(option4Prop);
+
+    option5Prop = new NumberProp("");
+    addProp(option5Prop);
+
+    propHeight = 240;
+    
+    enabled = false;
+    primitive = NULL;
+}
+
+void ScenePrimitiveSheet::updatePrimitiveLabels() {
+    if(!primitive) {
+        return;
+    }
+
+    option1Prop->enabled = false;
+    option1Prop->visible = false;
+    option2Prop->enabled = false;
+    option2Prop->visible = false;
+    option3Prop->enabled = false;
+    option3Prop->visible = false;
+    option4Prop->enabled = false;
+    option4Prop->visible = false;
+    option5Prop->enabled = false;
+    option5Prop->visible = false;
+    
+
+    switch(primitive->getPrimitiveType()) {
+        case ScenePrimitive::TYPE_BOX:
+            option1Prop->setPropName("Width");
+            option2Prop->setPropName("Height");
+            option3Prop->setPropName("Depth");
+            
+            option1Prop->enabled = true;
+            option1Prop->visible = true;
+            option2Prop->enabled = true;
+            option2Prop->visible = true;
+            option3Prop->enabled = true;
+            option3Prop->visible = true;
+            
+            propHeight = 45 + (45 * 3);
+        break;
+        case ScenePrimitive::TYPE_PLANE:
+            option1Prop->setPropName("Width");
+            option2Prop->setPropName("Height");
+            
+            option1Prop->enabled = true;
+            option1Prop->visible = true;
+            option2Prop->enabled = true;
+            option2Prop->visible = true;
+            
+            propHeight = 45 + (45 * 2);
+        break;
+        case ScenePrimitive::TYPE_VPLANE:
+            option1Prop->setPropName("Width");
+            option2Prop->setPropName("Height");
+            
+            option1Prop->enabled = true;
+            option1Prop->visible = true;
+            option2Prop->enabled = true;
+            option2Prop->visible = true;
+            
+            propHeight = 45 + (45 * 2);
+        break;
+        case ScenePrimitive::TYPE_CYLINDER:
+            option1Prop->setPropName("Length");
+            option2Prop->setPropName("Radius");
+            option3Prop->setPropName("Segments");
+            
+            option1Prop->enabled = true;
+            option1Prop->visible = true;
+            option2Prop->enabled = true;
+            option2Prop->visible = true;
+            option3Prop->enabled = true;
+            option3Prop->visible = true;
+            
+            propHeight = 45 + (45 * 3);
+        break;
+        case ScenePrimitive::TYPE_UNCAPPED_CYLINDER:
+            option1Prop->setPropName("Length");
+            option2Prop->setPropName("Radius");
+            option3Prop->setPropName("Segments");
+            
+            option1Prop->enabled = true;
+            option1Prop->visible = true;
+            option2Prop->enabled = true;
+            option2Prop->visible = true;
+            option3Prop->enabled = true;
+            option3Prop->visible = true;
+            
+            propHeight = 45 + (45 * 3);
+        break;
+        case ScenePrimitive::TYPE_SPHERE:
+            option1Prop->setPropName("Radius");
+            option2Prop->setPropName("Lat. segments");
+            option3Prop->setPropName("Long. segments");
+            
+            option1Prop->enabled = true;
+            option1Prop->visible = true;
+            option2Prop->enabled = true;
+            option2Prop->visible = true;
+            option3Prop->enabled = true;
+            option3Prop->visible = true;
+            
+            propHeight = 45 + (45 * 3);
+        break;
+        case ScenePrimitive::TYPE_TORUS:
+            option1Prop->setPropName("Torus radius");
+            option2Prop->setPropName("Pipe radius");
+            option3Prop->setPropName("Ring segments");
+            option4Prop->setPropName("Pipe segments");
+            
+            option1Prop->enabled = true;
+            option1Prop->visible = true;
+            option2Prop->enabled = true;
+            option2Prop->visible = true;
+            option3Prop->enabled = true;
+            option3Prop->visible = true;
+            option4Prop->enabled = true;
+            option4Prop->visible = true;
+            
+            propHeight = 45 + (45 * 4);
+        break;
+        case ScenePrimitive::TYPE_CONE:
+            option1Prop->setPropName("Length");
+            option2Prop->setPropName("Radius");
+            option3Prop->setPropName("Segments");
+            
+            option1Prop->enabled = true;
+            option1Prop->visible = true;
+            option2Prop->enabled = true;
+            option2Prop->visible = true;
+            option3Prop->enabled = true;
+            option3Prop->visible = true;
+            
+            propHeight = 45 + (45 * 3);
+        break;
+        case ScenePrimitive::TYPE_CIRCLE:
+            option1Prop->setPropName("Width");
+            option2Prop->setPropName("Height");
+            option3Prop->setPropName("Segments");
+            
+            option1Prop->enabled = true;
+            option1Prop->visible = true;
+            option2Prop->enabled = true;
+            option2Prop->visible = true;
+            option3Prop->enabled = true;
+            option3Prop->visible = true;
+            
+            propHeight = 45 + (45 * 3);
+        break;
+    }
+    dispatchEvent(new Event(), Event::COMPLETE_EVENT);
+}
+
+ScenePrimitiveSheet::~ScenePrimitiveSheet() {
+    
+}
+
+void ScenePrimitiveSheet::setScenePrimitive(ScenePrimitive *primitive) {
+    this->primitive = primitive;
+    if(primitive) {
+        typeProp->set(primitive->getPrimitiveType());
+        option1Prop->set(primitive->getPrimitiveParameter1());
+        option2Prop->set(primitive->getPrimitiveParameter2());
+        option3Prop->set(primitive->getPrimitiveParameter3());
+        option4Prop->set(primitive->getPrimitiveParameter4());
+        option5Prop->set(primitive->getPrimitiveParameter5());
+        updatePrimitiveLabels();
+        enabled = true;
+    } else {
+        enabled = false;
+    }
+}
+
+void ScenePrimitiveSheet::handleEvent(Event *event) {
+    
+    if(!primitive) {
+        return;
+    }
+    
+    if(event->getEventCode() == Event::CHANGE_EVENT) {
+        primitive->setPrimitiveOptions(typeProp->get(), option1Prop->get(), option2Prop->get(), option3Prop->get(), option4Prop->get(), option5Prop->get());
+        if(event->getDispatcher() == typeProp) {
+            updatePrimitiveLabels();
+        }
+    }
+    
+    PropSheet::handleEvent(event);
+}
+
 MaterialPropSheet::MaterialPropSheet() : PropSheet("MATERIAL", "material") {
     materialProp = new ComboProp("Material");
     addProp(materialProp);

+ 3 - 0
IDE/Contents/Source/ToolWindows.cpp

@@ -245,6 +245,9 @@ AssetImporterWindow::AssetImporterWindow() : UIWindow("3D Asset Importer", 500,
 }
 
 void AssetImporterWindow::handleEvent(Event *event) {
+    if(!enabled) {
+        return;
+    }
 	if(event->getDispatcher() == okButton) {
 	
 		String prefixString;

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

@@ -64,7 +64,7 @@ TransformGizmo::TransformGizmo(Scene *targetScene, Camera *targetCamera) : Entit
 	this->targetScene = targetScene;
 	this->targetCamera = targetCamera;
 	
-	ScenePrimitive *centerCircle = new ScenePrimitive(ScenePrimitive::TYPE_CIRCLE, 0.3, 0.3, 16);
+	ScenePrimitive *centerCircle = new ScenePrimitive(ScenePrimitive::TYPE_LINE_CIRCLE, 0.3, 0.3, 16);
 	centerCircle->getMesh()->setMeshType(Mesh::LINE_LOOP_MESH);
 	centerCircle->setColor(0.7, 0.7, 0.7, 1.0);
 	centerCircle->depthTest = false;
@@ -163,7 +163,7 @@ TransformGizmo::TransformGizmo(Scene *targetScene, Camera *targetCamera) : Entit
 
 	// ROTATE
 
-	bgCircle = new ScenePrimitive(ScenePrimitive::TYPE_CIRCLE, 1.6, 1.6, 32);
+	bgCircle = new ScenePrimitive(ScenePrimitive::TYPE_LINE_CIRCLE, 1.6, 1.6, 32);
 	bgCircle->getMesh()->setMeshType(Mesh::LINE_LOOP_MESH);
 	bgCircle->setColor(0.0, 0.0, 0.0, 1.0);
 	bgCircle->depthTest = false;
@@ -171,7 +171,7 @@ TransformGizmo::TransformGizmo(Scene *targetScene, Camera *targetCamera) : Entit
 	rotateDectorators->addChild(bgCircle);
     bgCircle->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX());
 
-	outerCircle = new ScenePrimitive(ScenePrimitive::TYPE_CIRCLE, 2.0, 2.0, 32);
+	outerCircle = new ScenePrimitive(ScenePrimitive::TYPE_LINE_CIRCLE, 2.0, 2.0, 32);
 	outerCircle->getMesh()->setMeshType(Mesh::LINE_LOOP_MESH);
 	outerCircle->setColor(1.0, 1.0, 1.0, 1.0);
 	outerCircle->depthTest = false;
@@ -179,7 +179,7 @@ TransformGizmo::TransformGizmo(Scene *targetScene, Camera *targetCamera) : Entit
 	rotateDectorators->addChild(outerCircle);
     outerCircle->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX());
     
-	pitchCircle = new ScenePrimitive(ScenePrimitive::TYPE_CIRCLE, 1.55, 1.55, 32);
+	pitchCircle = new ScenePrimitive(ScenePrimitive::TYPE_LINE_CIRCLE, 1.55, 1.55, 32);
 	pitchCircle->getMesh()->setMeshType(Mesh::LINE_LOOP_MESH);
 	pitchCircle->setColor(1.0, 0.0, 0.0, 1.0);
 	pitchCircle->depthTest = false;
@@ -188,7 +188,7 @@ TransformGizmo::TransformGizmo(Scene *targetScene, Camera *targetCamera) : Entit
 	pitchCircle->setMaterialByName("OneSidedLine");
     pitchCircle->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX());
     
-	yawCircle = new ScenePrimitive(ScenePrimitive::TYPE_CIRCLE, 1.65, 1.65, 32);
+	yawCircle = new ScenePrimitive(ScenePrimitive::TYPE_LINE_CIRCLE, 1.65, 1.65, 32);
 	yawCircle->getMesh()->setMeshType(Mesh::LINE_LOOP_MESH);
 	yawCircle->setColor(0.0, 1.0, 0.0, 1.0);
 	yawCircle->depthTest = false;
@@ -197,7 +197,7 @@ TransformGizmo::TransformGizmo(Scene *targetScene, Camera *targetCamera) : Entit
 	yawCircle->setMaterialByName("OneSidedLine");
     yawCircle->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX());
     
-	rollCircle = new ScenePrimitive(ScenePrimitive::TYPE_CIRCLE, 1.6, 1.6, 32);
+	rollCircle = new ScenePrimitive(ScenePrimitive::TYPE_LINE_CIRCLE, 1.6, 1.6, 32);
 	rollCircle->getMesh()->setMeshType(Mesh::LINE_LOOP_MESH);
 	rollCircle->setColor(0.0, 0.0, 1.0, 1.0);
 	rollCircle->depthTest = false;