Esempio n. 1
0
inline Core::Transform assimpToCore( const aiVector3D&    T,
                                     const aiQuaternion& R,
                                     const aiVector3D&    S ) {
    Core::Vector3    t = assimpToCore( T );
    Core::Quaternion r = assimpToCore( R );
    Core::Vector3    s = assimpToCore( S );
    Core::Transform M;
    M.fromPositionOrientationScale( t, r, s );
    return M;
}
Esempio n. 2
0
ParentCommand::ParentCommand(const HierarchyNodePtr& child, const HierarchyNodePtr& parent)
{
  m_Node = child;
  m_NextParent = parent;
  m_PreviousParent = child->GetParent();

  m_Node->SetParent( m_NextParent.Ptr() );

  Core::Transform* transform = Reflect::ObjectCast< Core::Transform >( m_Node );
  if ( transform )
  {
    Push( transform->ComputeObjectComponents() );
  }
}
Esempio n. 3
0
        bool RadiumEngine::loadFile( const std::string& filename )
        {
            //for ( auto& system : m_systems )
            //{
            //    system.second->handleFileLoading( file );
            //}
            
            // Fill file in a string (http://stackoverflow.com/a/2602060)
            std::ifstream t(filename);
            std::string file;

            t.seekg(0, std::ios::end);
            file.reserve(t.tellg());
            t.seekg(0, std::ios::beg);

            file.assign( ( std::istreambuf_iterator<char>( t ) ),
                         ( std::istreambuf_iterator<char>() ) );
            std::string err;

            std::vector<LoadedEntity> loadedData;
            Parser::parse(file, loadedData);

            LOG(logDEBUG) << "Found " << loadedData.size() << " entities to load.";

            std::string rootFolder = Core::StringUtils::getDirName( filename );

            for (const auto& entityData : loadedData)
            {
                Entity* entity = m_entityManager->getOrCreateEntity(entityData.name);
                Core::Transform transform;
                transform.fromPositionOrientationScale(entityData.position, entityData.orientation, entityData.scale);
                entity->setTransform(transform);

                for (const auto& systemData : entityData.data)
                {
                    auto system = m_systems.find(systemData.system);
                    
                    if (system != m_systems.end())
                    {
                        system->second->handleDataLoading(entity, rootFolder, systemData.data);
                    }
                }
            }

            return true;
        }
Esempio n. 4
0
        void RotateGizmo::updateTransform(const Core::Transform& worldTo, const Core::Transform& t)
        {
            m_worldTo = worldTo;
            m_transform = t;
            Core::Transform displayTransform = Core::Transform::Identity();
            if (m_mode == LOCAL)
            {
                displayTransform = m_transform;
            }
            else
            {
                displayTransform.translate(m_transform.translation());
            }

            for (auto roIdx : m_renderObjects)
            {
                Engine::RadiumEngine::getInstance()->getRenderObjectManager()->getRenderObject(
                        roIdx)->setLocalTransform(m_worldTo * displayTransform);
            }
        }
