Parcourir la source

Merge branch 'master' of https://github.com/ivansafrin/Polycode

Ivan Safrin il y a 11 ans
Parent
commit
1194dfe5ba

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

@@ -381,6 +381,8 @@ namespace Polycode {
         
             static Vector3 calculateFaceTangent(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector2 &texCoord1, const Vector2 &texCoord2, const Vector2 &texCoord3);
         
+            void saveAsOBJ(const String fileName);
+        
             void normalizeBoneWeights();
         
             VertexDataArray vertexPositionArray;

+ 4 - 0
Core/Contents/Include/PolyVector2.h

@@ -76,6 +76,10 @@ namespace Polycode {
 			inline Vector2 operator * (const Number val) const {
 				return Vector2(x * val, y * val);
 			}
+        
+            inline Vector2 operator * (const Vector2 &v2) const {
+                return Vector2(x * v2.x, y * v2.y);
+            }
 
 			inline Vector2 operator / (const Number val) const {
 				assert( val != 0.0 );

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

@@ -1320,6 +1320,40 @@ void Mesh::calculateNormals() {
     }
 }
 
+void Mesh::saveAsOBJ(const String fileName) {
+	FILE *f = fopen(fileName.c_str(), "w");
+    
+	if (!f) {
+		return;
+	}
+    
+	char buffer[256];
+
+    for(int i=0; i < vertexPositionArray.data.size()-2; i += 3) {
+		sprintf(buffer, "v %f %f %f\n", vertexPositionArray.data[i], vertexPositionArray.data[i+1], vertexPositionArray.data[i+2]);
+        fputs(buffer, f);
+    }
+    
+    for(int i=0; i < vertexTexCoordArray.data.size()-1; i += 2) {
+		sprintf(buffer, "vt %f %f\n", vertexTexCoordArray.data[i], vertexTexCoordArray.data[i+1]);
+        fputs(buffer, f);
+    }
+    
+
+    for(int i=0; i < vertexNormalArray.data.size()-2; i += 3) {
+		sprintf(buffer, "vn %f %f %f\n", vertexNormalArray.data[i], vertexNormalArray.data[i+1], vertexNormalArray.data[i+2]);
+        fputs(buffer, f);
+    }
+    
+    
+    for(int i=0; i < indexArray.data.size()-2; i += 3) {
+		sprintf(buffer, "f %d %d %d\n", indexArray.data[i]+1, indexArray.data[i+1]+1, indexArray.data[i+2]+1);
+        fputs(buffer, f);
+    }
+    
+	fclose(f);
+}
+
 int Mesh::getMeshType() {
     return meshType;
 }

+ 6 - 0
Core/Contents/Source/PolySceneMesh.cpp

@@ -393,6 +393,12 @@ void SceneMesh::Render() {
         }
     }
     
+    bool useVertexBuffer = this->useVertexBuffer;
+
+    if(useVertexBuffer && skeleton && !sendBoneMatricesToMaterial) {
+        useVertexBuffer = false;
+    }
+    
 	if(useVertexBuffer) {
         VertexBuffer *vb = mesh->getVertexBuffer();
         if(vb){

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

@@ -61,6 +61,7 @@ class EntityEditorPropertyView : public UIElement {
         SceneCurveSheet *curveSheet;
         CameraSheet *cameraSheet;
         EntityPropSheet *propSheet;
+        SceneMeshSheet *sceneMeshSheet;
     
         ShaderTexturesSheet *shaderTexturesSheet;
         ShaderOptionsSheet *shaderOptionsSheet;

+ 3 - 2
IDE/Contents/Include/PolycodeProps.h

@@ -722,7 +722,7 @@ class SceneLightSheet : public PropSheet {
         SliderProp *shadowMapFOVProp;
         NumberProp *shadowResolutionProp;
 };
-/*
+
 class SceneMeshSheet : public PropSheet {
     public:
         SceneMeshSheet();
@@ -733,9 +733,10 @@ class SceneMeshSheet : public PropSheet {
     
     private:
     
+        BoolProp *gpuSkinningProp;
         SceneMesh *sceneMesh;
 };
-*/
+
 
 class ScenePrimitiveSheet : public PropSheet {
 public:

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

@@ -70,6 +70,10 @@ EntityEditorPropertyView::EntityEditorPropertyView() : UIElement() {
     primitiveSheet = new ScenePrimitiveSheet();
     entityProps->addPropSheet(primitiveSheet);
     primitiveSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
+
+    sceneMeshSheet = new SceneMeshSheet();
+    entityProps->addPropSheet(sceneMeshSheet);
+    sceneMeshSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
     
     soundSheet = new SoundSheet();
     entityProps->addPropSheet(soundSheet);
@@ -165,7 +169,9 @@ void EntityEditorPropertyView::setEntity(Entity *entity) {
     } else {
         primitiveSheet->setScenePrimitive(NULL);
     }
-
+    
+    sceneMeshSheet->setSceneMesh(sceneMesh);
+    
     SceneSound *sound = dynamic_cast<SceneSound*>(entity);
     soundSheet->setSound(sound);
 

+ 23 - 3
IDE/Contents/Source/PolycodeProps.cpp

@@ -2838,10 +2838,13 @@ void SceneLightSheet::handleEvent(Event *event) {
     }
     PropSheet::handleEvent(event);
 }
-/*
-SceneMeshSheet::SceneMeshSheet() : PropSheet("MESH FILE", "scene_mesh_file") {
+
+SceneMeshSheet::SceneMeshSheet() : PropSheet("SCENE MESH", "scene_mesh") {
     enabled = false;
     sceneMesh = NULL;
+    
+    gpuSkinningProp = new BoolProp("GPU Skinning");
+    addProp(gpuSkinningProp);
 }
 
 SceneMeshSheet::~SceneMeshSheet() {
@@ -2849,13 +2852,30 @@ SceneMeshSheet::~SceneMeshSheet() {
 }
 
 void SceneMeshSheet::setSceneMesh(SceneMesh *mesh) {
+    this->sceneMesh = mesh;
     
+    if(sceneMesh) {
+        
+        gpuSkinningProp->set(sceneMesh->sendBoneMatricesToMaterial);
+        
+        enabled = true;
+    } else {
+        enabled = false;
+    }
 }
 
 void SceneMeshSheet::handleEvent(Event *event) {
+    if(!sceneMesh) {
+        return;
+    }
     
+    if(event->getDispatcher() == gpuSkinningProp) {
+        sceneMesh->sendBoneMatricesToMaterial = gpuSkinningProp->get();
+    }
+    
+    PropSheet::handleEvent(event);
 }
-*/
+
 
 ScenePrimitiveSheet::ScenePrimitiveSheet() : PropSheet("PRIMITIVE", "scene_primitive") {
     typeProp = new ComboProp("Type");