SceneNode* ParticlesEditorSceneModelHelper::PreprocessSceneNode(SceneNode* rawNode) { // There is one and only preprocessing case - if the "raw" node is "orphaned" Particles Emitter // (without the ParticlesEffectNode parent), we'll create the new Particles Effect node and // move the raw Emitter node to it. ParticleEmitter * emitter = GetEmitter(rawNode); if (!emitter) { return rawNode; } //ParticleEmitterNode* emitterNode = static_cast<ParticleEmitterNode*>(rawNode); //emitterNode->SetEmitter(emitterComponent->GetParticleEmitter()); SceneNode* curParentNode = rawNode->GetParent(); ParticleEffectComponent * effectComponent = cast_if_equal<ParticleEffectComponent*>(curParentNode->GetComponent(Component::PARTICLE_EFFECT_COMPONENT)); // If the Emitter Node has parent, but its parent is not ParticleEffectNode, we need to // "adopt" this node by creating ParticleEffect node and attaching. if (curParentNode && (effectComponent == NULL)) { SceneNode* newParentNodeParticleEffect = CreateParticleEffectNode(); curParentNode->AddNode(newParentNodeParticleEffect); // Add the emitter node to the new Effect (this will also remove it from the scene). newParentNodeParticleEffect->AddNode(rawNode); // Register the Particle Editor structure for the new node. EffectParticleEditorNode* effectEditorNode = ParticlesEditorController::Instance()->RegisterParticleEffectNode(newParentNodeParticleEffect); EmitterParticleEditorNode* emitterEditorNode = new EmitterParticleEditorNode(newParentNodeParticleEffect, rawNode, QString::fromStdString(rawNode->GetName())); effectEditorNode->AddChildNode(emitterEditorNode); return newParentNodeParticleEffect; } // No preprocessing needed. return rawNode; }
void test_scene_write(IArchiveWriter& w) { SceneNode* node = new SceneNode(); SceneNode* n1 = new SceneNode(); SceneNode* n2 = new SceneNode(); SceneNode* n3 = new SceneNode(); TransformationNode* tn = new TransformationNode(); tn->SetPosition(Vector<3,float>(1,2,3)); node->AddNode(n1); node->AddNode(n2); n1->AddNode(n3); n3->AddNode(tn); w.WriteScene("root", node); delete node; }
/** * Setup handler. * * This is the main setup method of the game factory. Here you can add * any non-standard modules and perform other setup tasks prior to the * engine start up. * * @param engine The game engine instance. */ bool GameFactory::SetupEngine(IGameEngine& engine) { #define ParticleType BillBoardParticle<EnergyParticle<DirectionParticle<IParticle> > > #define GroupType EnergyParticleGroup<ParticleType > DirectoryManager::AppendPath("./projects/PatSys/data/"); DirectoryManager::AppendPath("./projects/LegoTest/data/"); DirectoryManager::AppendPath("./projects/LegoTest/data/ldraw/parts/"); DirectoryManager::AppendPath("./projects/LegoTest/data/ldraw/p/"); DirectoryManager::AppendPath("./projects/LegoTest/data/ldraw/models/"); ResourceManager<ITextureResource>::AddPlugin(new TGAPlugin()); ResourceManager<IModelResource>::AddPlugin(new OBJPlugin()); ResourceManager<IModelResource>::AddPlugin(new LDRAWPlugin()); // Add your mouse and keyboard module here SDLInput* input = new SDLInput(); DownCameraEventHandler* cameraHandler = new DownCameraEventHandler(camera, this); cameraHandler->BindToEventSystem(); engine.AddModule(*input); engine.AddModule(*cameraHandler); // Create a root scene node SceneNode* scene = new SceneNode(); PropertyList* pSimple = new PropertyList("levels/simple.lvl"); CustomLevel* level = new CustomLevel(*pSimple); level->Load(); //SceneNode* physNode = level->GetPhysicsGraph(); SceneNode* staticScene = level->GetSceneGraph(); scene->AddNode(staticScene); TransformationNode* lightTrans = new TransformationNode(); PointLightNode* pl = new PointLightNode(); pl->ambient = Vector<4,float>(0,0,0,1); pl->diffuse = Vector<4,float>(1,1,1,1); pl->specular = Vector<4,float>(0,0,0,1); lightTrans->AddNode(pl); lightTrans->Move(0,10,0); scene->AddNode(lightTrans); IModelResourcePtr res = ResourceManager<IModelResource>::Create("car.dat"); res->Load(); TransformationNode* tnode = new TransformationNode(); tnode->Scale(.5, .5, .5); tnode->Move(0,-20,0); tnode->AddNode(res->GetSceneNode()); res->Unload(); scene->AddNode(tnode); // Supply the scene to the renderer this->renderer->SetSceneRoot(scene); QuitHandler* quit_h = new QuitHandler(); quit_h->BindToEventSystem(); // Add some module engine.AddModule(*(new OpenEngine::Utils::Statistics(1000))); // Return true to signal success. return true; }
static bool LoadWheel( const PTree & cfg_wheel, struct LoadDrawable & loadDrawable, SceneNode & topnode, std::ostream & error_output) { SceneNode::Handle wheelnode = topnode.AddNode(); ContentManager & content = loadDrawable.content; const std::string& path = loadDrawable.path; std::string meshname; std::vector<std::string> texname; std::shared_ptr<Model> mesh; const PTree * cfg_tire; Vec3 size(0); std::string sizestr; if (!cfg_wheel.get("mesh", meshname, error_output)) return false; if (!cfg_wheel.get("texture", texname, error_output)) return false; if (!cfg_wheel.get("tire", cfg_tire, error_output)) return false; if (!cfg_tire->get("size", sizestr, error_output)) return false; if (!cfg_tire->get("size", size, error_output)) return false; // load wheel bool genrim = true; cfg_wheel.get("genrim", genrim); if (genrim) { // get wheel disk mesh content.load(mesh, path, meshname); // gen wheel mesh meshname = meshname + sizestr; if (!content.get(mesh, path, meshname)) { float width = size[0] * 0.001; float diameter = size[2] * 0.0254; VertexArray rimva, diskva; MeshGen::mg_rim(rimva, size[0], size[1], size[2], 10); diskva = mesh->GetVertexArray(); diskva.Translate(-0.75 * 0.5, 0, 0); diskva.Scale(width, diameter, diameter); content.load(mesh, path, meshname, rimva + diskva); } } if (!loadDrawable(meshname, texname, cfg_wheel, topnode, &wheelnode)) { return false; } // load tire (optional) texname.clear(); if (cfg_tire->get("texture", texname)) { meshname.clear(); if (!cfg_tire->get("mesh", meshname)) { // gen tire mesh meshname = "tire" + sizestr; if (!content.get(mesh, path, meshname)) { VertexArray tireva; MeshGen::mg_tire(tireva, size[0], size[1], size[2]); content.load(mesh, path, meshname, tireva); } } if (!loadDrawable(meshname, texname, *cfg_tire, topnode.GetNode(wheelnode))) { return false; } } // load brake (optional) texname.clear(); const PTree * cfg_brake; if (cfg_wheel.get("brake", cfg_brake, error_output) && cfg_brake->get("texture", texname)) { float radius; std::string radiusstr; cfg_brake->get("radius", radius); cfg_brake->get("radius", radiusstr); meshname.clear(); if (!cfg_brake->get("mesh", meshname)) { // gen brake disk mesh meshname = "brake" + radiusstr; if (!content.get(mesh, path, meshname)) { float diameter_mm = radius * 2 * 1000; float thickness_mm = 0.025 * 1000; VertexArray brakeva; MeshGen::mg_brake_rotor(brakeva, diameter_mm, thickness_mm); content.load(mesh, path, meshname, brakeva); } } if (!loadDrawable(meshname, texname, *cfg_brake, topnode.GetNode(wheelnode))) { return false; } } return true; }