mirror of
https://github.com/ApfelTeeSaft/vb01.git
synced 2026-08-26 19:33:45 +00:00
skeletal animation sample improvement
This commit is contained in:
+24
-19
@@ -6,7 +6,6 @@
|
||||
#include "animationController.h"
|
||||
#include "animationChannel.h"
|
||||
#include "assetManager.h"
|
||||
#include "imageReader.h"
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
@@ -17,7 +16,8 @@ using namespace vb01;
|
||||
int main(){
|
||||
const string PATH = "../", TEX_PATH = PATH + "samples/textures/", MODEL_PATH = PATH + "samples/models/";
|
||||
|
||||
string skyboxTextures[] = {
|
||||
const int numTextures = 6;
|
||||
string skyboxTextures[numTextures] = {
|
||||
TEX_PATH + "top.jpg",
|
||||
TEX_PATH + "bottom.jpg",
|
||||
TEX_PATH + "left.jpg",
|
||||
@@ -25,12 +25,10 @@ int main(){
|
||||
TEX_PATH + "front.jpg",
|
||||
TEX_PATH + "back.jpg"
|
||||
};
|
||||
AssetManager::getSingleton()->load(skyboxTextures[0]);
|
||||
AssetManager::getSingleton()->load(skyboxTextures[1]);
|
||||
AssetManager::getSingleton()->load(skyboxTextures[2]);
|
||||
AssetManager::getSingleton()->load(skyboxTextures[3]);
|
||||
AssetManager::getSingleton()->load(skyboxTextures[4]);
|
||||
AssetManager::getSingleton()->load(skyboxTextures[5]);
|
||||
|
||||
//Loads the assets to be stored and retrievable at a later time
|
||||
for(int i = 0; i < numTextures; i++)
|
||||
AssetManager::getSingleton()->load(skyboxTextures[i]);
|
||||
|
||||
/*
|
||||
* Gets Root object to start the sample,
|
||||
@@ -45,24 +43,25 @@ int main(){
|
||||
* Places the camera in front of the model.
|
||||
*/
|
||||
Camera *cam = root->getCamera();
|
||||
cam->setPosition(Vector3(0, 0, 1) * 20);
|
||||
cam->setPosition(Vector3(0, 0.25, 1) * 20);
|
||||
cam->lookAt(Vector3(0, 0, -1).norm(), Vector3(0, 1, 0).norm());
|
||||
|
||||
Model *model = new Model(MODEL_PATH + "kek.vb");
|
||||
AssetManager::getSingleton()->load(MODEL_PATH + "kek.xml");
|
||||
|
||||
Model *model = new Model(MODEL_PATH + "kek.xml");
|
||||
Material *mat = new Material(PATH + "texture");
|
||||
mat->addBoolUniform("lightingEnabled", false);
|
||||
mat->addBoolUniform("texturingEnabled", true);
|
||||
|
||||
string images[] = {TEX_PATH + "defaultTexture.jpg"};
|
||||
AssetManager::getSingleton()->load(images[0]);
|
||||
|
||||
Texture *texture = new Texture(images, 1, false);
|
||||
mat->addTexUniform("textures[0]", texture, true);
|
||||
mat->addBoolUniform("lightingEnabled", false);
|
||||
mat->addBoolUniform("texturingEnabled", true);
|
||||
|
||||
model->setMaterial(mat);
|
||||
rootNode->attachChild(model);
|
||||
|
||||
int numChildren = model->getNumChildren();
|
||||
Node *node = model->getChild(1);
|
||||
Mesh *mesh = node->getMesh(0);
|
||||
Skeleton *skeleton = mesh->getSkeleton();
|
||||
|
||||
/*
|
||||
* The AnimationController plays the animations set in the AnimationChannel objects.
|
||||
* AnimationChannel objects require an animation and animatable objects, e.g. textures to work.
|
||||
@@ -70,13 +69,19 @@ int main(){
|
||||
AnimationController *controller = AnimationController::getSingleton();
|
||||
AnimationChannel *channel = new AnimationChannel();
|
||||
controller->addAnimationChannel(channel);
|
||||
|
||||
/*
|
||||
* Here we see that it is possible to transform skeleton
|
||||
* bones either manually or via an animation.
|
||||
*/
|
||||
Skeleton *skeleton = model->getChild(0)->getSkeleton(0);
|
||||
skeleton->getBone("handIK.L")->setPosePos(Vector3(1.5, -1.5, 0));
|
||||
|
||||
channel->addAnimatable(skeleton->getBone("handIK.R"));
|
||||
channel->addAnimatable(skeleton->getBone("elbowIK.R"));
|
||||
channel->setAnimationName("righArmAnim");
|
||||
channel->setLoop(true);
|
||||
|
||||
skeleton->getBone("handIK.L")->setPosePos(Vector3(1.5, -1.5, 0));
|
||||
|
||||
while(true){
|
||||
root->update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user