Browse Source

Add sponza as a sample

Panagiotis Christopoulos Charitos 8 years ago
parent
commit
e756829942

+ 1 - 1
.gitignore

@@ -11,4 +11,4 @@
 !*.md
 !*.txt
 !CMakeLists.txt
-build/*
+build*/*

+ 4 - 3
README.md

@@ -81,9 +81,10 @@ Next steps
 ==========
 
 Try to build with samples enabled (see the relevant option in your CMake GUI, ANKI_BUILD_SAMPLES) and try running the 
-simple_scene executable. All samples must run from within the samples directory.
+sponza executable. Then you will be able to see sponza running in AnKi. All samples must run from within their 
+directory.
 
-	$cd path/to/anki/samples
-	$./path/to/build/samples/simple_scene/simple_scene
+	$cd path/to/anki/samples/sponza
+	$./path/to/build/samples/sponza/sponza
 
 More samples will follow.

+ 1 - 0
samples/CMakeLists.txt

@@ -1,2 +1,3 @@
 add_definitions(-UANKI_BUILD)
 add_subdirectory(simple_scene)
+add_subdirectory(sponza)

+ 140 - 0
samples/common/Framework.cpp

@@ -0,0 +1,140 @@
+// Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include "Framework.h"
+
+using namespace anki;
+
+Error SampleApp::init(int argc, char** argv)
+{
+	// Init the super class
+	Config config;
+	config.set("fullscreenDesktopResolution", true);
+	config.set("dataPaths", ".:../..");
+	config.set("debugContext", 0);
+	ANKI_CHECK(config.setFromCommandLineArguments(argc, argv));
+	ANKI_CHECK(App::init(config, allocAligned, nullptr));
+
+	// Input
+	getInput().lockCursor(true);
+	getInput().hideCursor(true);
+	getInput().moveCursor(Vec2(0.0));
+
+	// Some renderer stuff
+	getMainRenderer().getOffscreenRenderer().getVolumetric().setFogParticleColor(Vec3(1.0, 0.9, 0.9) * 0.0001);
+
+	ANKI_CHECK(sampleExtraInit());
+
+	return ErrorCode::NONE;
+}
+
+Error SampleApp::userMainLoop(Bool& quit)
+{
+	const F32 MOVE_DISTANCE = 0.1;
+	const F32 ROTATE_ANGLE = toRad(2.5);
+	const F32 MOUSE_SENSITIVITY = 9.0;
+	quit = false;
+
+	SceneGraph& scene = getSceneGraph();
+	Renderer& renderer = getMainRenderer().getOffscreenRenderer();
+	Input& in = getInput();
+
+	if(in.getKey(KeyCode::ESCAPE))
+	{
+		quit = true;
+		return ErrorCode::NONE;
+	}
+
+	// move the camera
+	static MoveComponent* mover = &scene.getActiveCamera().getComponent<MoveComponent>();
+
+	if(in.getKey(KeyCode::_1) == 1)
+	{
+		mover = &scene.getActiveCamera().getComponent<MoveComponent>();
+	}
+
+	if(in.getKey(KeyCode::F1) == 1)
+	{
+		renderer.getDbg().setEnabled(!renderer.getDbg().getEnabled());
+	}
+	if(in.getKey(KeyCode::F2) == 1)
+	{
+		renderer.getDbg().flipFlags(DbgFlag::SPATIAL_COMPONENT);
+	}
+	if(in.getKey(KeyCode::F6) == 1)
+	{
+		renderer.getDbg().switchDepthTestEnabled();
+	}
+
+	if(in.getKey(KeyCode::UP))
+	{
+		mover->rotateLocalX(ROTATE_ANGLE);
+	}
+
+	if(in.getKey(KeyCode::DOWN))
+	{
+		mover->rotateLocalX(-ROTATE_ANGLE);
+	}
+
+	if(in.getKey(KeyCode::LEFT))
+	{
+		mover->rotateLocalY(ROTATE_ANGLE);
+	}
+
+	if(in.getKey(KeyCode::RIGHT))
+	{
+		mover->rotateLocalY(-ROTATE_ANGLE);
+	}
+
+	if(in.getKey(KeyCode::A))
+	{
+		mover->moveLocalX(-MOVE_DISTANCE);
+	}
+
+	if(in.getKey(KeyCode::D))
+	{
+		mover->moveLocalX(MOVE_DISTANCE);
+	}
+
+	if(in.getKey(KeyCode::Z))
+	{
+		mover->moveLocalY(MOVE_DISTANCE);
+	}
+
+	if(in.getKey(KeyCode::SPACE))
+	{
+		mover->moveLocalY(-MOVE_DISTANCE);
+	}
+
+	if(in.getKey(KeyCode::W))
+	{
+		mover->moveLocalZ(-MOVE_DISTANCE);
+	}
+
+	if(in.getKey(KeyCode::S))
+	{
+		mover->moveLocalZ(MOVE_DISTANCE);
+	}
+
+	if(in.getKey(KeyCode::Q))
+	{
+		mover->rotateLocalZ(ROTATE_ANGLE);
+	}
+
+	if(in.getKey(KeyCode::E))
+	{
+		mover->rotateLocalZ(-ROTATE_ANGLE);
+	}
+
+	if(in.getMousePosition() != Vec2(0.0))
+	{
+		F32 angY = -ROTATE_ANGLE * in.getMousePosition().x() * MOUSE_SENSITIVITY * getMainRenderer().getAspectRatio();
+
+		mover->rotateLocalY(angY);
+		mover->rotateLocalX(ROTATE_ANGLE * in.getMousePosition().y() * MOUSE_SENSITIVITY);
+	}
+
+	return ErrorCode::NONE;
+}

