コード例 #1
0
ファイル: GameManager.cpp プロジェクト: TheCodeInside/BowLand
// Creates a player
GameObject* GameManager::CreatePlayer( uint32_t index, const XMFLOAT3& position, const XMFLOAT3& scale )
{
    Scene* scene = Scene::GetInstance();
    GameObject* player = scene->AddGameObject( "Player_" + std::to_string( index ) );
    ID3D11Device* device = player->GetDevice();
    ID3D11DeviceContext* deviceContext = player->GetDeviceContext();

    // Set the player's transform info
    Transform* transform = player->GetTransform();
    transform->SetPosition( position );
    transform->SetScale( scale );

    // Add the collider to the player
    BoxCollider* collider = player->AddComponent<BoxCollider>();
    collider->SetSize( XMFLOAT3( 1, 1, 1 ) );

    // Add the rigid body to the player
    Rigidbody* rigidbody = player->AddComponent<Rigidbody>();
    rigidbody->SetMass( 0 );

    // Add the default material to the player
    DefaultMaterial* material = player->AddComponent<DefaultMaterial>();
    material->LoadDiffuseMap( "Textures\\Rocks2.jpg" );
    material->LoadNormalMap( "Textures\\Rocks2Normals.jpg" );
    material->SetDirectionalLight( StageLight );

    // Add the mesh renderer to the player
    MeshRenderer* meshRenderer = player->AddComponent<MeshRenderer>();
    meshRenderer->SetMaterial( material );
    meshRenderer->SetMesh( MeshLoader::Load( "Models\\cube.obj", device, deviceContext ) );

    return player;
}
コード例 #2
0
//-----------------------------------------------------------------------------------
void Path::Render() const
{
    MeshBuilder builder;
    builder.Begin();
    const float TILE_SIZE = 25.0f;
    for (PathNode* node : m_openList)
    {
        Vector2 bottomLeft = Vector2(node->position) * TILE_SIZE;
        builder.AddTexturedAABB(AABB2(bottomLeft, bottomLeft + (Vector2::ONE * TILE_SIZE)), Vector2::ZERO, Vector2::ONE, RGBA(0x0000FF7F));
        Renderer::instance->DrawText2D(bottomLeft, std::to_string(node->f).substr(0, 4), 0.5f, RGBA::WHITE, false, BitmapFont::CreateOrGetFontFromGlyphSheet("Runescape"));
    }
    for (PathNode* node : m_closedList)
    {
        Vector2 bottomLeft = Vector2(node->position) * TILE_SIZE;
        builder.AddTexturedAABB(AABB2(bottomLeft, bottomLeft + (Vector2::ONE * TILE_SIZE)), Vector2::ZERO, Vector2::ONE, RGBA(0xFF00007F));
        Renderer::instance->DrawText2D(bottomLeft, std::to_string(node->f).substr(0, 4), 0.5f, RGBA::WHITE, false, BitmapFont::CreateOrGetFontFromGlyphSheet("Runescape"));
    }
    for (PathNode* node : m_resultantPath)
    {
        Vector2 bottomLeft = Vector2(node->position) * TILE_SIZE;
        builder.AddTexturedAABB(AABB2(bottomLeft, bottomLeft + (Vector2::ONE * TILE_SIZE)), Vector2::ZERO, Vector2::ONE, RGBA(0x00FF007F));
    }

    Vector2 bottomLeft = (Vector2(m_currentGoal) * TILE_SIZE);
    builder.AddTexturedAABB(AABB2(bottomLeft, bottomLeft + (Vector2::ONE * TILE_SIZE)), Vector2::ZERO, Vector2::ONE, RGBA(0x00FF007F));
    
    builder.End();
    Mesh* mesh = new Mesh();
    builder.CopyToMesh(mesh, &Vertex_PCUTB::Copy, sizeof(Vertex_PCUTB), &Vertex_PCUTB::BindMeshToVAO);
    MeshRenderer* renderer = new MeshRenderer(mesh, Renderer::instance->m_defaultMaterial);
    renderer->Render();
    delete mesh;
}
コード例 #3
0
//-----------------------------------------------------------------------------------
void Renderer::DrawVertexArray(const Vertex_PCT* vertexes, int numVertexes, DrawMode drawMode /*= DrawMode::QUADS*/)
{
	if (numVertexes == 0)
	{
		return;
	}
	MeshBuilder builder;
	builder.Begin();
	for (int i = 0; i < numVertexes; ++i)
	{
		builder.SetColor(vertexes[i].color);
		builder.SetUV(vertexes[i].texCoords);
		builder.SetTBN(Vector3::ZERO, Vector3::ZERO, Vector3::ZERO);
		builder.AddVertex(vertexes[i].pos);
		builder.AddIndex(i);
	}
	builder.End();

	Mesh* mesh = new Mesh();
	builder.CopyToMesh(mesh, &Vertex_PCUTB::Copy, sizeof(Vertex_PCUTB), &Vertex_PCUTB::BindMeshToVAO);
	mesh->m_drawMode = drawMode;
	MeshRenderer* thingToRender = new MeshRenderer(mesh, m_defaultMaterial);
	m_defaultMaterial->SetMatrices(Matrix4x4::IDENTITY, m_viewStack.GetTop(), m_projStack.GetTop());
	GL_CHECK_ERROR();
	thingToRender->Render();
	delete mesh;
}
コード例 #4
0
//-----------------------------------------------------------------------------------
void Renderer::DrawText2D(const Vector2& position, const std::string& asciiText, float scale, const RGBA& tint /*= RGBA::WHITE*/, bool drawShadow /*= false*/, const BitmapFont* font /*= nullptr*/, const Vector2& right /*= Vector3::UNIT_X*/, const Vector2& up /*= Vector3::UNIT_Z*/)
{
	//To be used when I expand this method to 3D text
	UNUSED(up);
	UNUSED(right);
	if (asciiText.empty())
	{
		return;
	}
	if (font == nullptr)
	{
		font = m_defaultFont;
	}
	int stringLength = asciiText.size();
	Vector2 cursorPosition = position + (Vector2::UNIT_Y * (float)font->m_maxHeight * scale);
	const Glyph* previousGlyph = nullptr;
	MeshBuilder builder;
	builder.Begin();
	for (int i = 0; i < stringLength; i++)
	{
		unsigned char currentCharacter = asciiText[i];
		const Glyph* glyph = font->GetGlyph(currentCharacter);
		float glyphWidth = static_cast<float>(glyph->width) * scale;
		float glyphHeight = static_cast<float>(glyph->height) * scale;

		if (previousGlyph)
		{
			const Vector2 kerning = font->GetKerning(*previousGlyph, *glyph);
			cursorPosition += (kerning * scale);
		}
		Vector2 offset = Vector2(glyph->xOffset * scale, -glyph->yOffset * scale);
		Vector2 topRight = cursorPosition + offset + Vector2(glyphWidth, 0.0f);
		Vector2 bottomLeft = cursorPosition + offset - Vector2(0.0f, glyphHeight);
		AABB2 quadBounds = AABB2(bottomLeft, topRight);
		AABB2 glyphBounds = font->GetTexCoordsForGlyph(*glyph);
		if (drawShadow)
		{
			float shadowWidthOffset = glyphWidth / 10.0f;
			float shadowHeightOffset = glyphHeight / -10.0f;
			Vector2 shadowOffset = Vector2(shadowWidthOffset, shadowHeightOffset);
			AABB2 shadowBounds = AABB2(bottomLeft + shadowOffset, topRight + shadowOffset);
			builder.AddTexturedAABB(shadowBounds, glyphBounds.mins, glyphBounds.maxs, RGBA::BLACK);
		}
		builder.AddTexturedAABB(quadBounds, glyphBounds.mins, glyphBounds.maxs, tint);
		cursorPosition.x += glyph->xAdvance * scale;
		previousGlyph = glyph;
	}
	builder.End();

	Mesh* mesh = new Mesh();
	builder.CopyToMesh(mesh, &Vertex_PCUTB::Copy, sizeof(Vertex_PCUTB), &Vertex_PCUTB::BindMeshToVAO);
	mesh->m_drawMode = DrawMode::TRIANGLES;
	MeshRenderer* thingToRender = new MeshRenderer(mesh, font->GetMaterial());
	m_defaultMaterial->SetMatrices(Matrix4x4::IDENTITY, m_viewStack.GetTop(), m_projStack.GetTop());
	GL_CHECK_ERROR();
	thingToRender->Render();
	delete mesh;
	delete thingToRender;
}
コード例 #5
0
void SBrush::AddPatch(const SurfacePoint *pPoint, const Vector &vPatchCenter, float fSize, float fPressure, float fStrength, AxisAlignedBoundingBox &cDirtyWorldArea)
{
	if (!pPoint || !pPoint->Mesh())
		return;

	if (m_aMeshChanges.find(pPoint->Mesh()) == m_aMeshChanges.end())
	{
		// map a mesh to a meshchange;
		// this supports sculpting on multi meshes. 
		m_aMeshChanges[pPoint->Mesh()] = pPoint->Mesh()->StartChange();

		// 
		unsigned int i = 0;
		MeshRenderer *p;
		while ( p = ((const Mesh *)pPoint->Mesh())->ChildByClass<MeshRenderer>( i++ ) )
			m_aRenderers.push_back( p );
	}

	const unsigned int fIdx = pPoint->FaceIndex();
	QVector<unsigned int> vIndices;
	if (pPoint->Mesh()->Type() == Topology::typeQuadric)
	{
		for (unsigned int c = 0; c < 4; ++c)
		{
			const unsigned int vIdx = pPoint->Mesh()->QuadIndex(fIdx, c);  
			MeshChange::VertexChange &vc = m_aMeshChanges[pPoint->Mesh()]->Add(vIdx, fIdx);

			const Vector vOldPos = vc.m_vPosition;
			Vector vDelta = Vector(0, 10, 0);
			pPoint->Mesh()->VertexPosition(vIdx) = vOldPos + vDelta;

			vIndices.push_back(vIdx);
		}
	}
	else
	{
		for (unsigned int c = 0; c < 3; ++c)
		{
			const unsigned int vIdx = pPoint->Mesh()->TriangleIndex(fIdx, c); 
			MeshChange::VertexChange &vc = m_aMeshChanges[pPoint->Mesh()]->Add(vIdx, fIdx);

			const Vector vOldPos = vc.m_vPosition;
			Vector vDelta = Vector(0, 10, 0);
			pPoint->Mesh()->VertexPosition(vIdx) = vOldPos + vDelta;
			
			vIndices.push_back(vIdx);
		}
	} 

	// 
	for ( int r = 0; r < m_aRenderers.size(); r++ )
	{
		MeshRenderer *pR = m_aRenderers[r];
		for ( int i = 0; i < vIndices.size(); i++ )
			pR->OnVertexPositionChange( vIndices[i], fIdx );
	};
	Kernel()->ViewPort()->Redraw();
};
コード例 #6
0
ファイル: Exhaustion.cpp プロジェクト: mortennobel/PolyPlane
Exhaustion::Exhaustion(kick::GameObject *gameObject) : Component(gameObject) {
    MeshRenderer* mr = gameObject->addComponent<MeshRenderer>();
    Material *material = new Material();
    material->setShader(Project::loadShader("poly-assets/shaders/unlit_vertex_colored.shader"));
    mr->setMaterial(material);
    Mesh *mesh = new Mesh();

    mesh->setMeshData(loadPlyData("poly-assets/models","cloud.ply"));
    mr->setMesh(mesh);
}
コード例 #7
0
ファイル: StaticMesh.cpp プロジェクト: legersun/Novus-Engine
MeshRenderer<Vertex>* StaticMesh::AddMesh(std::vector<Vertex>& vertices, std::vector<unsigned int>& indices)
{
	MeshRenderer<novus::Vertex>* newMesh = NE_NEW MeshRenderer<novus::Vertex>();

	newMesh->Init(EngineStatics::getRenderer(), vertices, indices);

	mMeshes.push_back(newMesh);

	return newMesh;
}
コード例 #8
0
void SetDefaultMeshRenderer(MeshRenderer& meshRenderer){
	//meshRenderer = MeshRenderer();

	//meshRenderer.m_material = new Material();
	meshRenderer.SetDefaultMaterial();

	//meshRenderer.m_mesh = new Mesh();
	meshRenderer.m_mesh->SetDrawMode(GL_QUADS);

	meshRenderer.BindVertexArray();
}
コード例 #9
0
ファイル: Scene.cpp プロジェクト: ChoiYoungMin/Jaraffe
HRESULT Jaraffe::CScene::Init()
{
	// 1) Create MainCamera
	Camera* newCamera = new Camera();
	Camera::SetMainCamera(newCamera);

	GameObject* m_pMainCamera = GameObject::Create();
	m_pMainCamera->InsertComponent(new Transform);
	m_pMainCamera->InsertComponent(newCamera);

	m_pMainCamera->Init();

	// 2) Create Directional Light
	Jaraffe::Component::Light* pMainLight = new Jaraffe::Component::Light();
	auto plight = pMainLight->SetLightType(Jaraffe::Light::LightType::Directional);
	if (plight != nullptr)
	{
		auto cast = (Jaraffe::Light::DirectionalLight*)plight;
		cast->Ambient	= XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
		cast->Diffuse	= XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
		cast->Specular	= XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
		cast->Direction = XMFLOAT3(-0.707f, 0.0f, 0.707f);
	}

	GameObject* m_DirectionalLight = GameObject::Create();
	m_DirectionalLight->InsertComponent(new Transform);
	m_DirectionalLight->InsertComponent(pMainLight);

	//---- T E S T ----
	Jaraffe::Material* pMat = new Jaraffe::Material();
	Jaraffe::Texture* pTex = new Jaraffe::Texture();
	pTex->SetTexture(gTEXTUREMGR->CreateTexture(L"Resources/Textures/WoodCrate01.dds"));
	pMat->m_MainTexture = pTex;

	MeshRenderer* pMeshRenderer = new MeshRenderer();
	pMeshRenderer->SetMaterial(pMat);

	GameObject* m_pTestModel = GameObject::Create();
	m_pTestModel->InsertComponent(new Transform);
	m_pTestModel->InsertComponent(pMeshRenderer);
	m_pTestModel->InsertComponent(new Mesh);

	m_ObjectList.push_back(m_pTestModel);

	//---- E N D   ----

	// All GameObject Init
	for (size_t i = 0; i < m_ObjectList.size(); i++)
	{
		m_ObjectList[i]->Init();
	}

	return S_OK;
}
コード例 #10
0
ファイル: ProjectScreen.cpp プロジェクト: ConnorRB96/mutiny
void ProjectScreen::onAwake()
{
  Screen::setResolution(800, 600, false);

  header.reset(new Header(this));
  filesPanel.reset(new FilesPanel(this));
  hierarchyPanel.reset(new HierarchyPanel(this));
  inspectorPanel.reset(new InspectorPanel(this));
  scenePanel.reset(new ScenePanel(this));
  logPanel.reset(new LogPanel(this));
  dropdownLayer.reset(new DropdownLayer(this));

  AuthorCamera::create();
  inspectorCamera = InspectorCamera::create();
  Floor::create();

  GameObject* inspectorGo = new GameObject("_EDITOR_InspectorMesh");
  inspectorGo->setLayer(1 << 1);
  //inspectorGo->getTransform()->setPosition(Vector3(0, 0, 0));
  MeshRenderer* inspectorMr = inspectorGo->addComponent<MeshRenderer>();
  inspectorMf = inspectorGo->addComponent<MeshFilter>();
  inspectorMf->setMesh(Resources::load<Mesh>("primitives/cube"));

  inspectorMat.reset(new Material(Resources::load<Shader>(
    "shaders/EditorDiffuseTexture")));

  inspectorMr->setMaterial(inspectorMat.get());

  sceneName = "Untitled.mutiny";
  Application::setTitle("Mutiny - " + sceneName + " - " + SelectProjectScreen::selectedProject);

  // Temp (So I can see something...)
  GameObject* go = GameObject::createPrimitive(PrimitiveType::CUBE);
  go->setName("Player");
  go->getTransform()->setPosition(Vector3(0, 10, 0));

  go = GameObject::createPrimitive(PrimitiveType::CUBE);
  go->setName("WeaponSpawner");
  go->getTransform()->setPosition(Vector3(10, 10, 0));

  GameObject* go2 = GameObject::createPrimitive(PrimitiveType::CUBE);
  go2->setName("Sword");
  go2->getTransform()->setPosition(Vector3(0, 0, 0));
  go2->getTransform()->setParent(go->getTransform());

  go = GameObject::createPrimitive(PrimitiveType::CUBE);
  go->setName("Terrain");
  go->getTransform()->setPosition(Vector3(10, 0, 0));

  go = GameObject::createPrimitive(PrimitiveType::CUBE);
  go->setName("House");
  go->getTransform()->setPosition(Vector3(10, 0, 10));
}
コード例 #11
0
ファイル: SkyBox.cpp プロジェクト: jpmit/mutiny
void SkyBox::onAwake()
{
  Debug::log("SkyBox awoken");

  std::vector<Vector3> vertices;
  vertices.push_back(Vector3(-100, -100, 50));
  vertices.push_back(Vector3(-100, 100, 50));
  vertices.push_back(Vector3(100, 100, 50));
  vertices.push_back(Vector3(100, 100, 50));
  vertices.push_back(Vector3(100, -100, 50));
  vertices.push_back(Vector3(-100, -100, 50));

  std::vector<Vector2> uv;
  uv.push_back(Vector2(0, 1));
  uv.push_back(Vector2(0, 0));
  uv.push_back(Vector2(1, 0));
  uv.push_back(Vector2(1, 0));
  uv.push_back(Vector2(1, 1));
  uv.push_back(Vector2(0, 1));

  std::vector<int> triangles;
  triangles.push_back(0);
  triangles.push_back(1);
  triangles.push_back(2);
  triangles.push_back(3);
  triangles.push_back(4);
  triangles.push_back(5);

  Mesh* mesh = new Mesh();
  mesh->setVertices(vertices);
  mesh->setUv(uv);
  mesh->setTriangles(triangles, 0);

  MeshFilter* meshFilter = getGameObject()->addComponent<MeshFilter>();
  meshFilter->setMesh(mesh);

  Texture2d* texture = Resources::load<Texture2d>("textures/clouds");

  //Texture2d* texture = new Texture2d(1, 1);
  //texture->setPixel(0, 0, Color(1, 0, 0));
  //texture->apply();

  Material* material = new Material(Resources::load<Material>("shaders/Internal-SkyboxTexture"));
  material->setMainTexture(texture);

  MeshRenderer* meshRenderer = getGameObject()->addComponent<MeshRenderer>();
  meshRenderer->setMaterial(material);

  //getGameObject()->getTransform()->translate(Vector3(0, 0, 10));
  //getGameObject()->getTransform()->rotate(Vector3(0, 180, 0));
}
コード例 #12
0
//-----------------------------------------------------------------------------------
void Renderer::DrawText2D
	( const Vector2& startBottomLeft
	, const std::string& asciiText
	, float cellWidth
	, float cellHeight
	, const RGBA& tint /*= RGBA::WHITE*/
	, bool drawShadow /*= false*/
	, const BitmapFont* font /*= nullptr*/)
{
	const float SHADOW_WIDTH_OFFSET = cellWidth / 10.0f;
	const float SHADOW_HEIGHT_OFFSET = cellHeight / -10.0f;
	const Vector2 SHADOW_OFFSET = Vector2(SHADOW_WIDTH_OFFSET, SHADOW_HEIGHT_OFFSET);

	if (asciiText.empty())
	{
		return;
	}
	MeshBuilder builder;
	builder.Begin();
	if (font == nullptr)
	{
		font = m_defaultFont;
	}
	int stringLength = asciiText.size();
	Vector2 currentPosition = startBottomLeft;
	for (int i = 0; i < stringLength; i++)
	{
		unsigned char currentCharacter = asciiText[i];
		Vector2 topRight = currentPosition + Vector2(cellWidth, cellHeight);
		AABB2 quadBounds = AABB2(currentPosition, topRight);
		AABB2 glyphBounds =	font->GetTexCoordsForGlyph(currentCharacter);
		if (drawShadow)
		{
			AABB2 shadowBounds = AABB2(currentPosition + SHADOW_OFFSET, topRight + SHADOW_OFFSET);
			builder.AddTexturedAABB(shadowBounds, glyphBounds.mins, glyphBounds.maxs, RGBA::BLACK);
		}
		builder.AddTexturedAABB(quadBounds, glyphBounds.mins, glyphBounds.maxs, tint);
		currentPosition.x += cellWidth;
	}
	builder.End();

	Mesh* mesh = new Mesh();
	builder.CopyToMesh(mesh, &Vertex_PCUTB::Copy, sizeof(Vertex_PCUTB), &Vertex_PCUTB::BindMeshToVAO);
	mesh->m_drawMode = DrawMode::TRIANGLES;
	MeshRenderer* thingToRender = new MeshRenderer(mesh, font->GetMaterial());
	m_defaultMaterial->SetMatrices(Matrix4x4::IDENTITY, m_viewStack.GetTop(), m_projStack.GetTop());
	GL_CHECK_ERROR();
	thingToRender->Render();
	delete mesh;
	delete thingToRender;
}
コード例 #13
0
ファイル: BloomScreen.cpp プロジェクト: citruslee/mutiny
void BloomScreen::onAwake()
{
  BloomCamera::create();
  playerGo = new GameObject("Player");
  playerGo->getTransform()->setPosition(Vector3(-10, 0, -10));

  MeshRenderer* playerMr = playerGo->addComponent<MeshRenderer>();
  playerMr->setMaterial(Resources::load<Material>("shaders/Internal-MeshRendererTexture"));
  playerMr->getMaterial()->setMainTexture(Resources::load<Texture2d>("models/curuthers/Whiskers_diffuse").cast<Texture>());

  arc<Mesh> mesh = Resources::load<Mesh>("models/curuthers/curuthers");
  MeshFilter* playerMf = playerGo->addComponent<MeshFilter>();
  playerMf->setMesh(mesh);
}
コード例 #14
0
ファイル: Terrain.cpp プロジェクト: mortennobel/PolyPlane
void Terrain::addPlant(Transform *parent, vec3 pos){
    static int plantCounter = 0;
    plantCounter++;
    Mesh* plantMesh = plants[plantCounter % plants.size()];
    auto gameObject = Engine::activeScene()->createGameObject("Terrain");
    MeshRenderer* meshRenderer = gameObject->addComponent<MeshRenderer>();
    meshRenderer->setMesh(plantMesh);
    Material *material = new Material();
    material->setShader(Project::loadShader("poly-assets/shaders/diffuse_vertex_colored.shader"));
    meshRenderer->setMaterial(material);

    vec3 finalPos = (vec3)(parent->globalMatrix()*vec4(pos,1.0f));
    gameObject->transform()->setLocalPosition(finalPos);
    gameObject->transform()->setLocalScale(vec3(1)*linearRand(0.5f,1.5f));
    gameObject->transform()->setLocalRotationEuler(vec3(0,(float)linearRand(-M_PI,M_PI),0));
}
コード例 #15
0
//assumes mesh renderer has already been newed off
void SetDefaultTexturedMeshRenderer(MeshRenderer& meshRenderer){

	meshRenderer.m_material->InitializeMaterial("Data/Shaders/basicSampler.vert", "Data/Shaders/basicSampler.frag");

	meshRenderer.m_mesh->SetDrawMode(GL_QUADS);

	meshRenderer.BindVertexArray();
}
コード例 #16
0
ファイル: Terrain.cpp プロジェクト: citruslee/mutiny
void Terrain::onAwake()
{
  MeshRenderer* mr = getGameObject()->addComponent<MeshRenderer>();
  MeshFilter* mf = getGameObject()->addComponent<MeshFilter>();
  arc<Mesh> mesh = Resources::load<Mesh>("models/terrain/terrain");
  arc<Texture2d> tex = Resources::load<Texture2d>("models/terrain/terrain");

  arc<Material> material(new Material(Resources::load<Material>("shaders/Internal-MeshRendererTexture")));
  material->setMainTexture(tex.cast<Texture>());

  mr->setMaterial(material);
  mf->setMesh(mesh);

  MeshCollider* meshCollider = getGameObject()->addComponent<MeshCollider>();

  getGameObject()->getTransform()->setPosition(Vector3(0, -1, 25));
}
コード例 #17
0
MeshRenderer* MeshRenderer::CreateOrGetMeshRenderer(const std::string& name, bool allocMat, bool allocMesh, bool allowNullMeshRenderer) {

	UNUSED(allowNullMeshRenderer);

	MeshRendererMapIterator meshIter = s_globalMeshRenderers.find(name);
	if (meshIter != s_globalMeshRenderers.end()) {
		return meshIter->second;
	}
	MeshRenderer* newMeshRenderer = new MeshRenderer(name, allocMat, allocMesh); //mem leak here

														//if not null add to list
	if (!(newMeshRenderer->GetName() == "")) {
		s_globalMeshRenderers[name] = newMeshRenderer;
	}
	return newMeshRenderer;

}
コード例 #18
0
void DirectusMaterial::Reflect(weak_ptr<GameObject> gameobject)
{
    m_inspectedMaterial = weak_ptr<Material>();

    // Catch the evil case
    if (gameobject.expired())
    {
        this->hide();
        return;
    }

    MeshRenderer* meshRenderer = gameobject.lock()->GetComponent<MeshRenderer>().lock().get();
    if (!meshRenderer)
    {
        this->hide();
        return;
    }



    m_inspectedMaterial = meshRenderer->GetMaterial();
    if (m_inspectedMaterial.expired())
    {
        this->hide();
        return;
    }

    // Do the actual reflection
    ReflectName();
    ReflectShader();
    ReflectAlbedo();
    ReflectRoughness();
    ReflectMetallic();
    ReflectNormal();
    ReflectHeight();
    ReflectOcclusion();
    ReflectEmission();
    ReflectMask();
    ReflectTiling();
    ReflectOffset();

    SetPropertiesVisible(m_inspectedMaterial.lock()->IsEditable() ? true : false);

    // Make this widget visible
    this->show();
}
コード例 #19
0
ファイル: Renderer.cpp プロジェクト: picoriley/Picoguelike
//-----------------------------------------------------------------------------------
void Renderer::DrawVertexArray(const Vertex_PCT* vertexes, int numVertexes, DrawMode drawMode /*= QUADS*/, Texture* texture /*= nullptr*/)
{
// 	if (!texture)
// 	{
// 		texture = m_defaultTexture;
// 	}
// 	BindTexture(*texture);
// 	glEnableClientState(GL_VERTEX_ARRAY);
// 	glEnableClientState(GL_COLOR_ARRAY);
// 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// 	
// 	glVertexPointer(3, GL_FLOAT, sizeof(Vertex_PCT), &vertexes[0].pos);
// 	glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex_PCT), &vertexes[0].color);
// 	glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex_PCT), &vertexes[0].texCoords);
// 
// 	glDrawArrays(GetDrawMode(drawMode), 0, numVertexes);
// 
// 	glDisableClientState(GL_VERTEX_ARRAY);
// 	glDisableClientState(GL_COLOR_ARRAY);
// 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
// 	UnbindTexture();
	if (numVertexes == 0)
	{
		return;
	}
	MeshBuilder builder;
	builder.Begin();
	for (int i = 0; i < numVertexes; ++i)
	{
		builder.SetColor(vertexes[i].color);
		builder.SetUV(vertexes[i].texCoords);
		builder.SetTBN(Vector3::ZERO, Vector3::ZERO, Vector3::ZERO);
		builder.AddVertex(vertexes[i].pos);
		builder.AddIndex(i);
	}
	builder.End();

	Mesh* mesh = new Mesh();
	builder.CopyToMesh(mesh, &Vertex_PCUTB::Copy);
	mesh->m_drawMode = drawMode;
	MeshRenderer thingToRender = MeshRenderer(mesh, m_defaultMaterial);
	m_defaultMaterial->SetMatrices(Matrix4x4::IDENTITY, m_viewStack.GetTop(), m_projStack.GetTop());
	GL_CHECK_ERROR();
	thingToRender.Render();
	delete mesh;
}
コード例 #20
0
ファイル: LayerScreen.cpp プロジェクト: jjiezheng/mutiny
void LayerScreen::onAwake()
{
  cameraGo = LayerCamera::create();

  playerGo = new GameObject("Player");
  //playerGo->setLayer(1 << 1);
  playerGo->getTransform()->setPosition(Vector3(0, 0, 0));

  MeshRenderer* playerMr = playerGo->addComponent<MeshRenderer>();
  playerMr->setMaterial(Resources::load<Material>("shaders/textured"));
  playerMr->getMaterial()->setMainTexture(Resources::load<Texture2d>("models/curuthers/Whiskers_diffuse"));

  Mesh* mesh = Resources::load<Mesh>("models/curuthers/curuthers");
  MeshFilter* playerMf = playerGo->addComponent<MeshFilter>();
  playerMf->setMesh(mesh);
  
  
}
コード例 #21
0
ファイル: Terrain.cpp プロジェクト: mortennobel/PolyPlane
void Terrain::addCloud(vec3 pos, vec3 min, vec3 max){
    static MeshData* cloudMesh = loadPlyData("poly-assets/models","cloud.ply");
    static Mesh *mesh = new Mesh();
    mesh->setMeshData(cloudMesh);

    auto gameObject = Engine::activeScene()->createGameObject("Cloud");
    gameObject->addComponent<Cloud>(min, max);
    MeshRenderer* meshRenderer = gameObject->addComponent<MeshRenderer>();
    meshRenderer->setMesh(mesh);
    Material *material = new Material();
    material->setShader(Project::loadShader("poly-assets/shaders/unlit_vertex_colored.shader"));
    meshRenderer->setMaterial(material);


    gameObject->transform()->setLocalPosition(pos);
    gameObject->transform()->setLocalScale(vec3(1)*linearRand(0.5f,5.0f));
    gameObject->transform()->setLocalRotationEuler(vec3(0,(float)linearRand(-M_PI,M_PI),0));
}
コード例 #22
0
ファイル: zframework3d.cpp プロジェクト: zzez12/ZFramework
void ZFramework3D::slot_load_laplacian()
{
	QString fileName = QFileDialog::getOpenFileName(this,
		tr("Load eigen vector"),
		QDir::currentPath(),
		tr("TXT File(*.txt);;"
		"All Files (*)"));
	ZMeshSpace::ZMeshAlgorithms* handler = ZDataManager::getDataManager()->getAlgorithmHandler();
	ZMeshSpace::Mesh3D* mesh = ZDataManager::getDataManager()->getMesh();
	handler->setMesh(mesh);

	if(!fileName.isEmpty())
		handler->loadEigenVector(fileName.toLocal8Bit());
	QGLViewerWidget* wiget = this->ui.widget;
	MeshRenderer* mr = (MeshRenderer*)wiget->getRenderer();
	mr->setRenderType(RENDER_TYPE_VERTEX_COLOR);
	updateViews();
}
コード例 #23
0
	TestObject():sponge(false,2,false){
		mesh = new IndexedMesh();
		sponge.toMesh(mesh);
		std::cout << mesh->getFaces().size() << std::endl;
		mesh->removeDoubleTriangles(true);
		std::cout << mesh->getFaces().size() << std::endl;

		meshRender = new MeshRenderer();
		meshRender->buildFromMesh(mesh,false);
	}
