示例#1
0
void QEmitterNode::setMaxCount(unsigned int value)
{
    if (signalsBlocked())
    {
        m_xmlNode.setAttribute("maxCount", value);
        h3dSetNodeParamI(m_hordeID, H3DEmitter::MaxCountI, value);
    }
    else if (value != QEmitterNode::maxCount())
        m_model->undoStack()->push(new QXmlNodePropertyCommand(tr("Set Max Count"), this, "Max_Count", value, EmitterMaxCountID));

}
void QTerrainNode::setMaterial(const Material& material)
{
	if (signalsBlocked())
	{
		m_xmlNode.setAttribute("material", material.FileName);
		h3dRemoveResource(m_materialID);
		m_materialID = h3dAddResource( H3DResTypes::Material, qPrintable(material.FileName), 0 );		
		h3dutLoadResourcesFromDisk(".");
		h3dSetNodeParamI(m_hordeID, H3DEXTTerrain::MatResI, m_materialID);
	}
	else if (material != QTerrainNode::material())
		m_model->undoStack()->push(new QXmlNodePropertyCommand("Set Material", this, "Material", QVariant::fromValue(material), TerrainMaterialID));
}
void QTerrainNode::setHeightMap(const Texture& heightMap)
{
	if (signalsBlocked())
	{
		m_xmlNode.setAttribute("heightmap", heightMap.FileName);
		h3dRemoveResource(m_heightMapID);
		m_heightMapID = h3dAddResource( H3DResTypes::Texture, qPrintable(heightMap.FileName), 0 );		
		h3dutLoadResourcesFromDisk(".");
		h3dSetNodeParamI(m_hordeID, H3DEXTTerrain::HeightTexResI, m_heightMapID);
	}
	else if (heightMap != QTerrainNode::heightMap())
		m_model->undoStack()->push(new QXmlNodePropertyCommand("Set HeightMap", this, "HeightMap", QVariant::fromValue(heightMap), TerrainHeightMapID));	
}
void QEmitterNode::setEffect(const Effect& effect)
{
	if (signalsBlocked())
	{
		m_xmlNode.setAttribute("particleEffect", effect.FileName);
		if (m_effectResource != 0)
			h3dRemoveResource(m_effectResource);
		m_effectResource = h3dAddResource( H3DResTypes::ParticleEffect, qPrintable(effect.FileName), 0 );
		h3dutLoadResourcesFromDisk(".");
		h3dSetNodeParamI(m_hordeID, H3DEmitter::PartEffResI, m_effectResource);
	}
	else if (effect != QEmitterNode::effect())
		m_model->undoStack()->push(new QXmlNodePropertyCommand("Set Effect", this, "Effect", QVariant::fromValue(effect), EmitterMaterialID));
}
示例#5
0
void QEmitterNode::setMaterial(const Material& material)
{
    if (signalsBlocked())
    {
        m_xmlNode.setAttribute("material", material.FileName);
        if (m_matResource != 0)
            h3dRemoveResource(m_matResource);
        m_matResource = h3dAddResource( H3DResTypes::Material, qPrintable(material.FileName), 0 );
//        h3dutLoadResourcesFromDisk(".");
        SceneEditor::load_h3dres_from_file_qrc(".");
        h3dSetNodeParamI(m_hordeID, H3DEmitter::MatResI, m_matResource);
    }
    else if (material != QEmitterNode::material())
        m_model->undoStack()->push(new QXmlNodePropertyCommand("Set Material", this, "Material", QVariant::fromValue(material), EmitterMaterialID));
}
void QModelNode::addRepresentation()
{
	m_resourceID = h3dAddResource(H3DResTypes::Geometry, qPrintable(m_xmlNode.attribute("geometry")), 0);

	// Load resource immediately since a later call to loadResourceFromDisk results in a bad behaviour of the Horde3D engine
	QString resourceName = h3dutGetResourcePath(H3DResTypes::Geometry);
	if( !resourceName.isEmpty() && !resourceName.endsWith('/') && !resourceName.endsWith('\\'))
		resourceName += '/';
	resourceName += geometry();

	QFile file(QFileInfo(resourceName).absoluteFilePath());
	if (!file.open(QIODevice::ReadOnly))
		qWarning("Error opening resource %s (%s)", qPrintable(m_xmlNode.attribute("geometry")), qPrintable( QFileInfo(resourceName).absoluteFilePath() ));
	
	// Stupid return value, if false it can also be the case that the resource was loaded before instead of that their was an error
	h3dLoadResource(m_resourceID, file.readAll().constData(), file.size());
	file.close();

	QSceneNode* parentNode = static_cast<QSceneNode*>(parent());
	unsigned int rootID = parentNode ? parentNode->hordeId() : H3DRootNode;

	m_hordeID = h3dAddModelNode(rootID, qPrintable(m_xmlNode.attribute("name", "ATTENTION No Node Name")), m_resourceID);
	
	float x, y, z, rx, ry, rz, sx, sy, sz;
	getTransformation(x,y,z,rx,ry,rz,sx,sy,sz);
	h3dSetNodeTransform(m_hordeID, x, y, z, rx, ry, rz, sx, sy, sz);
	
	h3dSetNodeParamI(m_hordeID, H3DModel::SWSkinningI, softwareSkinning());
	h3dSetNodeParamF(m_hordeID, H3DModel::LodDist1F, 0, lodDist1());
	h3dSetNodeParamF(m_hordeID, H3DModel::LodDist2F, 0, lodDist2());
	h3dSetNodeParamF(m_hordeID, H3DModel::LodDist3F, 0, lodDist3());
	h3dSetNodeParamF(m_hordeID, H3DModel::LodDist4F, 0, lodDist4());

	// Attachment
	QDomElement attachment = m_xmlNode.firstChildElement("Attachment");	
	SceneTreeModel* model = static_cast<SceneTreeModel*>(m_model);
	AttachmentPlugIn* plugIn = model->nodeFactory()->attachmentPlugIn();
	if (!attachment.isNull() &&  plugIn != 0)
		plugIn->initNodeAttachment(this);
}
void QTerrainNode::addRepresentation()
{
	m_heightMapID = h3dAddResource(
		H3DResTypes::Texture, 
		qPrintable(m_xmlNode.attribute("heightmap")), 
		H3DResFlags::NoTexCompression | H3DResFlags::NoTexMipmaps );
	m_materialID = h3dAddResource(H3DResTypes::Material, qPrintable(m_xmlNode.attribute("material")), 0);
	// Load resource immediately since a later call to loadResourceFromDisk results in a bad behaviour of the Horde3D engine
	QDir textureDir( QDir::current() );
	QFile file(textureDir.absoluteFilePath(m_xmlNode.attribute("heightmap")));
	if (!file.open(QIODevice::ReadOnly))
		qWarning("Error opening resource %s", qPrintable(m_xmlNode.attribute("heightmap")));
	
	// Stupid return value, if false it can also be the case that the resource was loaded before instead of that their was an error
	h3dLoadResource(m_heightMapID, file.readAll().constData(), file.size());
	file.close();

	QSceneNode* parentNode = static_cast<QSceneNode*>(parent());
	unsigned int rootID = parentNode ? parentNode->hordeId() : H3DRootNode;

	m_hordeID = h3dextAddTerrainNode(rootID, qPrintable(m_xmlNode.attribute("name", "ATTENTION No Node Name")), m_heightMapID, m_materialID);
	h3dSetNodeParamI(m_hordeID, H3DEXTTerrain::BlockSizeI, blockSize());
	h3dSetNodeParamF(m_hordeID, H3DEXTTerrain::MeshQualityF, 0, meshQuality());
	h3dSetNodeParamF(m_hordeID, H3DEXTTerrain::SkirtHeightF, 0, skirtHeight());

	float x, y, z, rx, ry, rz, sx, sy, sz;
	getTransformation(x,y,z,rx,ry,rz,sx,sy,sz);
	h3dSetNodeTransform(m_hordeID, x, y, z, rx, ry, rz, sx, sy, sz);

	// Attachment		
	QDomElement attachment = m_xmlNode.firstChildElement("Attachment");	
	SceneTreeModel* model = static_cast<SceneTreeModel*>(m_model);
	AttachmentPlugIn* plugIn = model->nodeFactory()->attachmentPlugIn();
	if (!attachment.isNull() &&  plugIn != 0)
		plugIn->initNodeAttachment(this);
}
示例#8
0
文件: app.cpp 项目: dreamsxin/nawia
bool Application::init()
{	
	// Initialize engine and open default sound device
	if( !h3dInit() || !h3dOpenDevice( 0x0 ) )
	{	
		h3dutDumpMessages();
		return false;
	}

	// Set options
	h3dSetOption( H3DOptions::LoadTextures, 1 );
	h3dSetOption( H3DOptions::TexCompression, 0 );
	h3dSetOption( H3DOptions::FastAnimation, 0 );
	h3dSetOption( H3DOptions::MaxAnisotropy, 4 );
	h3dSetOption( H3DOptions::ShadowMapSize, 2048 );

	// Add resources
	// Pipelines
	_hdrPipeRes = h3dAddResource( H3DResTypes::Pipeline, "pipelines/hdr.pipeline.xml", 0 );
	_forwardPipeRes = h3dAddResource( H3DResTypes::Pipeline, "pipelines/forward.pipeline.xml", 0 );
	// Overlays
	_fontMatRes = h3dAddResource( H3DResTypes::Material, "overlays/font.material.xml", 0 );
	_panelMatRes = h3dAddResource( H3DResTypes::Material, "overlays/panel.material.xml", 0 );
	_logoMatRes = h3dAddResource( H3DResTypes::Material, "overlays/logo.material.xml", 0 );
	// Environment
	H3DRes floorRes = h3dAddResource( H3DResTypes::SceneGraph, "models/tiles/tiles.scene.xml", 0 );
	// Knight
	H3DRes speakerRes = h3dAddResource( H3DResTypes::SceneGraph, "models/speaker/speaker.scene.xml", 0 );
	// Music
	_soundRes = h3dAddResource( RST_SoundResource, "sounds/stringed_disco.ogg", 0 );

	// Load resources
	h3dutLoadResourcesFromDisk( _contentDir.c_str() );

	// Add scene nodes
	// Add camera
	_cam = h3dAddCameraNode( H3DRootNode, "Camera", _hdrPipeRes );
	//h3dSetNodeParamI( _cam, CameraNodeParams::OcclusionCulling, 1 );
	// Add listener to the camera
	H3DNode listener = h3dAddListenerNode( _cam, "Listener" );
	h3dSetActiveListener( listener );
	// Add floor
	H3DNode floor = h3dAddNodes( H3DRootNode, floorRes );
	h3dSetNodeTransform( floor, 0, -0.125, 0, 0, 0, 0, 1, 1, 1 );
	// Add the speakers
	H3DNode speaker1 = h3dAddNodes( H3DRootNode, speakerRes );
	h3dSetNodeTransform( speaker1, -2, 0, -2, 0, 215.0f, 0, 1, 1, 1 );
	H3DNode speaker2 = h3dAddNodes( H3DRootNode, speakerRes );
	h3dSetNodeTransform( speaker2, 2, 0, -2, 0, 145.0f, 0, 1, 1, 1 );
	// Add music to the speakers
	_sound1 = h3dAddSoundNode( speaker1, "Sound1", _soundRes );
	_sound2 = h3dAddSoundNode( speaker2, "Sound2", _soundRes );
	// Add light source
	_light = h3dAddLightNode( H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP" );
	h3dSetNodeTransform( _light, 0, 7, 0, -90, 0, 0, 1, 1, 1 );
	h3dSetNodeParamF( _light, H3DLight::RadiusF, 0, 30 );
	h3dSetNodeParamF( _light, H3DLight::FovF, 0, 90 );
	h3dSetNodeParamI( _light, H3DLight::ShadowMapCountI, 1 );
	h3dSetNodeParamF( _light, H3DLight::ShadowMapBiasF, 0, 0.01f );

	// Set the distance model
	h3dSetDistanceModel( _distanceModel );
	// Set the timer so the light immediately gets a random color
	_lightTimer = 1.0f;

	// Customize post processing effects
	H3DRes matRes = h3dFindResource( H3DResTypes::Material, "pipelines/postHDR.material.xml" );
	// hdrParams: exposure, brightpass threshold, brightpass offset (see shader for description)
	h3dSetMaterialUniform( matRes, "hdrParams", 2.0f, 0.6f, 0.08f, 0 );

	// Play the music
	h3dPlaySound( _sound1 );
	h3dPlaySound( _sound2 );

	return true;
}
示例#9
0
文件: app.cpp 项目: dreamsxin/nawia
void Application::keyPressEvent( int key )
{
	switch( key )
	{
	case '1':
		if( h3dIsSoundPlaying( _sound1 ) )
		{
			h3dPauseSound( _sound1 );
			h3dPauseSound( _sound2 );
		}
		else
		{
			h3dPlaySound( _sound1 );
			h3dPlaySound( _sound2 );
		}

		break;
	case '2':
		h3dRewindSound( _sound1 );
		h3dRewindSound( _sound2 );

		break;
	case '7':
		_soundLoop = !_soundLoop;

		h3dSetNodeParamI( _sound1, H3DSoundNodeParams::Loop, _soundLoop ? 1 : 0 );
		h3dSetNodeParamI( _sound2, H3DSoundNodeParams::Loop, _soundLoop ? 1 : 0 );
		break;
	case '8':
		// Rotate between the distance models
		switch( _distanceModel )
		{
		case H3DDistanceModels::None:
			_distanceModel = H3DDistanceModels::InverseDistance;
			break;
		case H3DDistanceModels::InverseDistance:
			_distanceModel = H3DDistanceModels::InverseDistanceClamped;
			break;
		case H3DDistanceModels::InverseDistanceClamped:
			_distanceModel = H3DDistanceModels::LinearDistance;
			break;
		case H3DDistanceModels::LinearDistance:
			_distanceModel = H3DDistanceModels::LinearDistanceClamped;
			break;
		case H3DDistanceModels::LinearDistanceClamped:
			_distanceModel = H3DDistanceModels::ExponentDistance;
			break;
		case H3DDistanceModels::ExponentDistance:
			_distanceModel = H3DDistanceModels::ExponentDistanceClamped;
			break;
		case H3DDistanceModels::ExponentDistanceClamped:
			_distanceModel = H3DDistanceModels::None;
			break;
		}

		h3dSetDistanceModel( _distanceModel );
		break;
	case GLFW_KEY_F3:
		if( h3dGetNodeParamI( _cam, H3DCamera::PipeResI ) == _hdrPipeRes )
			h3dSetNodeParamI( _cam, H3DCamera::PipeResI, _forwardPipeRes );
		else
			h3dSetNodeParamI( _cam, H3DCamera::PipeResI, _hdrPipeRes );

		break;
	case GLFW_KEY_F7:
		_debugViewMode = !_debugViewMode;
		h3dSetOption( H3DOptions::DebugViewMode, _debugViewMode ? 1.0f : 0.0f );
		break;
	case GLFW_KEY_F8:
		_wireframeMode = !_wireframeMode;
		h3dSetOption( H3DOptions::WireframeMode, _wireframeMode ? 1.0f : 0.0f );
		break;
	case GLFW_KEY_F6:
		_statMode += 1;

		if( _statMode > H3DUTMaxStatMode )
			_statMode = 0;

		break;
	}
}
示例#10
0
bool TentacleApplication::init()
{
  // Initialize engine
  if( !h3dInit() )
  {
    h3dutDumpMessages();
    return false;
  }

	// Set options
	h3dSetOption( H3DOptions::LoadTextures, 1 );
	h3dSetOption( H3DOptions::TexCompression, 0 );
	h3dSetOption( H3DOptions::MaxAnisotropy, 4 );
	h3dSetOption( H3DOptions::ShadowMapSize, 2048 );
	h3dSetOption( H3DOptions::FastAnimation, 1 );

  // Add resources
  // Pipelines
  _hdrPipeRes = h3dAddResource( H3DResTypes::Pipeline, "pipelines/hdr.pipeline.xml", 0 );
  _forwardPipeRes = h3dAddResource( H3DResTypes::Pipeline, "pipelines/forward.pipeline.xml", 0 );
  // Font
  _fontMatRes = h3dAddResource( H3DResTypes::Material, "overlays/font.material.xml", 0 );
  // Logo
  _logoMatRes = h3dAddResource( H3DResTypes::Material, "overlays/logo.material.xml", 0 );
  // invJacXpl
  //_invJacMatRes = h3dAddResource( H3DResTypes::Material, "materials/invJac.material.xml", 0 );
  // Environment
  H3DRes envRes = h3dAddResource( H3DResTypes::SceneGraph, "models/sphere/sphere.scene.xml", 0 );
  // Tentacle
  H3DRes tentacleRes = h3dAddResource( H3DResTypes::SceneGraph, "models/tentacle.scene.xml", 0 );
  // Fly
  H3DRes flyRes = h3dAddResource( H3DResTypes::SceneGraph, "models/fly.scene.xml", 0 );

  _dx = _dy = _dz = 0;

  // Load resources
  h3dutLoadResourcesFromDisk( _contentDir.c_str() );

  // Add scene nodes
  // Add camera
  _cam = h3dAddCameraNode( H3DRootNode, "Camera", _forwardPipeRes );
  // Add environment
  H3DNode env = h3dAddNodes( H3DRootNode, envRes );
  h3dSetNodeTransform( env, 0, -20, 0, 0, 0, 0, 20, 20, 20 );

  // Add tentacle node
  _tentacle = h3dAddNodes( H3DRootNode, tentacleRes );
  h3dSetNodeTransform( _tentacle, 0, 0, 0, 0, 0, 0.0, 1.0f, 1.0f, 1.0f );

  // Create tentacle kinematic chain
  _tentacleIK = setUpKinematikChain(_tentacle);
  //cout << _tentacleIK->getEndPosition(_tentacleIK->getNumJoints()-1);
  //_ikCCDSolver = new SmrCCDSolver(_tentacleIK);
  //_ikCCDSolver->addConstraintPtr(_ikConstraint);

  _ikGSMMSolver = new SMRGSMMSolver(_tentacleIK);
  _ikGSMMSolver->addConstraintPtr(_ikConstraint);

  _ikInvJacSolver = new SMRInvJacSolver(_tentacleIK);
  _ikInvJacSolver->addConstraintPtr(_ikConstraint);

  //delete(_tentacleIK);

  _currentSolver = _ikInvJacSolver;
  _ikMethodString = "J pseudo-inverse";

  // Add fly node
  _fly = h3dAddNodes( H3DRootNode, flyRes );
  h3dSetNodeTransform( _fly, 0, 4, 0, 0, 0, 0, 0.2f, 0.2f, 0.2f );

  // Add light source
  H3DNode light = h3dAddLightNode( H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP" );
  h3dSetNodeTransform( light, 0, 15, 10, -60, 0, 0, 1, 1, 1 );
  h3dSetNodeParamF( light, H3DLight::RadiusF,0, 30 );
  h3dSetNodeParamF( light, H3DLight::FovF,0, 90 );
  h3dSetNodeParamI( light, H3DLight::ShadowMapCountI, 0 );
  h3dSetNodeParamF( light, H3DLight::ShadowMapBiasF,0, 0.01f );
  h3dSetNodeParamF( light, H3DLight::ColorF3,0, 1.0f );
  h3dSetNodeParamF( light, H3DLight::ColorF3,1, 0.8f );
  h3dSetNodeParamF( light, H3DLight::ColorF3,2, 0.7f );

  // Customize post processing effects
	H3DNode matRes = h3dFindResource( H3DResTypes::Material, "pipelines/postHDR.material.xml" );

  //hdrParams: exposure, brightpass threshold, brightpass offset (see shader for description)
	h3dSetMaterialUniform( matRes, "hdrParams", 2.5f, 0.5f, 0.08f, 0 );

  return true;
}