2016-04-27 5 views
0

Я новичок с gameplay3d и прошел все учебные пособия, однако я не могу отобразить эту простую (не много полигонов и материалов) модель, которую я закодировал из Fbx. Я проверил модель с единством3D, и закрытое исходное программное обеспечение, которое использует gameplay3d, и все, кажется, в порядке. Наверное, мне не хватает некоторых деталей, загружающих сцену.
Это файл модели, включающий также оригинальный файл fbx. Я подозреваю, что это имеет отношение к свету https://www.dropbox.com/sh/ohgpsfnkm3iv24s/AACApRcxwtbmpKu4_5nnp8rZa?dl=0 Это класс, который загружает сцену.В драйвере GamePlay3d не будет отображаться модель, импортированная из fbx

#include "Demo.h" 

// Declare our game instance 
Demo game; 

Demo::Demo() 
    : _scene(NULL), _wireframe(false) 
{ 
} 

void Demo::initialize() 
{ 
    // Load game scene from file 
    Bundle* bundle = Bundle::create("KGN56AI30N.gpb"); 
    _scene = bundle->loadScene(); 
    SAFE_RELEASE(bundle); 
    // Get the box model and initialize its material parameter values and bindings 

    Camera* camera = Camera::createPerspective(45.0f, getAspectRatio(), 1.0f, 20.0f); 
    Node* cameraNode = _scene->addNode("camera"); 

    // Attach the camera to a node. This determines the position of the camera. 
    cameraNode->setCamera(camera); 

    // Make this the active camera of the scene. 
    _scene->setActiveCamera(camera); 
    SAFE_RELEASE(camera); 
    // Move the camera to look at the origin. 
    cameraNode->translate(0,0, 10); 
    cameraNode->rotateX(MATH_DEG_TO_RAD(0.25f)); 
    // Update the aspect ratio for our scene's camera to match the current device resolution 
    _scene->getActiveCamera()->setAspectRatio(getAspectRatio()); 
    // Set the aspect ratio for the scene's camera to match the current resolution 
    _scene->getActiveCamera()->setAspectRatio(getAspectRatio()); 

    Light* directionalLight = Light::createDirectional(Vector3::one()); 
    _directionalLightNode = Node::create("directionalLight"); 
    _directionalLightNode->setLight(directionalLight); 
    SAFE_RELEASE(directionalLight); 
    _scene->addNode(_directionalLightNode); 
    _scene->setAmbientColor(1.0, 1.0, 1.0); 
    _scene->visit(this, &Demo::initializeMaterials); 

} 


bool Demo::initializeMaterials(Node* node) 
{ 
     Model* model = dynamic_cast<Model*>(node->getDrawable()); 

     if (model) 
     { 
      for(int i=0;i<model->getMeshPartCount();i++) 
      { 
      Material* material = model->getMaterial(i); 
      if(material) 
      { 
      // For this sample we will only bind a single light to each object in the scene. 
      MaterialParameter* colorParam = material->getParameter("u_directionalLightColor[0]"); 
      colorParam->setValue(Vector3(0.75f, 0.75f, 0.75f)); 
      MaterialParameter* directionParam = material->getParameter("u_directionalLightDirection[0]"); 
      directionParam->setValue(Vector3(1, 1, 1)); 
      } 
      } 
     } 
     return true; 
} 

void Demo::finalize() 
{ 
    SAFE_RELEASE(_scene); 
} 

void Demo::update(float elapsedTime) 
{ 
    // Rotate model 
    //_scene->findNode("box")->rotateY(MATH_DEG_TO_RAD((float)elapsedTime/1000.0f * 180.0f)); 
} 

void Demo::render(float elapsedTime) 
{ 
    // Clear the color and depth buffers 
    clear(CLEAR_COLOR_DEPTH, Vector4::zero(), 1.0f, 0); 

    // Visit all the nodes in the scene for drawing 
    _scene->visit(this, &Demo::drawScene); 
} 

bool Demo::drawScene(Node* node) 
{ 
    // If the node visited contains a drawable object, draw it 
    Drawable* drawable = node->getDrawable(); 
    if (drawable) 
     drawable->draw(_wireframe); 

    return true; 
} 

void Demo::keyEvent(Keyboard::KeyEvent evt, int key) 
{ 
    if (evt == Keyboard::KEY_PRESS) 
    { 
     switch (key) 
     { 
     case Keyboard::KEY_ESCAPE: 
      exit(); 
      break; 
     } 
    } 
} 

