Exemple #1
0
void Graphics_Mesh(bool isOpenGLMode)
{
	StartGraphicsTest();
	SetGLEnable(isOpenGLMode);

	asd::Log* log = asd::Log_Imp::Create(L"graphics.html", L"メッシュ");

	auto window = asd::Window_Imp::Create(640, 480, asd::ToAString(L"メッシュ").c_str());
	ASSERT_TRUE(window != nullptr);

	auto file = asd::File_Imp::Create();
	ASSERT_TRUE(file != nullptr);

	auto graphics = asd::Graphics_Imp::Create(window, isOpenGLMode ? asd::GraphicsDeviceType::OpenGL : asd::GraphicsDeviceType::DirectX11, log, file, false, false);
	ASSERT_TRUE(graphics != nullptr);

	auto renderer3d = new asd::Renderer3D(graphics, asd::RenderSettings());
	ASSERT_TRUE(renderer3d != nullptr);
	renderer3d->SetWindowSize(asd::Vector2DI(640, 480));

	auto mesh1 = CreateMesh(graphics);
	auto mesh2 = CreateMesh(graphics);
	auto deformer = CreateDeformer(graphics);
	auto animation = CreateAnimation();

	SetMeshBone(mesh2);

	mesh1->SendToGPUMemory();
	mesh2->SendToGPUMemory();

	auto cameraObject = new asd::RenderedCameraObject3D(graphics);
	cameraObject->SetPosition(asd::Vector3DF(0, 0, 10));
	cameraObject->SetFocus(asd::Vector3DF(0, 0, 0));
	cameraObject->SetFieldOfView(20.0f);
	cameraObject->SetZNear(1.0f);
	cameraObject->SetZFar(20.0f);
	cameraObject->SetWindowSize(asd::Vector2DI(800, 600));

	auto meshObject1 = new asd::RenderedModelObject3D(graphics);
	meshObject1->AddMesh(mesh1);
	
	meshObject1->SetPosition(asd::Vector3DF(1, 0, 0));
	meshObject1->SetRotation(asd::Vector3DF(20.0f, 20.0f, 0.0f));

	auto meshObject2 = new asd::RenderedModelObject3D(graphics);
	meshObject2->AddMesh(mesh2);
	meshObject2->SetDeformer(deformer.get());
	meshObject2->SetPosition(asd::Vector3DF(-1, 0, 0));
	meshObject2->SetRotation(asd::Vector3DF(20.0f, 20.0f, 0.0f));
	meshObject2->AddAnimationClip(asd::ToAString("anime1").c_str(), animation.get());
	meshObject2->PlayAnimation(0, asd::ToAString("anime1").c_str());

	auto lightObject = new asd::RenderedDirectionalLightObject3D(graphics);
	lightObject->SetRotation(asd::Vector3DF(30, 160, 0));

	renderer3d->AddObject(cameraObject);
	renderer3d->AddObject(meshObject1);
	renderer3d->AddObject(meshObject2);
	renderer3d->AddObject(lightObject);

	int32_t time = 0;
	while (window->DoEvent())
	{
		graphics->Begin();
		graphics->Clear(true, false, asd::Color(0, 0, 0, 255));

		renderer3d->Flip(1);

		renderer3d->BeginRendering(1);
		asd::Sleep(100);
		renderer3d->EndRendering();

		graphics->SetRenderTarget(nullptr, nullptr);
		graphics->Clear(true, false, asd::Color(0, 0, 0, 255));

		renderer3d->RenderResult();

		graphics->Present();

		graphics->End();

		if (time == 10)
		{
			SAVE_SCREEN_SHOT(graphics, 0);
		}

		if (time == 11)
		{
			window->Close();
		}
		time++;
	}

	meshObject1->Release();
	meshObject2->Release();

	cameraObject->Release();
	lightObject->Release();

	delete renderer3d;

	graphics->Release();
	file->Release();

	window->Release();
	delete log;
}
void Graphics_Mesh(bool isOpenGLMode)
{
	StartGraphicsTest();
	SetGLEnable(isOpenGLMode);

	ace::Log* log = ace::Log_Imp::Create(L"graphics.html", L"メッシュ");

	auto window = ace::Window_Imp::Create(640, 480, ace::ToAString(L"メッシュ").c_str());
	ASSERT_TRUE(window != nullptr);

	auto graphics = ace::Graphics_Imp::Create(window, isOpenGLMode, log, false);
	ASSERT_TRUE(graphics != nullptr);

	auto renderer3d = new ace::Renderer3D(graphics);
	ASSERT_TRUE(renderer3d != nullptr);
	renderer3d->SetWindowSize(ace::Vector2DI(640, 480));

	auto mesh1 = CreateMesh(graphics);
	auto mesh2 = CreateMesh(graphics);
	auto deformer = CreateDeformer(graphics);
	auto animation = CreateAnimation();

	auto cameraObject = new ace::RenderedCameraObject3D(graphics);
	cameraObject->SetPosition(ace::Vector3DF(0, 0, 10));
	cameraObject->SetFocus(ace::Vector3DF(0, 0, 0));
	cameraObject->SetFieldOfView(20.0f);
	cameraObject->SetZNear(1.0f);
	cameraObject->SetZFar(20.0f);
	cameraObject->SetWindowSize(ace::Vector2DI(800, 600));

	auto meshObject1 = new ace::RenderedModelObject3D(graphics);
	meshObject1->AddMeshGroup();
	meshObject1->AddMesh(0, mesh1);
	
	meshObject1->SetPosition(ace::Vector3DF(1, 0, 0));
	meshObject1->SetRotation(ace::Vector3DF(20.0f, 20.0f, 0.0f));

	auto meshObject2 = new ace::RenderedModelObject3D(graphics);
	meshObject2->AddMeshGroup();
	meshObject2->AddMesh(0, mesh2);
	meshObject2->SetDeformer(0, deformer.get());
	meshObject2->SetPosition(ace::Vector3DF(-1, 0, 0));
	meshObject2->SetRotation(ace::Vector3DF(20.0f, 20.0f, 0.0f));
	meshObject2->AddAnimationClip(ace::ToAString("anime1").c_str(), animation.get());
	meshObject2->PlayAnimation(ace::ToAString("anime1").c_str());

	auto lightObject = new ace::RenderedDirectionalLightObject3D(graphics);
	lightObject->SetRotation(ace::Vector3DF(30, 160, 0));

	renderer3d->AddObject(cameraObject);
	renderer3d->AddObject(meshObject1);
	renderer3d->AddObject(meshObject2);
	renderer3d->AddObject(lightObject);

	auto renderer2d = new ace::Renderer2D_Imp(graphics, log, window->GetSize());


	int32_t time = 0;
	while (window->DoEvent())
	{
		graphics->Begin();
		graphics->Clear(true, false, ace::Color(0, 0, 0, 255));

		renderer3d->Flip();

		renderer3d->BeginRendering();
		ace::Sleep(100);
		renderer3d->EndRendering();

		graphics->SetRenderTarget(nullptr, nullptr);

		ace::Vector2DF positions[4];
		ace::Color colors[4];
		ace::Vector2DF uvs[4];

		colors[0] = ace::Color(255, 255, 255, 255);
		colors[1] = ace::Color(255, 255, 255, 255);
		colors[2] = ace::Color(255, 255, 255, 255);
		colors[3] = ace::Color(255, 255, 255, 255);

		positions[0].X = 0;
		positions[0].Y = 0;
		positions[1].X = 640;
		positions[1].Y = 0;
		positions[2].X = 640;
		positions[2].Y = 480;
		positions[3].X = 0;
		positions[3].Y = 480;

		uvs[0].X = 0;
		uvs[0].Y = 0;
		uvs[1].X = 1;
		uvs[1].Y = 0;
		uvs[2].X = 1;
		uvs[2].Y = 1;
		uvs[3].X = 0;
		uvs[3].Y = 1;

		renderer2d->AddSprite(positions, colors, uvs, renderer3d->GetRenderTarget(), ace::eAlphaBlend::ALPHA_BLEND_BLEND, 0);
		renderer2d->DrawCache();
		renderer2d->ClearCache();

		graphics->Present();

		graphics->End();

		if (time == 10)
		{
			SAVE_SCREEN_SHOT(graphics, 0);
		}

		if (time == 11)
		{
			window->Close();
		}
		time++;
	}

	meshObject1->Release();
	meshObject2->Release();

	cameraObject->Release();
	lightObject->Release();

	delete renderer2d;
	delete renderer3d;

	graphics->Release();

	window->Release();
	delete log;
}