ISceneNode* BinaryStreamArchiveReader::ReadNode() {
    SceneNodeTags tag = SceneNodeTags(ReadInt(TAG_KEY));
    ISceneNode *node = NULL;
    // Read a node

    switch (tag) {
#define SCENE_NODE(type)                            \
        case NODE_##type :                          \
            node = new type();                      \
            break;
#include <Scene/SceneNodes.def>
#undef SCENE_NODE
    case NODE_NULL:
        return NULL;
    case NODE_END:
        throw Core::Exception("Unknown node tag in ReadScene");
        break;
    }
    // Read children...
    unsigned int size = Begin(CHILD_KEY);

    for (unsigned int i=0; i<size; i++) {
        node->AddNode(ReadNode());
    }

    End(CHILD_KEY);

    node->Deserialize(*this);
    return node;

}
Esempio n. 2
0
void SetupScene(Config& config) {
    // Create scene nodes
    config.dynamicScene = new SceneNode();

    config.renderingScene->AddNode(config.dynamicScene);

    config.dynamicScene->AddNode(config.lightTrans);

    ISceneNode* current = config.dynamicScene;

    // Add models from models.txt to the scene
    ifstream* mfile = File::Open("projects/ShadowDemo/models.txt");
    
    bool firstModel = true;
    
    while (!mfile->eof()) {
        string mod_str;
        getline(*mfile, mod_str);

        // Check the string
        if (mod_str[0] == '#' || mod_str == "") continue;

        // Load the model
        IModelResourcePtr mod_res = ResourceManager<IModelResource>::Create(mod_str);
        mod_res->Load();
        if (mod_res->GetSceneNode() == NULL) continue;

        ISceneNode* mod_node = mod_res->GetSceneNode();
        mod_res->Unload();

        TransformationNode* mod_tran = new TransformationNode();
        mod_tran->AddNode(mod_node);
 
        if(firstModel){
            //config.camera->Follow(mod_tran);
            mod_tran->Move(0, 30, 190);
            firstModel = false;
        }else{
            mod_tran->Move(0, -50, 230);
        }
        
        current->AddNode(mod_tran);
        logger.info << "Successfully loaded " << mod_str << logger.end;
    }
    mfile->close();
    delete mfile;
}
Esempio n. 3
0
void SetupScene(Config& config) {
    if (config.scene  != NULL ||
        config.mouse  == NULL ||
        config.keyboard == NULL)
        throw Exception("Setup scene dependencies are not satisfied.");

    // Create a root scene node


    RenderStateNode* rn = new RenderStateNode();
    rn->EnableOption(RenderStateNode::COLOR_MATERIAL);
    rn->EnableOption(RenderStateNode::LIGHTING);
    //rn->EnableOption(RenderStateNode::BACKFACE);

    ISceneNode* root = config.scene = rn;

    PointLightNode *pln = new PointLightNode();
    pln->diffuse = Vector<4,float>(.5,.5,.5,1);
    TransformationNode *lightTn = new TransformationNode();

    lightTn->SetPosition(Vector<3,float>(0,10,0));

    lightTn->AddNode(pln);
    root->AddNode(lightTn);


    // Shapes

    ShapeNode *sn1 = new ShapeNode(new Shapes::Sphere(Vector<3,float>(20,10,-100), 15));
    sn1->shape->mat->diffuse = Vector<4,float>(1.0,0,0,1.0);
    sn1->shape->mat->specular = Vector<4,float>(1);
    sn1->shape->mat->shininess = 20;
    sn1->shape->reflection = 1.0;
    root->AddNode(sn1);

    ShapeNode *sn3 = new ShapeNode(new Shapes::Sphere(Vector<3,float>(-20,10,-100), 15));
    sn3->shape->mat->diffuse = Vector<4,float>(0,0,1.0,1.0);
    sn3->shape->reflection = .5;
    root->AddNode(sn3);

    // ShapeNode *sn3 = new ShapeNode(new Shapes::Ellipsoid(Vector<3,float>(0,0,0),
    //                                                      Vector<3,float>(1,1.0,,1)));
    // sn3->shape->mat->diffuse = Vector<4,float>(0,0,1.0,1.0);
    // sn3->shape->reflection = .5;
    // root->AddNode(sn3);


    ShapeNode *sn4 = new ShapeNode(new Shapes::Sphere(Vector<3,float>(0,10,-80), 15));
    sn4->shape->mat->diffuse = Vector<4,float>(0.005);
    sn4->shape->mat->specular = Vector<4,float>(1);
    sn4->shape->mat->shininess = 30;
    sn4->shape->transparent = true;
    sn4->shape->refraction = 2.42;
    sn4->shape->reflection = 0.2;
    
    root->AddNode(sn4);



    TransformationNode *tn2 = new TransformationNode();
    tn2->Move(0,-10,0);
    ShapeNode *sn2 = new ShapeNode(new Shapes::Plane(Vector<3,float>(0,-10,0),
                                                     Vector<3,float>(0,-10,1),
                                                     Vector<3,float>(1,-10,0)));
    tn2->AddNode(sn2);
    root->AddNode(tn2);




    config.traceTex = EmptyTextureResource::Create(800,600,24);
    config.traceTex->SetMipmapping(false);
    
    config.traceTex->Load();
    config.textureLoader->Load(config.traceTex, TextureLoader::RELOAD_QUEUED);

    //config.ms->SetScene(config.scene);
    config.textureLoader->Load(*config.scene);

    HUD::Surface *rtHud = config.hud->CreateSurface(config.traceTex);
    rtHud->SetPosition(HUD::Surface::LEFT,
                       HUD::Surface::TOP);
    //rtHud->SetScale(2.0,2.0);



    // Supply the scene to the renderer
    config.canvas->SetScene(config.scene);
    

    //config.textureLoader->SetDefaultReloadPolicy(OpenEngine::Renderers::TextureLoader::RELOAD_NEVER);
}