Esempio n. 5
0
void Enco3D::Rendering::Mesh::renderErrorMesh(Rendering::Shader *shader, Core::Transform *transform, const Component::Camera *camera, Rendering::RenderingEngine *renderingEngine)
{
	static bool initializedMeshAndMaterial = false;
	static Mesh errorMesh;
	static Material errorMaterial;

	if (!initializedMeshAndMaterial)
	{
		initializedMeshAndMaterial = true;

		Vertex vertices[8] =
		{
			Vertex(-1, -1, 0).setTexCoord(1, 1, 0).setNormal(0, 0, +1),
			Vertex(+1, -1, 0).setTexCoord(0, 1, 0).setNormal(0, 0, +1),
			Vertex(+1, +1, 0).setTexCoord(0, 0, 0).setNormal(0, 0, +1),
			Vertex(-1, +1, 0).setTexCoord(1, 0, 0).setNormal(0, 0, +1),

			Vertex(+1, -1, 0).setTexCoord(1, 1, 0).setNormal(0, 0, -1),
			Vertex(-1, -1, 0).setTexCoord(0, 1, 0).setNormal(0, 0, -1),
			Vertex(-1, +1, 0).setTexCoord(0, 0, 0).setNormal(0, 0, -1),
			Vertex(+1, +1, 0).setTexCoord(1, 0, 0).setNormal(0, 0, -1),
		};

		unsigned int indices[12] =
		{
			0, 1, 2, 0, 2, 3,
			4, 5, 6, 4, 6, 7,
		};

		errorMesh = Mesh(vertices, 8, indices, 12);

		errorMaterial.addTexture2D("diffuseTexture", new Texture2D("texture/error.png", TextureFilter::Linear));
		errorMaterial.addVector3f("diffuseColor", Core::Color3Template::White);
		errorMaterial.addFloat("specularIntensity", 0.0f);
		errorMaterial.addFloat("specularExponent", 1.0f);
	}

	Core::Transform billboardTransform;
	billboardTransform.setTranslation(transform->getTranslation());
	billboardTransform.setScaling(transform->getScaling());
	billboardTransform.setBillboardEnabled(true);
	billboardTransform.setBillboardCamera((Component::Camera*)camera);

	billboardTransform.update();

	shader->bind();
	shader->updateUniforms(&billboardTransform, camera, renderingEngine, errorMaterial);

	errorMesh.render();
}
Esempio n. 6
0
void Lux::Graphics::RenderingSystem::RenderPass()
{
	if (!m_LightEntry || !m_MainCamera || !m_MainCameraTransform)
		return;

	// Resize Window if needed
	if (m_RenderWindow->IsWindowResized())
	{
		float aspect = m_RenderWindow->GetWidth() / (float)m_RenderWindow->GetHeight();
		m_MainCamera->GetRawPtr()->ChangeAspect(aspect);
	}
	
	m_MainCameraTransform->GetRawPtr()->ApplyTransform();
	EntityMap::iterator it;
	for (it = m_EntityMap.begin(); it != m_EntityMap.end(); ++it)
	{
		if (!it->second.m_Transform)
			continue;

		if (!it->second.m_MeshRenderer)
			continue;

		Core::Mesh* mesh = it->second.m_MeshRenderer->GetRawPtr()->GetMesh().get();
		
		if (!mesh)
			continue;

		// Make sure we multiply the transforms properly, taking into account parents
		mat4x4 finalTransform;
		Core::Transform* transformPtr = it->second.m_Transform->GetRawPtr();
		bool hasParent = true;
		do 
		{
			hasParent = transformPtr->GetParentTransform().IsValid();
			transformPtr->ApplyTransform();
			finalTransform *= transformPtr->GetMatrix();
			transformPtr = transformPtr->GetParentTransform().GetRawPtr();

		} while (hasParent);

		// Set the default uniform buffer
		Core::ShaderVariable worldMatVal(Core::VALUE_MAT4X4, glm::value_ptr(finalTransform), sizeof(mat4));
		Core::ShaderVariable viewMatVal(Core::VALUE_MAT4X4, glm::value_ptr(m_MainCameraTransform->GetRawPtr()->GetInverseTranslationMatrix()), sizeof(mat4));
		Core::ShaderVariable projMatVal(Core::VALUE_MAT4X4, glm::value_ptr(m_MainCamera->GetRawPtr()->GetProjectionMatrix()), sizeof(mat4));
		m_ObjUniformBuffer.SetVariable(0, viewMatVal);
		m_ObjUniformBuffer.SetVariable(1, projMatVal);
		m_ObjUniformBuffer.SetVariable(2, worldMatVal);

		// Light Buffer
		LightShaderResource lightShaderRes;
		lightShaderRes.m_Position = m_LightEntry->m_Transform->GetRawPtr()->GetPosition();
		lightShaderRes.m_Color = m_LightEntry->m_Light->GetRawPtr()->GetColor();
		lightShaderRes.m_Direction = m_LightEntry->m_Light->GetRawPtr()->GetDirection();
		lightShaderRes.m_Intensity = m_LightEntry->m_Light->GetRawPtr()->GetIntensity();
		//lightShaderRes.m_Type = (int)m_LightEntry->m_Light->GetRawPtr()->GetType();
		Core::ShaderVariable lightShaderVar(Core::VALUE_STRUCT, &lightShaderRes, sizeof(LightShaderResource));
		Core::ShaderVariable eyePos(Core::VALUE_VEC3, glm::value_ptr(m_MainCameraTransform->GetRawPtr()->GetPosition()), sizeof(vec3));

		m_LightUniformBuffer.SetVariable(0, lightShaderVar);
		m_LightUniformBuffer.SetVariable(1, eyePos);
		Core::Shader* shader = mesh->GetShader().get();
		shader->Activate();

		// Material Buffer
		Core::Material* matRes = mesh->GetMaterialProperties().get();
		MaterialShaderResource matShaderRes(*matRes);
		Core::ShaderVariable matShader(Core::VALUE_STRUCT, &matShaderRes, sizeof(MaterialShaderResource));
		m_MatUniformBuffer.SetVariable(0, matShader);

		if (!it->second.m_Init)
		{
			shader->InitializeUniformBuffer("ObjectBuffer", m_ObjUniformBuffer, VERTEX_PROGRAM);
			shader->InitializeUniformBuffer("LightBuffer", m_LightUniformBuffer, FRAGMENT_PROGRAM);
			shader->InitializeUniformBuffer("MaterialBuffer", m_MatUniformBuffer, FRAGMENT_PROGRAM);
			it->second.m_Init = true;
		}
		
		// Bind Samplers and Textures
		Core::Texture2D* diffuseTex = mesh->GetTexture(Core::DIFFUSE_MAP_IDX).get();
		LuxAssert(diffuseTex);

		Core::TextureSampler* texSampler = diffuseTex->GetSampler().get();
		LuxAssert(texSampler);

		texSampler->Activate(Core::DIFFUSE_MAP_IDX, FRAGMENT_PROGRAM);
		diffuseTex->Bind(Core::DIFFUSE_MAP_IDX, "DiffuseTexture", shader, FRAGMENT_PROGRAM);

		shader->Update();

		mesh->PreRender();
		m_RenderWindow->Render(mesh);
		mesh->PostRender();

		diffuseTex->Unbind();
		texSampler->Deactivate();
		shader->Deactivate();
	}
}