コード例 #24
0
ファイル: Terrain.cpp プロジェクト: mortennobel/PolyPlane
void Terrain::buildTerrain(vec2 offset, Mesh *mesh, MeshData* meshData, vec3 min, vec3 max){
    auto gameObject = Engine::activeScene()->createGameObject("Terrain");
    MeshRenderer* meshRenderer = gameObject->addComponent<MeshRenderer>();
    meshRenderer->setMesh(mesh);
    Material *material = new Material();
    material->setShader(Project::loadShader("poly-assets/shaders/unlit_vertex_colored.shader"));
    meshRenderer->setMaterial(material);

    gameObject->transform()->setPosition(vec3{offset.x*200*worldScale, 0, offset.y*200*worldScale});
    gameObject->transform()->setLocalScale(vec3{worldScale, 1, worldScale});
    gameObject->transform()->setLocalRotationEuler(vec3{0,M_PI*(offset.x+offset.y),0});

    auto& indices = meshData->submeshIndices(0);
    auto& pos = meshData->position();
    for (int i=0;i<190;i++){
        // find random triangle
        int index = (int)linearRand(0.0f, indices.size()/3-1.0f)*3;

        vec3 p1 = pos[index];
        vec3 p2 = pos[index+1];
        vec3 p3 = pos[index+2];
        if (p1.y <-0.1){
            continue;
        }
        bool horizontal =glm::abs(p1.y- p2.y)+glm::abs(p2.y-p3.y)<0.1f;
        if (horizontal){
            vec3 midpoint = (p1+p2+p3)*(1/3.0f);
            addPlant (gameObject->transform(), midpoint);
        }
    }

    for (int i=0;i<20;i++){
        float x= linearRand((-100.0f),(100.0f));
        float z= linearRand((-100.0f),(100.0f));
        vec3 cloudPos = vec3(x,0,z) * worldScale + gameObject->transform()->position();
        cloudPos.y = linearRand(20.0f,50.0f);

        addCloud(cloudPos, min, max);
    }
}
コード例 #25
0
ファイル: GameManager.cpp プロジェクト: TheCodeInside/BowLand
// Creates an arrow game object
GameObject* GameManager::CreateArrow( const XMFLOAT3& position, const XMFLOAT3& force )
{
    static const XMFLOAT3 ArrowSize = { 1, 0.1f, 1.0f };

    Scene* scene = Scene::GetInstance();
    ID3D11Device* device = _gameObject->GetDevice();
    ID3D11DeviceContext* deviceContext = _gameObject->GetDeviceContext();

    // Create the arrow object
    GameObject* arrow = scene->AddGameObject( _gameObject->GetName() + "_Arrow_" + std::to_string( _arrowCount++ ) );
    
    // Set some transform info
    Transform* transform = arrow->GetTransform();
    transform->SetPosition( position );

    // Add the arrow's collider
    BoxCollider* collider = arrow->AddComponent<BoxCollider>();
    collider->SetSize( ArrowSize );

    // Add the arrow's rigidbody
    Rigidbody* rigidbody = arrow->AddComponent<Rigidbody>();
    rigidbody->SetMass( 1.0f );

    // Set the arrow's collision callback
    GameObject::CollisionCallback callback = std::bind( &GameManager::OnArrowCollide, this, _1 );
    arrow->AddEventListener( "OnArrowCollide", callback );

    // Add a default material
    DefaultMaterial* material = arrow->AddComponent<DefaultMaterial>();
    material->LoadDiffuseMap( "Textures\\SolidWhite.png" );
    material->SetDirectionalLight( StageLight );

    // Add a mesh renderer
    MeshRenderer* meshRenderer = arrow->AddComponent<MeshRenderer>();
    meshRenderer->SetMaterial( material );
    meshRenderer->SetMesh( MeshLoader::Load( "Models\\arrow.obj", device, deviceContext ) );

    return arrow;
}
コード例 #26
0
//assumes only common model file path
MeshRenderer WarlockeryModelLoader::CreateNewMeshRendererFromWarlockeryModelFile(const std::string& fileName){

	MeshRenderer meshRenderer = MeshRenderer();

	meshRenderer.m_mesh = new Mesh();

	meshRenderer.m_mesh->SetDrawMode(GL_TRIANGLES);

	LoadWarlockeryModelFileToMesh(fileName, meshRenderer.m_mesh, true);

	meshRenderer.m_material = new Material();

	std::string modelShaderName = "ModelLighting";

	SetCustomModelMaterial(meshRenderer.m_material, modelShaderName + ".vert", modelShaderName + ".frag");

	LoadModelTexturesForWarlockeryModelFile(meshRenderer.m_material, fileName);
	
	meshRenderer.BindVertexArray();

	return meshRenderer;

}
コード例 #27
0
ファイル: BSP.cpp プロジェクト: baibaiwei/CubicVR
//DRAWING FUNCTIONS
//Draw all faces marked as visible
void BSP::DrawGLSL(MeshRenderer &shader)
{
	if (single_cluster)
	{
		shader.render(clusterObject,SHADER_STAGE_OPAQUE);
	}
	else
	{
//		for (int i = 0; i < numLeaves; i++)
//		{
//			if (leafActive.IsSet(i) && clusterObjects[i] != NULL) shader.render(*clusterObjects[i],SHADER_STAGE_OPAQUE);
//		}
	}
}
コード例 #28
0
ファイル: zframework3d.cpp プロジェクト: zzez12/ZFramework
void ZFramework3D::slot_compute_laplacian()
{
	ZMeshSpace::ZMeshAlgorithms* handler = ZDataManager::getDataManager()->getAlgorithmHandler();
	ZMeshSpace::Mesh3D* mesh = ZDataManager::getDataManager()->getMesh();
	QString strType = ui.cobLaplacianType->currentText();
	ZMeshSpace::ZMeshAlgorithms::LaplacianType type = ZMeshSpace::ZMeshAlgorithms::COTANGENT;
	if (strType==QString("Uniform"))
	{
		type = ZMeshSpace::ZMeshAlgorithms::UNIFORM;
	}
	else if (strType==QString("Cotangent"))
	{
		type = ZMeshSpace::ZMeshAlgorithms::COTANGENT;
	}
	handler->setMesh(mesh);
	handler->setLaplacianType(type);
	handler->computeLaplacian();
	handler->computeEigens();
	QGLViewerWidget* wiget = this->ui.widget;
	MeshRenderer* mr = (MeshRenderer*)wiget->getRenderer();
	mr->setRenderType(RENDER_TYPE_VERTEX_COLOR);
	qDebug("Compute Laplacian done!\n");
}
コード例 #29
0
ファイル: Renderer.cpp プロジェクト: picoriley/Picoguelike
//-----------------------------------------------------------------------------------
void Renderer::DrawVertexArrayModern(const Vertex_PCT* vertexes, int numVertexes, Renderer::DrawMode drawMode /*= QUADS*/, Texture* texture /*= nullptr*/)
{
	MeshBuilder builder;
	builder.Begin();
	for (int i = 0; i < numVertexes; ++i)
	{
		builder.SetColor(vertexes[i].color);
		builder.SetUV(vertexes[i].texCoords);
		builder.SetTBN(Vector3::ZERO, Vector3::ZERO, Vector3::ZERO);
		builder.AddVertex(vertexes[i].pos);
		builder.AddIndex(i);
	}
	builder.End();

	Mesh* mesh = new Mesh();
	builder.CopyToMesh(mesh, &Vertex_PCUTB::Copy);
	mesh->m_drawMode = drawMode;
	MeshRenderer thingToRender = MeshRenderer(mesh, m_defaultMaterial);
	m_defaultMaterial->SetMatrices(Matrix4x4::IDENTITY, m_viewStack.GetTop(), m_projStack.GetTop());
	GL_CHECK_ERROR();
	thingToRender.Render();
	delete mesh;
}
コード例 #30
0
ファイル: zframework3d.cpp プロジェクト: zzez12/ZFramework
void ZFramework3D::slot_load_eigen()
{
	ZMeshSpace::ZMeshAlgorithms* handler = ZDataManager::getDataManager()->getAlgorithmHandler();
	ZMeshSpace::Mesh3D* mesh = ZDataManager::getDataManager()->getMesh();
	handler->setMesh(mesh);

	QString fileName = QFileDialog::getOpenFileName(this,
		tr("Load Eigen file"),
		QDir::currentPath(),
		tr("EIG File(*.eig);;"
		"All Files(*.*)"));
	if (!fileName.isEmpty())
	{
		handler->loadEigenVectors(fileName.toLocal8Bit());
		qDebug("Save Laplacian done!\n");

		QGLViewerWidget* wiget = this->ui.widget;
		MeshRenderer* mr = (MeshRenderer*)wiget->getRenderer();
		mr->setRenderType(RENDER_TYPE_VERTEX_COLOR);
		slot_change_idx();
		//updateViews();
	}
}