demo 2: lots of vertices imported from blender
This commit is contained in:
parent
0e6f2db4ed
commit
aaa580852e
|
@ -29,3 +29,4 @@ add_subdirectory(engine)
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
|
|
||||||
add_subdirectory(demos/demo1-wireframes)
|
add_subdirectory(demos/demo1-wireframes)
|
||||||
|
add_subdirectory(demos/demo2-blender-import)
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
project(monkey)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME}.elf
|
||||||
|
src/main.cpp
|
||||||
|
src/mesh.cpp
|
||||||
|
src/monkey.cpp
|
||||||
|
src/monkey.h
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${PROJECT_NAME}.elf gba-bitmap-engine)
|
||||||
|
|
||||||
|
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
|
||||||
|
COMMAND ${CMAKE_OBJCOPY} -v -O binary ${PROJECT_NAME}.elf ${PROJECT_NAME}.gba
|
||||||
|
)
|
|
@ -0,0 +1,68 @@
|
||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
var jsonObject = JSON.parse(fs.readFileSync('monkey.babylon', 'utf8'));
|
||||||
|
|
||||||
|
var result =
|
||||||
|
"#include <libgba-sprite-engine/mesh.h>\n" +
|
||||||
|
"Mesh* createMesh() { \n" +
|
||||||
|
"\t auto obj = new Mesh();\n";
|
||||||
|
|
||||||
|
var meshes = 0;
|
||||||
|
function addMesh(x, y, z) {
|
||||||
|
result += `\t obj->add(VectorFx::fromInt(${x}, ${y}, ${z}));\n`;
|
||||||
|
meshes++;
|
||||||
|
}
|
||||||
|
var faces = 0;
|
||||||
|
function addFace(a, b, c) {
|
||||||
|
result += `\t obj->addFace({ ${a}, ${b}, ${c}});\n`;
|
||||||
|
faces++;
|
||||||
|
}
|
||||||
|
function setPosition(position) {
|
||||||
|
result += `\t obj->setPosition(VectorFx::fromInt(${position[0]}, ${position[1]}, ${position[2]}));\n`;
|
||||||
|
}
|
||||||
|
function done() {
|
||||||
|
result +=
|
||||||
|
"\t return obj;\n" +
|
||||||
|
"}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
for(var meshIndex = 0; meshIndex < jsonObject.meshes.length; meshIndex++) {
|
||||||
|
var verticesArray = jsonObject.meshes[meshIndex].vertices;
|
||||||
|
var indicesArray = jsonObject.meshes[meshIndex].indices;
|
||||||
|
var uvCount = jsonObject.meshes[meshIndex].uvCount;
|
||||||
|
var verticesStep = 1;
|
||||||
|
switch(uvCount) {
|
||||||
|
case 0:
|
||||||
|
verticesStep = 6;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
verticesStep = 8;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
verticesStep = 10;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
var verticesCount = verticesArray.length / verticesStep;
|
||||||
|
var facesCount = indicesArray.length / 3;
|
||||||
|
//var mesh = new SoftEngine.Mesh(jsonObject.meshes[meshIndex].name, verticesCount, facesCount);
|
||||||
|
for(var index = 0; index < verticesCount; index++) {
|
||||||
|
var x = verticesArray[index * verticesStep];
|
||||||
|
var y = verticesArray[index * verticesStep + 1];
|
||||||
|
var z = verticesArray[index * verticesStep + 2];
|
||||||
|
|
||||||
|
addMesh(x, y, z);
|
||||||
|
}
|
||||||
|
for(var index = 0; index < facesCount; index++) {
|
||||||
|
var a = indicesArray[index * 3];
|
||||||
|
var b = indicesArray[index * 3 + 1];
|
||||||
|
var c = indicesArray[index * 3 + 2];
|
||||||
|
|
||||||
|
addFace(a, b, c);
|
||||||
|
}
|
||||||
|
var position = jsonObject.meshes[meshIndex].position;
|
||||||
|
setPosition(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
done();
|
||||||
|
fs.writeFileSync('src/mesh.cpp', result);
|
||||||
|
console.log(`mesh.cpp written; ${meshes} meshes and ${faces} faces. GLHF!`)
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,22 @@
|
||||||
|
//
|
||||||
|
// Created by Wouter Groeneveld on 11/07/20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <libgba-sprite-engine/scene.h>
|
||||||
|
#include <libgba-sprite-engine/gba_engine.h>
|
||||||
|
#include <libgba-sprite-engine/palette/palette_manager.h>
|
||||||
|
|
||||||
|
#include "monkey.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::shared_ptr<GBAEngine> engine(new GBAEngine());
|
||||||
|
|
||||||
|
MonkeyScene* startScene = new MonkeyScene(engine);
|
||||||
|
engine->setScene(startScene);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
engine->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,38 @@
|
||||||
|
//
|
||||||
|
// Created by Wouter Groeneveld on 11/07/20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <libgba-sprite-engine/background/text_stream.h>
|
||||||
|
#include "monkey.h"
|
||||||
|
|
||||||
|
const unsigned short pal[4] __attribute__((aligned(4))) = {
|
||||||
|
0x0000, 0xFFFF, 0x3AE2
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<Mesh*> MonkeyScene::meshes() {
|
||||||
|
return { monkey.get() };
|
||||||
|
}
|
||||||
|
|
||||||
|
Camera MonkeyScene::camera() {
|
||||||
|
return Camera(VectorFx::fromInt(0, 0, 10), VectorFx::fromInt(0, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
int msecs = 1;
|
||||||
|
void MonkeyScene::load() {
|
||||||
|
foregroundPalette = std::unique_ptr<ForegroundPaletteManager>(new ForegroundPaletteManager());
|
||||||
|
backgroundPalette = std::unique_ptr<BackgroundPaletteManager>(new BackgroundPaletteManager(pal, sizeof(pal)));
|
||||||
|
|
||||||
|
monkey = std::unique_ptr<Mesh>(createMesh());
|
||||||
|
|
||||||
|
engine->getTimer()->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MonkeyScene::tick(u16 keys) {
|
||||||
|
int curmsecs = engine->getTimer()->getMsecs();
|
||||||
|
int elapsed = curmsecs - msecs;
|
||||||
|
msecs = curmsecs;
|
||||||
|
|
||||||
|
TextStream::instance().setText(std::to_string(1000 / elapsed) + std::string(" FPS"), 1, 1);
|
||||||
|
|
||||||
|
monkey->rotate(2, 2);
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
//
|
||||||
|
// Created by Wouter Groeneveld on 11/07/20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef GBA_BITMAP_ENGINE_PROJECT_MONKEY_H
|
||||||
|
#define GBA_BITMAP_ENGINE_PROJECT_MONKEY_H
|
||||||
|
|
||||||
|
#include <libgba-sprite-engine/scene.h>
|
||||||
|
#include <libgba-sprite-engine/mesh.h>
|
||||||
|
#include <libgba-sprite-engine/camera.h>
|
||||||
|
#include <libgba-sprite-engine/gba_engine.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
// forward declaration of generated mesh.cpp file
|
||||||
|
Mesh* createMesh();
|
||||||
|
|
||||||
|
class MonkeyScene : public Scene {
|
||||||
|
private:
|
||||||
|
std::unique_ptr<Mesh> monkey;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
MonkeyScene(std::shared_ptr<GBAEngine> engine) : Scene(engine) {}
|
||||||
|
|
||||||
|
void load() override;
|
||||||
|
void tick(u16 keys) override;
|
||||||
|
std::vector<Mesh*> meshes() override;
|
||||||
|
Camera camera() override;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //GBA_BITMAP_ENGINE_PROJECT_MONKEY_H
|
|
@ -8,6 +8,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include <libgba-sprite-engine/gba/tonc_types.h>
|
||||||
|
|
||||||
#define TEXT_WIDTH 8
|
#define TEXT_WIDTH 8
|
||||||
|
|
||||||
// tonc_text.h assemly ref
|
// tonc_text.h assemly ref
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
return facesArr;
|
return facesArr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setPosition(VectorFx position) { pos = position; }
|
||||||
inline VectorFx &position() { return pos; }
|
inline VectorFx &position() { return pos; }
|
||||||
inline VectorFx &rotation() { return rot; }
|
inline VectorFx &rotation() { return rot; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue