예제 #1
0
파일: MeshViewApp.cpp 프로젝트: zulis/Imrod
void MeshViewApp::update()
{
	// Track the time
	float elapsed = (float) getElapsedSeconds() - m_time;
	m_time += elapsed;

	if (m_fileMonitorConfig->hasChanged())
	{
		loadConfig(m_configFileName, true);
	}

	if(m_fileMonitorVert->hasChanged() || m_fileMonitorFrag->hasChanged())
	{
		loadShader(m_shaderFileName);
	}

	if(m_rotateMesh)
	{
		float rotateAngle = elapsed * 0.2f;
		m_matrix.rotate(Vec3f::yAxis(), rotateAngle);
	}

	if(isInitialized())
	{
		m_assimpLoader.setTime(elapsed);
		m_assimpLoader.update();
	}
}
예제 #2
0
	Ptr<Mesh> Mesh::CreateMeshFromFile(const String& filePath)
	{
		auto exceptionManager = ExceptionManager::GetInstance();

		AssimpLoader loader;
		Ptr<Mesh> mesh = loader.Load(filePath);
		if (mesh == nullptr)
		{
			Ptr<Exception> exception = Ptr<Exception>::New((String)"加载模型文件" + filePath + "失败。原因是:\n"
				+ exceptionManager->GetException()->GetInfo());
			exceptionManager->PushException(exception);
			return nullptr;
		}
		return mesh;
	}
예제 #3
0
void TrackerRenderer::loadModels() {
  // Set up options
  Ogre::UnaryOptionList unOpt;
  Ogre::BinaryOptionList binOpt;

  unOpt["-q"] = false;
  unOpt["-3ds_ani_fix"] = false;
  unOpt["-3ds_dae_fix"] = false;
  unOpt["-shader"] = false;
  binOpt["-log"] = "ass.log";
  binOpt["-aniName"] = "";
  binOpt["-aniSpeedMod"] = 0.0f;
  binOpt["-l"] = "";
  binOpt["-v"] = "";
  binOpt["-s"] = "Distance";
  binOpt["-p"] = "";
  binOpt["-f"] = "";

  AssimpLoader::AssOptions opts;
  opts.quietMode = false;
  opts.logFile = "ass.log";
  opts.customAnimationName = "";
  opts.dest = "";
  opts.animationSpeedModifier = 1.0;
  opts.lodValue = 250000;
  opts.lodFixed = 0;
  opts.lodPercent = 20;
  opts.numLods = 0;
  opts.usePercent = true;
  opts.source =
      "/home/alessandro/projects/drone_ws/src/fato_tracker/data/ros_hydro/"
      "ros_hydro.obj";

  AssimpLoader loader;
  loader.convert(opts);

  std::cout << "assimp model loaded" << std::endl;
}
예제 #4
0
파일: MeshViewApp.cpp 프로젝트: zulis/Imrod
void MeshViewApp::setupCamera(bool inTheMiddleOfY)
{
	m_camera.setNearClip(0.1f);
	m_camera.setFarClip(10000.0f);
	AxisAlignedBox3f bbox = m_assimpLoader.getBoundingBox();
	Vec3f size = bbox.getSize();
	float max = size.x;
	max = max < size.y ? size.y : max;
	max = max < size.z ? size.z : max;

	if(inTheMiddleOfY)
	m_camera.setEyePoint(Vec3f(0.0f, size.y / 2, max * 2.0f));
	else
	m_camera.setEyePoint(Vec3f(0.0f, max, max * 2.0f));

	m_camera.setCenterOfInterestPoint(bbox.getCenter());
}
예제 #5
0
int main(int numargs, char** args)
{
    if (numargs < 2)
    {
        help();
        return -1;
    }

    // Assume success
	int retCode = 0;

    try
    {
        logMgr = new Ogre::LogManager();

        // this log catches output from the parseArgs call and routes it to stdout only
        logMgr->createLog("Temporary log", false, true, true);

        AssOptions opts = parseArgs(numargs, args);
        // use the log specified by the cmdline params
        logMgr->setDefaultLog(logMgr->createLog(opts.logFile, false, true));
        // get rid of the temporary log as we use the new log now
        logMgr->destroyLog("Temporary log");

        rgm = new Ogre::ResourceGroupManager();
        mth = new Ogre::Math();
        lodMgr = new Ogre::LodStrategyManager();
        meshMgr = new Ogre::MeshManager();
        matMgr = new Ogre::MaterialManager();
        matMgr->initialise();
        skelMgr = new Ogre::SkeletonManager();
        meshSerializer = new Ogre::MeshSerializer();
        //xmlMeshSerializer = new Ogre::XMLMeshSerializer();
        skeletonSerializer = new Ogre::SkeletonSerializer();
        //xmlSkeletonSerializer = new Ogre::XMLSkeletonSerializer();
        bufferManager = new Ogre::DefaultHardwareBufferManager(); // needed because we don't have a rendersystem
        scmgr = new Ogre::ScriptCompilerManager();
        archmgr = new Ogre::ArchiveManager();
        mfsarchf = new Ogre::FileSystemArchiveFactory();
        Ogre::ArchiveManager::getSingleton().addArchiveFactory( mfsarchf );

        if(opts.quietMode)
            opts.params |= AssimpLoader::LP_QUIET_MODE;

        AssimpLoader loader;
        loader.convert(opts.source, opts.customAnimationName, opts.params, opts.dest, opts.animationSpeedModifier);

    }
    catch(Ogre::Exception& e)
    {
        std::cerr << "FATAL ERROR: " << e.getDescription() << std::endl;
        std::cerr << "ABORTING!" << std::endl;
        retCode = 1;
    }

    //delete xmlSkeletonSerializer;
    delete skeletonSerializer;
    //delete xmlMeshSerializer;
    delete meshSerializer;
    delete skelMgr;
    delete matMgr;
    //delete meshMgr; FIX this!!
    delete bufferManager;
    delete scmgr;
    delete archmgr;
    delete mfsarchf;
    delete lodMgr;
    delete mth;
    delete rgm;
    delete logMgr;

    return retCode;

}
예제 #6
0
파일: MeshViewApp.cpp 프로젝트: zulis/Imrod
void MeshViewApp::draw()
{
	// Clear the window
	gl::clear();
	gl::color(Color::white());

	if(isInitialized())
	{
		// Get ready to draw in 3D
		gl::pushMatrices();
		gl::setMatrices(m_camera);

		gl::enableDepthRead();
		gl::enableDepthWrite();

		// Bind textures
		if(m_texDiffuse)
			m_texDiffuse->enableAndBind();

		if (m_texNormal)
			m_texNormal->bind(1);

		if (m_texSpecular)
			m_texSpecular->bind(2);

		if(m_texAO)
			m_texAO->bind(3);

		if(m_texEmissive)
			m_texEmissive->bind(4);

		// Bind shader
		m_shader->bind();
		m_shader->uniform("texDiffuse", 0);
		m_shader->uniform("texNormal", 1);
		m_shader->uniform("texSpecular", 2);
		m_shader->uniform("texAO", 3);
		m_shader->uniform("texEmissive", 4);
		m_shader->uniform("texDiffusePower", m_texDiffusePower);
		m_shader->uniform("texNormalPower", m_texNormalPower);
		m_shader->uniform("texSpecularPower", m_texSpecularPower);
		m_shader->uniform("texAOPower", m_texAOPower);
		m_shader->uniform("texEmissivePower", m_texEmissivePower);
		m_shader->uniform("diffuseEnabled", m_diffuseEnabled);
		m_shader->uniform("normalEnabled", m_normalEnabled);
		m_shader->uniform("specularEnabled", m_specularEnabled);
		m_shader->uniform("aoEnabled", m_aoEnabled);
		m_shader->uniform("emissiveEnabled", m_emissiveEnabled);

		m_shader->uniform("material.Ka", m_matAmbient);
		m_shader->uniform("material.Kd", m_matDiffuse);
		m_shader->uniform("material.Ks", m_matSpecular);
		m_shader->uniform("material.Shininess", m_matShininess);
		m_shader->uniform("gamma", m_gamma);

		// Enable lights
		m_light1->enable();
		m_light2->enable();

		// Render model
		gl::pushModelView();
		gl::multModelView(m_matrix);
		m_assimpLoader.draw();
		gl::popModelView();

		// Disable lights
		m_light1->disable();
		m_light2->disable();

		// Unbind shader
		m_shader->unbind();

		// Unbind textures
		gl::disable(m_texDiffuse->getTarget());

		// Disable 3D rendering
		gl::disableDepthWrite();
		gl::disableDepthRead();

		// Restore matrices
		gl::popMatrices();

		// Enable 2D rendering
		gl::setMatricesWindow(getWindowSize());
		gl::setViewport(getWindowBounds());

		// Render parameter window
		if(m_params)
			m_params->draw();
	}

	// Render debug information
	Debug::get().draw(ColorAf::white());
}
예제 #7
0
파일: MeshViewApp.cpp 프로젝트: zulis/Imrod
void MeshViewApp::loadConfig(const std::string& fileName, bool isReload)
{
	try
	{
		if (fs::exists(fileName))
			m_configFileName = fileName; 
		else
			m_configFileName = getAssetPath(fileName).string();

		m_fileMonitorConfig = FileMonitor::create(m_configFileName);

		Config cfg(m_configFileName);
		m_shaderFileName = cfg.getString("Shader", "FileName");
		loadShader(m_shaderFileName);

		if (!isReload)
		{
			m_assimpLoader = AssimpLoader(getAssetPath(cfg.getString("Model", "FileName")), false);
			m_assimpLoader.setAnimation(0);
			m_assimpLoader.enableTextures(false);
			m_assimpLoader.enableSkinning(false);
			m_assimpLoader.enableAnimation(false);
			m_assimpLoader.enableMaterials(false);
		}

		cfg.setSection("Textures");

		if(m_texDiffuse)
			m_texDiffuse = NULL;
		if (m_texNormal)
			m_texNormal = NULL;
		if (m_texSpecular)
			m_texSpecular = NULL;
		if(m_texAO)
			m_texAO = NULL;
		if(m_texEmissive)
			m_texEmissive = NULL;

		m_texDiffusePower = 1.0f;
		m_texNormalPower = 1.0f;
		m_texSpecularPower = 1.0f;
		m_texAOPower = 1.0f;
		m_texEmissivePower = 1.0f;

		m_diffuseEnabled = false;
		m_normalEnabled = false;
		m_specularEnabled = false;
		m_aoEnabled = false;
		m_emissiveEnabled = false;

		std::string diffuseFileName = cfg.getString("Diffuse");
		if(diffuseFileName != std::string())
		{
			m_texDiffuse = gl::Texture::create(loadImage(loadAsset(diffuseFileName)));
			m_texDiffusePower = cfg.getFloat("DiffusePower");
			m_diffuseEnabled = true;
		}

		std::string normalFileName = cfg.getString("Normal");
		if (normalFileName != std::string())
		{
			m_texNormal = gl::Texture::create(loadImage(loadAsset(normalFileName)));
			m_texNormalPower = cfg.getFloat("NormalPower");
			m_normalEnabled = true;
		}

		std::string specularFileName = cfg.getString("Specular");
		if (specularFileName != std::string())
		{
			m_texSpecular = gl::Texture::create(loadImage(loadAsset(specularFileName)));
			m_texSpecularPower = cfg.getFloat("SpecularPower");
			m_specularEnabled = true;
		}

		std::string aoFileName = cfg.getString("AO");
		if(aoFileName != std::string())
		{
			m_texAO = gl::Texture::create(loadImage(loadAsset(aoFileName)));
			m_texAOPower = cfg.getFloat("AOPower");
			m_aoEnabled = true;
		}

		std::string emissiveFileName = cfg.getString("Emissive");
		if(emissiveFileName != std::string())
		{
			m_texEmissive = gl::Texture::create(loadImage(loadAsset(emissiveFileName)));
			m_texEmissivePower = cfg.getFloat("EmissivePower");
			m_emissiveEnabled = true;
		}

		cfg.setSection("Material");
		m_matAmbient = cfg.getVec3f("Ambient");
		m_matDiffuse = cfg.getVec3f("Diffuse");
		m_matSpecular = cfg.getVec3f("Specular");
		m_matShininess = cfg.getFloat("Shininess");
		m_gamma = cfg.getFloat("Gamma");
	}
	catch(const std::exception& e)
	{
		console() << "Failed to load assets:" << std::endl;
		console() << e.what();
	}
}