void Demo::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex) 
{ 
    switch (evt) 
    { 
    case Touch::TOUCH_PRESS: 
     _wireframe = !_wireframe; 
     break; 
    case Touch::TOUCH_RELEASE: 
     break; 
    case Touch::TOUCH_MOVE: 
     break; 
    }; 
} 

ответ

0

Я не могу загрузить ваш файл .box. Сколько моделей у вас на сцене? Вот простой способ сделать то, что вы хотите сделать - не оптимально, но это поможет вам начать ...

Итак, во-первых, я не вижу, где в вашем коде вы на самом деле назначаете Shader используется с материалом. Я использую что-то вроде этого:

material = model->setMaterial("Shaders/Animation/ADSVertexViewAnim.vsh", "Shaders/Animation/ADSVertexViewAnim.fsh"); 

Вам нужно назначить шейдер, и приведенный выше код будет принимать вершинные и фрагмент шейдеры и использовать его, когда объект должен быть нарисован.

Я поступил немного иначе, не загружая файл сцены автоматически, но создавая пустую сцену, а затем извлекая мою модель из комплекта и добавляя ее в сцену вручную. Таким образом, я могу точно видеть, что происходит, и я контролирую каждый шаг. GamePlay3D имеет некоторые файлы свойств fancy, но использует их только после того, как вы знаете, как этот процесс работает вручную.

Первоначально я создал простой куб в сцене и создал сцену вручную и добавил обезьяну на график узлов следующим образом:

void GameMain::ExtractFromBundle() 
{ 
    /// Create a new empty scene. 
    _scene = Scene::create(); 

    // Create the Model and its Node 
    Bundle* bundle = Bundle::create("res/monkey.gpb");   // Create the bundle from GPB file 

    /// Create the Cube 
    { 
     Mesh* meshMonkey = bundle->loadMesh("Character_Mesh");    // Load the mesh from the bundle 
     Model* modelMonkey = Model::create(meshMonkey); 
     Node* nodeMonkey = _scene->addNode("Monkey"); 
     nodeMonkey->setTranslation(0,0,0); 
     nodeMonkey->setDrawable(modelMonkey); 
    } 
} 

Тогда я хочу, чтобы искать граф сцены и только назначить материал к объекту, который я хочу сделать (обезьяна). Используйте это, если вы хотите назначить различные материалы для различных объектов вручную ...

bool GameMain::initializeScene(Node* node) 
{ 
    Material* material; 

    std::cout << node->getId() << std::endl; 

    // find the node in the scene 
    if (strcmp(node->getId(), "Monkey") != 0) 
     return false; 

    Model* model = dynamic_cast<Model*>(node->getDrawable()); 
    if(!model) 
     return false; 

    material = model->setMaterial("Shaders/Animation/ADSVertexViewAnim.vsh", "Shaders/Animation/ADSVertexViewAnim.fsh"); 

    material->getStateBlock()->setCullFace(true); 
    material->getStateBlock()->setDepthTest(true); 
    material->getStateBlock()->setDepthWrite(true); 

    // The World-View-Projection Matrix is needed to be able to see view the 3D world thru the camera 
    material->setParameterAutoBinding("u_worldViewProjectionMatrix", "WORLD_VIEW_PROJECTION_MATRIX"); 

    // This matrix is necessary to calculate normals properly, but the WORLD_MATRIX would also work 
    material->setParameterAutoBinding("u_worldViewMatrix", "WORLD_VIEW_MATRIX"); 
    material->setParameterAutoBinding("u_viewMatrix", "VIEW_MATRIX"); 

    return true; 
} 

Теперь объект готов быть обращено .... поэтому я использую эти функции:

void GameMain::render(float elapsedTime) 
{ 
    // Clear the color and depth buffers 
    clear(CLEAR_COLOR_DEPTH, Vector4(0.0, 0.0, 0.0, 0.0), 1.0f, 0); 

    // Visit all the nodes in the scene for drawing 
    _scene->visit(this, &GameMain::drawScene); 
} 

bool GameMain::drawScene(Node* node) 
{ 
    // If the node visited contains a drawable object, draw it 
    Drawable* drawable = node->getDrawable(); 
    if (drawable) 
     drawable->draw(_wireframe); 

    return true; 
} 

я использую мои собственные шейдеры, поэтому мне не нужно беспокоиться о Light и DirectionalLight и обо всем этом. Как только я увижу объект, я добавлю динамические огни и т. Д., Но для начала, начните просто.

С уважением.