Horde3D
http://www.horde3d.org/forums/

Example on making a box in Blender and displaying it
http://www.horde3d.org/forums/viewtopic.php?f=2&t=557
Page 1 of 2

Author:  kornerr [ 15.11.2008, 12:40 ]
Post subject:  Example on making a box in Blender and displaying it

Would someone be so kind as to write the Horde 'Hello, world' example?
Thanks.

Author:  marciano [ 15.11.2008, 13:59 ]
Post subject:  Re: Example on making a box in Blender and displaying it

We already have a Hello World Tutorial.

Author:  kornerr [ 15.11.2008, 15:22 ]
Post subject:  Re: Example on making a box in Blender and displaying it

I asked for a box from Blender, because it does not work right out of the box even with 'working' Blender exporter (yes, it's not displayed even with wireframe turned on). That would be real "Hello, world". You don't write fancy Output class in C++ for a "Hello, world", neither do you use some pre-built (by someone somehow) skeletal model with animation. Also, a "Hello, world" is a complete application which can be built with no problems (yes, all the #includes and all the stuff).

Author:  swiftcoder [ 15.11.2008, 19:10 ]
Post subject:  Re: Example on making a box in Blender and displaying it

kornerr wrote:
I asked for a box from Blender, because it does not work right out of the box even with 'working' Blender exporter (yes, it's not displayed even with wireframe turned on).
Most likely you have a material problem, check the log file to see if any materials failed to load - the blender exporter sometimes sets up the paths wrong.

Quote:
Also, a "Hello, world" is a complete application which can be built with no problems (yes, all the #includes and all the stuff).
That is a little bit problematic for Horde, as it isn't a standalone framework. One of the main problems is that Horde can be integrated with a variety of platform/windowing frameworks, there are comprehensive samples for several popular frameworks on the wiki page, and the samples demonstrate using GLFW.

Author:  kornerr [ 16.11.2008, 03:36 ]
Post subject:  Re: Example on making a box in Blender and displaying it

Yes, I've checked logs, no errors. loadResourcesFromDisk returns 1. And I repeat nothing is displayed in wireframe. I don't care be it GLFW or SDL. Both work fine with premade models (yes, platform.scene.xml from Chicago sample works fine, but not my box from Blender).
All I ask for is what you can do in 5 minutes. Is this hard?

Author:  Volker [ 16.11.2008, 13:20 ]
Post subject:  Re: Example on making a box in Blender and displaying it

Well I'm always glad to help if asked in such a kindly way! :twisted:

I added additional information to the Blender export page in the wiki and tested the import of the exported cube using the editor. It
was no real problem. You may try to create your scene within the editor. If the scene works fine there, you should be able to load the created .scene.xml file in your application. An additional tutorial how to load a scene created in the editor might follow, but remember that we don't get paid for developing Horde3D and both have full-time jobs that don't allow us to offer support on commercial level.

You could start by posting your attempt of loading your model, perhaps we can then fix the problems together and create a new Hello World wiki article from that.

Author:  kornerr [ 16.11.2008, 14:18 ]
Post subject:  Re: Example on making a box in Blender and displaying it

main.cpp
Code:
#include <horde3d/Horde3D.h>
#include <horde3d/Horde3DUtils.h>
#include <SDL.h>
#include <iostream>
#include <cmath>
using namespace std;
using namespace Horde3D;
using namespace Horde3DUtils;

ResHandle model = 0,
          cam = 0;

float rotX = -45,
      rotY = 0,
      posX = 0,
      posY = 40,
      posZ = -40;

inline float deg2Rad(float f) {
    return f * (3.1415926f / 180.0f);
}

int main() {
    SDL_Init(SDL_INIT_VIDEO);
    SDL_WM_SetCaption("Horde3D + SDL", 0);
    int w = 800,
        h = 600;
    SDL_SetVideoMode(w, h, 32, SDL_OPENGL);
    init();
    resize(0, 0, w, h);
    ResHandle pipeRes = addResource(ResourceTypes::Pipeline,
            "forward.pipeline.xml", 0);
    ResHandle modelRes = addResource(ResourceTypes::SceneGraph,
            "untitled.scene.xml", 0);
    ResHandle logoMatRes = addResource(ResourceTypes::Material,
            "logo.material.xml", 0);
    setResourcePath (ResourceTypes::SceneGraph, "models");
    setResourcePath (ResourceTypes::Geometry, "models");
    setResourcePath (ResourceTypes::Animation, "models");
    setResourcePath (ResourceTypes::Material, "materials");
    setResourcePath (ResourceTypes::Code, "shaders");
    setResourcePath (ResourceTypes::Shader, "shaders");
    setResourcePath (ResourceTypes::Texture2D, "textures");
    setResourcePath (ResourceTypes::TextureCube, "textures");
    setResourcePath (ResourceTypes::Effect, "effects");
    setResourcePath (ResourceTypes::Pipeline, "pipelines");
    setOption( EngineOptions::LoadTextures, 1 );
    setOption( EngineOptions::TexCompression, 0 );
    setOption( EngineOptions::FastAnimation, 0 );
    setOption( EngineOptions::AnisotropyFactor, 8 );
    setOption( EngineOptions::ShadowMapSize, 2048 );
    setOption( EngineOptions::WireframeMode, 1);

    cout << "loaded all: " << loadResourcesFromDisk("data") << endl;
    model = addNodes(RootNode, modelRes);
    setNodeTransform(model, 0, 0, 0, 0, 0, 0, 1, 1, 1);
    if(!model)
        cout << "model creation failed\n";
    NodeHandle light = addLightNode(RootNode, "Light1", 0, "LIGHTING",
            "SHADOWMAP");
    setNodeTransform(light, 0, 40, 0, 0, 0, 0, 1, 1, 1);
    setNodeParami(light, LightNodeParams::ShadowMapCount, 3);
    cam = addCameraNode(RootNode, "Camera", pipeRes);
    setNodeTransform(cam, 0, 40, 0, 0, 0, 0, 1, 1, 1);
    cout << "cam setup: " << setupCameraView(cam, 45,
            static_cast<float>(w)/h, 0.1, 1000) << endl;
    //setNodeTransform(cam, 0, 20, -20, 0, 0, 0, 1, 1, 1);
    if(!cam)
        cout << "cam creation failed\n";
    bool running = true;
    SDL_Event event;
    SDL_ShowCursor(SDL_DISABLE);
    SDL_WM_GrabInput(SDL_GRAB_ON);
    setNodeTransform(cam, posX, posY, posZ, rotX, rotY, 0, 1, 1, 1);
    while(running) {
        bool posRotChanged = false;
        if(SDL_PollEvent(&event)) {
            if(event.type == SDL_KEYDOWN) {
                //cout << "keydown event caught\n";
                switch(event.key.keysym.sym) {
                    case SDLK_ESCAPE:
                        running = false;
                        break;
                    // Move forward
                    case SDLK_w:
                        posX -= sinf(deg2Rad(rotY)) * cosf(-deg2Rad(rotX));
                        posY -= sinf(-deg2Rad(rotX));
                        posZ -= cosf(deg2Rad(rotY)) * cosf(-deg2Rad(rotX));
                        posRotChanged = true;
                        break;
                    // Move backward
                    case SDLK_s:
                        posX += sinf(deg2Rad(rotY)) * cosf(-deg2Rad(rotX));
                        posY += sinf(-deg2Rad(rotX));
                        posZ += cosf(deg2Rad(rotY)) * cosf(-deg2Rad(rotX));
                        posRotChanged = true;
                        break;
                    // Strafe left
                    case SDLK_a:
                        posX += sinf(deg2Rad(rotY - 90));
                        posZ += cosf(deg2Rad(rotY - 90));
                        posRotChanged = true;
                        break;
                    // Strafe right
                    case SDLK_d:
                        posX += sinf(deg2Rad(rotY + 90));
                        posZ += cosf(deg2Rad(rotY + 90));
                        posRotChanged = true;
                        break;
                    default:
                        break;
                }
            }
            else if(event.type == SDL_MOUSEMOTION) {
                //cout << "mousemove event caught\n";
                rotY -= event.motion.xrel;
                rotX -= event.motion.yrel;
                posRotChanged = true;
            }
        }
        if(posRotChanged)
            setNodeTransform(cam, posX, posY, posZ, rotX, rotY, 0,
                    1, 1, 1);
        showOverlay(0.75f, 0, 0, 0, 1, 0, 1, 0,
                1, 0.2f, 1, 1, 0.75f, 0.2f, 0, 1,
                7, logoMatRes);
        render(cam);
        SDL_GL_SwapBuffers();
    }
    dumpMessages();
    release();
    SDL_Quit();

    return 0;
}

models/untitled.scene.xml
Code:
<Model name="untitled" geometry="untitled.geo">

   <Mesh name="Cube" material="untitled/Material.material.xml" batchStart="0" batchCount="36" vertRStart="0" vertREnd="23" />

materials/untitled/Material.material.xml
Code:
<Material>
   <Shader source="skinning.shader.xml" />

   <Uniform name="Materialcol" a="0.8" b="0.8" c="0.8" d="1.0" />
</Material>

XMLs created with Blender exporter.

Attachments:
File comment: models/untitled.geo
untitled.geo.zip [333 Bytes]
Downloaded 631 times

Author:  swiftcoder [ 16.11.2008, 16:16 ]
Post subject:  Re: Example on making a box in Blender and displaying it

kornerr wrote:
models/untitled.scene.xml
Code:
<Model name="untitled" geometry="untitled.geo">

   <Mesh name="Cube" material="untitled/Material.material.xml" batchStart="0" batchCount="36" vertRStart="0" vertREnd="23" />
It may just have been missed when you copy/pasted, but it appears that the model file is missing the closing </Model> tag.

Author:  kornerr [ 16.11.2008, 16:19 ]
Post subject:  Re: Example on making a box in Blender and displaying it

Yes, missed the tag.

Author:  Volker [ 16.11.2008, 23:36 ]
Post subject:  Re: Example on making a box in Blender and displaying it

I've noticed, that you have a Materialcol uniform in your material file. I guess that's because you don't have any texture coordinates defined in your blender model. If you don't have a texture, you can't use the skinning shader. You may try the Materialcol.shader.xml in the Community SVN or create a blender model that uses UV texture mapping.

Author:  kornerr [ 17.11.2008, 00:30 ]
Post subject:  Re: Example on making a box in Blender and displaying it

Thanks, the box is finally visible with the above shader. I wonder how 'wireframe' should be affected at all by shaders in the first place. I thought it would always display the box.

Author:  Volker [ 17.11.2008, 08:07 ]
Post subject:  Re: Example on making a box in Blender and displaying it

You have to differ between wireframe and debug mode. In the debug mode you should indeed see the box even if no shader is loaded. In wireframe mode you see the same scene as in normal mode, the only difference is that it is rendered in wireframe mode.

Author:  Siavash [ 02.02.2009, 18:02 ]
Post subject:  Re: Example on making a box in Blender and displaying it

I've unwrapped a simple cube in blender 2.48a then textured it, but there isn't any textures in texture folder after exporting :?:

Author:  swiftcoder [ 02.02.2009, 19:13 ]
Post subject:  Re: Example on making a box in Blender and displaying it

Siavash wrote:
I've unwrapped a simple cube in blender 2.48a then textured it, but there isn't any textures in texture folder after exporting :?:
You have to export the textures separately - I don't think any of the exporters handle this for you.

Author:  Siavash [ 02.02.2009, 19:26 ]
Post subject:  Re: Example on making a box in Blender and displaying it

swiftcoder wrote:
Siavash wrote:
I've unwrapped a simple cube in blender 2.48a then textured it, but there isn't any textures in texture folder after exporting :?:
You have to export the textures separately - I don't think any of the exporters handle this for you.
Could you explain it a bit more, then how to export and assign textures to models ?

Page 1 of 2 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/