Преглед изворни кода

Icosphere and Octosphere meshes now force correct mesh type, ScenePrimitive options for icospheres and octospheres, IDE entity editor primitive options for icosphere and octospheres

Ivan Safrin пре 11 година
родитељ
комит
b0cb636bc0

+ 17 - 2
Core/Contents/Include/PolyScenePrimitive.h

@@ -120,14 +120,29 @@ namespace Polycode {
 			* v3 - Number of segments
 			*/			
 			static const int TYPE_CIRCLE = 8;			
-
+        
+            /**
+             * An ico sphere.
+             * v1 - Sphere radius
+             * v2 - number of subdivisions
+             */
+            static const int TYPE_ICOSPHERE = 9;
+        
+            /**
+             * An ico sphere.
+             * v1 - Sphere radius
+             * v2 - number of subdivisions
+             */
+            static const int TYPE_OCTOSPHERE = 10;
+        
             /**
              * A 2D line circle.
              * v1 - X size
              * v2 - Y size
              * v3 - Number of segments
              */
-            static const int TYPE_LINE_CIRCLE = 9;
+            static const int TYPE_LINE_CIRCLE = 11;
+
 
             int getPrimitiveType() const;
         

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

@@ -678,6 +678,8 @@ void Mesh::subdivideToRadius(Number radius, int subdivisions)
 
 void Mesh::createOctosphere(Number radius, int subdivisions) {
 
+    setMeshType(Mesh::TRI_MESH);
+    
 	indexedMesh = true;
 
 	Vector3 points[6]={
@@ -705,7 +707,8 @@ void Mesh::createOctosphere(Number radius, int subdivisions) {
 	addIndexedFace(1, 5, 2);
 
 	subdivideToRadius(radius, subdivisions);
-
+    
+    calculateNormals();
 	calculateTangents();
 	arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;
 	arrayDirtyMap[RenderDataArray::COLOR_DATA_ARRAY] = true;
@@ -716,6 +719,8 @@ void Mesh::createOctosphere(Number radius, int subdivisions) {
 
 void Mesh::createIcosphere(Number radius, int subdivisions) {
 
+    setMeshType(Mesh::TRI_MESH);
+    
 	const float a = 0.5257311121191336;
 	const float b = 0.85065080835204;
 
@@ -765,6 +770,7 @@ void Mesh::createIcosphere(Number radius, int subdivisions) {
 
 	subdivideToRadius(radius, subdivisions);
 
+    calculateNormals();
 	calculateTangents();
 	arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;
 	arrayDirtyMap[RenderDataArray::COLOR_DATA_ARRAY] = true;

+ 8 - 0
Core/Contents/Source/PolyScenePrimitive.cpp

@@ -103,6 +103,14 @@ void ScenePrimitive::recreatePrimitive() {
 		case TYPE_LINE_CIRCLE:
 			mesh->createLineCircle(v1, v2, v3);
             setLocalBoundingBox(v1, v2, 0.001);
+        break;
+		case TYPE_ICOSPHERE:
+			mesh->createIcosphere(v1, v2);
+            setLocalBoundingBox(v1*2, v1*2, v1*2);
+        break;
+		case TYPE_OCTOSPHERE:
+			mesh->createOctosphere(v1, v2);
+            setLocalBoundingBox(v1*2, v1*2, v1*2);
         break;
 	}
 }

+ 38 - 1
IDE/Contents/Source/PolycodeProps.cpp

@@ -2788,6 +2788,8 @@ ScenePrimitiveSheet::ScenePrimitiveSheet() : PropSheet("PRIMITIVE", "scene_primi
     typeProp->comboEntry->addComboItem("Torus");
     typeProp->comboEntry->addComboItem("Cone");
     typeProp->comboEntry->addComboItem("Circle");
+    typeProp->comboEntry->addComboItem("IcoSphere");
+    typeProp->comboEntry->addComboItem("OctoSphere");
     
     addProp(typeProp);
     
@@ -2908,6 +2910,28 @@ void ScenePrimitiveSheet::updatePrimitiveLabels() {
             
             propHeight = 45 + (32 * 3);
         break;
+        case ScenePrimitive::TYPE_ICOSPHERE:
+            option1Prop->setPropName("Radius");
+            option2Prop->setPropName("Subdivisions");
+            
+            option1Prop->enabled = true;
+            option1Prop->visible = true;
+            option2Prop->enabled = true;
+            option2Prop->visible = true;
+            
+            propHeight = 45 + (32 * 2);
+        break;
+        case ScenePrimitive::TYPE_OCTOSPHERE:
+            option1Prop->setPropName("Radius");
+            option2Prop->setPropName("Subdivisions");
+            
+            option1Prop->enabled = true;
+            option1Prop->visible = true;
+            option2Prop->enabled = true;
+            option2Prop->visible = true;
+            
+            propHeight = 45 + (32 * 2);
+        break;
         case ScenePrimitive::TYPE_TORUS:
             option1Prop->setPropName("Torus radius");
             option2Prop->setPropName("Pipe radius");
@@ -2984,7 +3008,20 @@ void ScenePrimitiveSheet::handleEvent(Event *event) {
     }
     
     if(event->getEventCode() == Event::CHANGE_EVENT) {
-        primitive->setPrimitiveOptions(typeProp->get(), option1Prop->get(), option2Prop->get(), option3Prop->get(), option4Prop->get(), option5Prop->get());
+        
+        Number v1 = option1Prop->get();
+        Number v2 = option2Prop->get();
+        Number v3 = option3Prop->get();
+        Number v4 = option4Prop->get();
+        Number v5 = option5Prop->get();
+        
+        if((typeProp->get() == ScenePrimitive::TYPE_ICOSPHERE  && primitive->getPrimitiveType() != ScenePrimitive::TYPE_ICOSPHERE)|| (typeProp->get() == ScenePrimitive::TYPE_OCTOSPHERE  && primitive->getPrimitiveType() != ScenePrimitive::TYPE_OCTOSPHERE)) {
+            option2Prop->set(1.0);
+            v2 = 1.0;
+        }
+        
+        primitive->setPrimitiveOptions(typeProp->get(), v1, v2, v3, v4, v5);
+           
         if(event->getDispatcher() == typeProp) {
             updatePrimitiveLabels();
         }