Skip to content

Commit 1194dfe

Browse files
committed
Merge branch 'master' of https://github.com/ivansafrin/Polycode
2 parents edc12c4 + 4c3720b commit 1194dfe

File tree

8 files changed

+80
-6
lines changed

8 files changed

+80
-6
lines changed

Core/Contents/Include/PolyMesh.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ namespace Polycode {
381381

382382
static Vector3 calculateFaceTangent(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector2 &texCoord1, const Vector2 &texCoord2, const Vector2 &texCoord3);
383383

384+
void saveAsOBJ(const String fileName);
385+
384386
void normalizeBoneWeights();
385387

386388
VertexDataArray vertexPositionArray;

Core/Contents/Include/PolyVector2.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ namespace Polycode {
7676
inline Vector2 operator * (const Number val) const {
7777
return Vector2(x * val, y * val);
7878
}
79+
80+
inline Vector2 operator * (const Vector2 &v2) const {
81+
return Vector2(x * v2.x, y * v2.y);
82+
}
7983

8084
inline Vector2 operator / (const Number val) const {
8185
assert( val != 0.0 );

Core/Contents/Source/PolyMesh.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,40 @@ void Mesh::calculateNormals() {
13201320
}
13211321
}
13221322

1323+
void Mesh::saveAsOBJ(const String fileName) {
1324+
FILE *f = fopen(fileName.c_str(), "w");
1325+
1326+
if (!f) {
1327+
return;
1328+
}
1329+
1330+
char buffer[256];
1331+
1332+
for(int i=0; i < vertexPositionArray.data.size()-2; i += 3) {
1333+
sprintf(buffer, "v %f %f %f\n", vertexPositionArray.data[i], vertexPositionArray.data[i+1], vertexPositionArray.data[i+2]);
1334+
fputs(buffer, f);
1335+
}
1336+
1337+
for(int i=0; i < vertexTexCoordArray.data.size()-1; i += 2) {
1338+
sprintf(buffer, "vt %f %f\n", vertexTexCoordArray.data[i], vertexTexCoordArray.data[i+1]);
1339+
fputs(buffer, f);
1340+
}
1341+
1342+
1343+
for(int i=0; i < vertexNormalArray.data.size()-2; i += 3) {
1344+
sprintf(buffer, "vn %f %f %f\n", vertexNormalArray.data[i], vertexNormalArray.data[i+1], vertexNormalArray.data[i+2]);
1345+
fputs(buffer, f);
1346+
}
1347+
1348+
1349+
for(int i=0; i < indexArray.data.size()-2; i += 3) {
1350+
sprintf(buffer, "f %d %d %d\n", indexArray.data[i]+1, indexArray.data[i+1]+1, indexArray.data[i+2]+1);
1351+
fputs(buffer, f);
1352+
}
1353+
1354+
fclose(f);
1355+
}
1356+
13231357
int Mesh::getMeshType() {
13241358
return meshType;
13251359
}

Core/Contents/Source/PolySceneMesh.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,12 @@ void SceneMesh::Render() {
393393
}
394394
}
395395

396+
bool useVertexBuffer = this->useVertexBuffer;
397+
398+
if(useVertexBuffer && skeleton && !sendBoneMatricesToMaterial) {
399+
useVertexBuffer = false;
400+
}
401+
396402
if(useVertexBuffer) {
397403
VertexBuffer *vb = mesh->getVertexBuffer();
398404
if(vb){

IDE/Contents/Include/EntityEditorPropertyView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class EntityEditorPropertyView : public UIElement {
6161
SceneCurveSheet *curveSheet;
6262
CameraSheet *cameraSheet;
6363
EntityPropSheet *propSheet;
64+
SceneMeshSheet *sceneMeshSheet;
6465

6566
ShaderTexturesSheet *shaderTexturesSheet;
6667
ShaderOptionsSheet *shaderOptionsSheet;

IDE/Contents/Include/PolycodeProps.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ class SceneLightSheet : public PropSheet {
722722
SliderProp *shadowMapFOVProp;
723723
NumberProp *shadowResolutionProp;
724724
};
725-
/*
725+
726726
class SceneMeshSheet : public PropSheet {
727727
public:
728728
SceneMeshSheet();
@@ -733,9 +733,10 @@ class SceneMeshSheet : public PropSheet {
733733

734734
private:
735735

736+
BoolProp *gpuSkinningProp;
736737
SceneMesh *sceneMesh;
737738
};
738-
*/
739+
739740

740741
class ScenePrimitiveSheet : public PropSheet {
741742
public:

IDE/Contents/Source/EntityEditorPropertyView.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ EntityEditorPropertyView::EntityEditorPropertyView() : UIElement() {
7070
primitiveSheet = new ScenePrimitiveSheet();
7171
entityProps->addPropSheet(primitiveSheet);
7272
primitiveSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
73+
74+
sceneMeshSheet = new SceneMeshSheet();
75+
entityProps->addPropSheet(sceneMeshSheet);
76+
sceneMeshSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
7377

7478
soundSheet = new SoundSheet();
7579
entityProps->addPropSheet(soundSheet);
@@ -165,7 +169,9 @@ void EntityEditorPropertyView::setEntity(Entity *entity) {
165169
} else {
166170
primitiveSheet->setScenePrimitive(NULL);
167171
}
168-
172+
173+
sceneMeshSheet->setSceneMesh(sceneMesh);
174+
169175
SceneSound *sound = dynamic_cast<SceneSound*>(entity);
170176
soundSheet->setSound(sound);
171177

IDE/Contents/Source/PolycodeProps.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,24 +2838,44 @@ void SceneLightSheet::handleEvent(Event *event) {
28382838
}
28392839
PropSheet::handleEvent(event);
28402840
}
2841-
/*
2842-
SceneMeshSheet::SceneMeshSheet() : PropSheet("MESH FILE", "scene_mesh_file") {
2841+
2842+
SceneMeshSheet::SceneMeshSheet() : PropSheet("SCENE MESH", "scene_mesh") {
28432843
enabled = false;
28442844
sceneMesh = NULL;
2845+
2846+
gpuSkinningProp = new BoolProp("GPU Skinning");
2847+
addProp(gpuSkinningProp);
28452848
}
28462849

28472850
SceneMeshSheet::~SceneMeshSheet() {
28482851

28492852
}
28502853

28512854
void SceneMeshSheet::setSceneMesh(SceneMesh *mesh) {
2855+
this->sceneMesh = mesh;
28522856

2857+
if(sceneMesh) {
2858+
2859+
gpuSkinningProp->set(sceneMesh->sendBoneMatricesToMaterial);
2860+
2861+
enabled = true;
2862+
} else {
2863+
enabled = false;
2864+
}
28532865
}
28542866

28552867
void SceneMeshSheet::handleEvent(Event *event) {
2868+
if(!sceneMesh) {
2869+
return;
2870+
}
28562871

2872+
if(event->getDispatcher() == gpuSkinningProp) {
2873+
sceneMesh->sendBoneMatricesToMaterial = gpuSkinningProp->get();
2874+
}
2875+
2876+
PropSheet::handleEvent(event);
28572877
}
2858-
*/
2878+
28592879

28602880
ScenePrimitiveSheet::ScenePrimitiveSheet() : PropSheet("PRIMITIVE", "scene_primitive") {
28612881
typeProp = new ComboProp("Type");

0 commit comments

Comments
 (0)