+ 17 - 0
samples/common/Framework.h

@@ -0,0 +1,17 @@
+// Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#pragma once
+
+#include <anki/AnKi.h>
+
+class SampleApp : public anki::App
+{
+public:
+	anki::Error init(int argc, char** argv);
+	anki::Error userMainLoop(anki::Bool& quit) override;
+
+	virtual anki::Error sampleExtraInit() = 0;
+};

+ 1 - 1
samples/simple_scene/CMakeLists.txt

@@ -1,2 +1,2 @@
-add_executable(simple_scene Main.cpp)
+add_executable(simple_scene Main.cpp ../common/Framework.cpp)
 target_link_libraries(simple_scene anki)

+ 15 - 141
samples/simple_scene/Main.cpp

@@ -1,157 +1,30 @@
+// Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
 #include <cstdio>
-#include <anki/AnKi.h>
+#include "../common/Framework.h"
 
 using namespace anki;
 
-class MyApp : public App
+class MyApp : public SampleApp
 {
 public:
-	Error init(int argc, char** argv);
-	Error userMainLoop(Bool& quit) override;
-};
-
-MyApp* app;
-
-Error MyApp::init(int argc, char** argv)
-{
-	// Init the super class
-	Config config;
-	config.set("fullscreenDesktopResolution", true);
-	config.set("dataPaths", ".:..");
-	config.set("debugContext", 0);
-	ANKI_CHECK(config.setFromCommandLineArguments(argc, argv));
-	ANKI_CHECK(App::init(config, allocAligned, nullptr));
-
-	// Load the scene.lua
-	ScriptResourcePtr script;
-	ANKI_CHECK(getResourceManager().loadResource("samples/assets/scene.lua", script));
-	ANKI_CHECK(getScriptManager().evalString(script->getSource()));
-
-	// Input
-	getInput().lockCursor(true);
-	getInput().hideCursor(true);
-	getInput().moveCursor(Vec2(0.0));
-
-	// Some renderer stuff
-	getMainRenderer().getOffscreenRenderer().getVolumetric().setFogParticleColor(Vec3(1.0, 0.9, 0.9) * 0.0001);
-
-	return ErrorCode::NONE;
-}
-
-Error MyApp::userMainLoop(Bool& quit)
-{
-	const F32 MOVE_DISTANCE = 0.1;
-	const F32 ROTATE_ANGLE = toRad(2.5);
-	const F32 MOUSE_SENSITIVITY = 9.0;
-	quit = false;
-
-	SceneGraph& scene = getSceneGraph();
-	Renderer& renderer = getMainRenderer().getOffscreenRenderer();
-	Input& in = getInput();
-
-	if(in.getKey(KeyCode::ESCAPE))
+	Error sampleExtraInit()
 	{
-		quit = true;
+		ScriptResourcePtr script;
+		ANKI_CHECK(getResourceManager().loadResource("assets/scene.lua", script));
+		ANKI_CHECK(getScriptManager().evalString(script->getSource()));
 		return ErrorCode::NONE;
 	}
-
-	// move the camera
-	static MoveComponent* mover = &scene.getActiveCamera().getComponent<MoveComponent>();
-
-	if(in.getKey(KeyCode::_1) == 1)
-	{
-		mover = &scene.getActiveCamera().getComponent<MoveComponent>();
-	}
-
-	if(in.getKey(KeyCode::F1) == 1)
-	{
-		renderer.getDbg().setEnabled(!renderer.getDbg().getEnabled());
-	}
-	if(in.getKey(KeyCode::F2) == 1)
-	{
-		renderer.getDbg().flipFlags(DbgFlag::SPATIAL_COMPONENT);
-	}
-	if(in.getKey(KeyCode::F6) == 1)
-	{
-		renderer.getDbg().switchDepthTestEnabled();
-	}
-
-	if(in.getKey(KeyCode::UP))
-	{
-		mover->rotateLocalX(ROTATE_ANGLE);
-	}
-
-	if(in.getKey(KeyCode::DOWN))
-	{
-		mover->rotateLocalX(-ROTATE_ANGLE);
-	}
-
-	if(in.getKey(KeyCode::LEFT))
-	{
-		mover->rotateLocalY(ROTATE_ANGLE);
-	}
-
-	if(in.getKey(KeyCode::RIGHT))
-	{
-		mover->rotateLocalY(-ROTATE_ANGLE);
-	}
-
-	if(in.getKey(KeyCode::A))
-	{
-		mover->moveLocalX(-MOVE_DISTANCE);
-	}
-
-	if(in.getKey(KeyCode::D))
-	{
-		mover->moveLocalX(MOVE_DISTANCE);
-	}
-
-	if(in.getKey(KeyCode::Z))
-	{
-		mover->moveLocalY(MOVE_DISTANCE);
-	}
-
-	if(in.getKey(KeyCode::SPACE))
-	{
-		mover->moveLocalY(-MOVE_DISTANCE);
-	}
-
-	if(in.getKey(KeyCode::W))
-	{
-		mover->moveLocalZ(-MOVE_DISTANCE);
-	}
-
-	if(in.getKey(KeyCode::S))
-	{
-		mover->moveLocalZ(MOVE_DISTANCE);
-	}
-
-	if(in.getKey(KeyCode::Q))
-	{
-		mover->rotateLocalZ(ROTATE_ANGLE);
-	}
-
-	if(in.getKey(KeyCode::E))
-	{
-		mover->rotateLocalZ(-ROTATE_ANGLE);
-	}
-
-	if(in.getMousePosition() != Vec2(0.0))
-	{
-		F32 angY = -ROTATE_ANGLE * in.getMousePosition().x() * MOUSE_SENSITIVITY * getMainRenderer().getAspectRatio();
-
-		mover->rotateLocalY(angY);
-		mover->rotateLocalX(ROTATE_ANGLE * in.getMousePosition().y() * MOUSE_SENSITIVITY);
-	}
-
-	return ErrorCode::NONE;
-}
+};
 
 int main(int argc, char* argv[])
 {
 	Error err = ErrorCode::NONE;
 
-	app = new MyApp;
+	MyApp* app = new MyApp;
 	err = app->init(argc, argv);
 	if(!err)
 	{
@@ -160,7 +33,8 @@ int main(int argc, char* argv[])
 
 	if(err)
 	{
-		ANKI_LOGE("Error reported. To run %s you have to navigate to the /path/to/anki/samples. And then execute it",
+		ANKI_LOGE("Error reported. To run %s you have to navigate to the /path/to/anki/samples/simple_scene. "
+				  "And then execute it",
 			argv[0]);
 	}
 	else

+ 0 - 0
samples/assets/column.ankimesh → samples/simple_scene/assets/column.ankimesh


+ 0 - 0
samples/assets/columnroom-material.ankimdl → samples/simple_scene/assets/columnroom-material.ankimdl


+ 0 - 0
samples/assets/room-material.ankimtl → samples/simple_scene/assets/room-material.ankimtl


+ 0 - 0
samples/assets/room.ankimesh → samples/simple_scene/assets/room.ankimesh


+ 0 - 0
samples/assets/roomroom-material.ankimdl → samples/simple_scene/assets/roomroom-material.ankimdl


+ 0 - 0
samples/assets/scene.lua → samples/simple_scene/assets/scene.lua


+ 0 - 0
samples/assets/sector.ankimesh → samples/simple_scene/assets/sector.ankimesh


+ 0 - 0
samples/assets/simple_scene.blend → samples/simple_scene/assets/simple_scene.blend


+ 2 - 0
samples/sponza/CMakeLists.txt

@@ -0,0 +1,2 @@
+add_executable(sponza Main.cpp ../common/Framework.cpp)
+target_link_libraries(sponza anki)

+ 49 - 0
samples/sponza/Main.cpp

@@ -0,0 +1,49 @@
+// Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include <cstdio>
+#include "../common/Framework.h"
+
+using namespace anki;
+
+class MyApp : public SampleApp
+{
+public:
+	Error sampleExtraInit()
+	{
+		ScriptResourcePtr script;
+		ANKI_CHECK(getResourceManager().loadResource("assets/scene.lua", script));
+		ANKI_CHECK(getScriptManager().evalString(script->getSource()));
+
+		getMainRenderer().getOffscreenRenderer().getVolumetric().setFogParticleColor(Vec3(1.0, 0.9, 0.9) * 0.009);
+		return ErrorCode::NONE;
+	}
+};
+
+int main(int argc, char* argv[])
+{
+	Error err = ErrorCode::NONE;
+
+	MyApp* app = new MyApp;
+	err = app->init(argc, argv);
+	if(!err)
+	{
+		err = app->mainLoop();
+	}
+
+	if(err)
+	{
+		ANKI_LOGE("Error reported. To run %s you have to navigate to the /path/to/anki/samples/sponza. "
+				  "And then execute it",
+			argv[0]);
+	}
+	else
+	{
+		delete app;
+		ANKI_LOGI("Bye!!");
+	}
+
+	return 0;
+}