Beispiel #1
0
void SceneLoader::ImportMaterial(Scene& scene,
                                 const aiMaterial* const material) {
    aiString ai_name;
    material->Get(AI_MATKEY_NAME, ai_name);
    aiColor4D diffuse_color(0.0f, 0.0f, 0.0f, 1.0f);
    material->Get(AI_MATKEY_COLOR_DIFFUSE, diffuse_color);
    aiColor4D specular_color(0.0f, 0.0f, 0.0f, 1.0f);
    material->Get(AI_MATKEY_COLOR_SPECULAR, specular_color);
    aiColor4D ambient_color(0.0f, 0.0f, 0.0f, 1.0f);
    material->Get(AI_MATKEY_COLOR_AMBIENT, ambient_color);
    aiColor4D emissive_color(0.0f, 0.0f, 0.0f, 1.0f);
    material->Get(AI_MATKEY_COLOR_EMISSIVE, emissive_color);
    float opacity = 0.0f;
    material->Get(AI_MATKEY_OPACITY, opacity);
    float reflectivity = 0.0f;
    material->Get(AI_MATKEY_REFLECTIVITY, reflectivity);
    float refractivity = 0.0f;
    material->Get(AI_MATKEY_REFRACTI, refractivity);
    float shininess = 0.0f;
    material->Get(AI_MATKEY_SHININESS, shininess);
    std::string name;
    name = std::string(ai_name.C_Str());
    Material mat;
    mat.kd = glm::vec3(diffuse_color[0], diffuse_color[1], diffuse_color[2]);
    mat.ks = glm::vec3(specular_color[0], specular_color[1], specular_color[2]);
    mat.ka = glm::vec3(ambient_color[0], ambient_color[1], ambient_color[2]);
    mat.ke = glm::vec3(emissive_color[0], emissive_color[1], emissive_color[2]);
    mat.kr = reflectivity;
    mat.kt = refractivity;
    mat.tr = opacity;
    mat.ns = shininess;
    scene.AddMaterial(name, mat);
}
Beispiel #2
0
Scene* CreateScene(void){
	Scene* scene = new Scene();

	//Initiate materials
	Material* sunMaterial = new Material(
		vec4(0.0f, 0.0f, 0.0f, 0.0f),
		vec4(0.0f, 0.0f, 0.0f, 0.0f),
		vec4(0.0f, 0.0f, 0.0f, 0.0f),
		vec4(1.0f, 1.0f, 0.6f, 1.0f),
		1
	);
	scene->AddMaterial(sunMaterial);

	Material* earthMaterial = new Material(
		vec4(0.04f, 0.04f, 0.2f, 1.0f),
		vec4(0.1f, 0.5f, 0.3f, 1.0f),
		vec4(0.5f, 0.5f, 0.5f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		5
	);
	scene->AddMaterial(earthMaterial);

	Material* moonMaterial = new Material(
		vec4(0.1f, 0.1f, 0.1f, 1.0f),
		vec4(0.5f, 0.5f, 0.5f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		1
	);
	scene->AddMaterial(moonMaterial);

	Material* brickMaterial = new Material(
		vec4(-0.3f, -0.3f, -0.3f, 1.0f),
		vec4(1.5f, 1.5f, 1.5f, 1.0f),
		vec4(1.6f, 1.6f, 1.6f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		20
	);
	scene->AddMaterial(earthMaterial);

	Material* metalMaterial = new Material(
		vec4(0.2f, 0.2f, 0.2f, 1.0f),
		vec4(0.2f, 0.2f, 0.2f, 1.0f),
		vec4(1.0f, 1.0f, 1.0f, 1.0f),
		vec4(0.0f, 0.0f, 0.0f, 1.0f),
		10
	);
	scene->AddMaterial(metalMaterial);

	// Initiate Textures
	Texture* mudBrickTexture = new Texture("Textures/AlternatingMudbrick-ColorMap.png");
	scene->AddTexture(mudBrickTexture);
	Texture* mudBrickNormals = new Texture("Textures/AlternatingMudbrick-NormalMap.png");
	scene->AddTexture(mudBrickNormals);

	Texture* crackedBrickTexture = new Texture("Textures/CrackedAlternatingBricks-ColorMap.png");
	scene->AddTexture(crackedBrickTexture);
	Texture* crackedBrickNormals = new Texture("Textures/CrackedAlternatingBricks-NormalMap.png");
	scene->AddTexture(crackedBrickNormals);

	Texture* sandTexture = new Texture("Textures/Sand_1_Diffuse.png");
	scene->AddTexture(sandTexture);
	Texture* sandNormals = new Texture("Textures/Sand_1_Normal.png");
	scene->AddTexture(sandNormals);

	Texture* heightMap = new Texture("Textures/terrain-heightmap.png");
	//Texture* heightMap = new Texture("Textures/heightmap.png");
	//Texture* heightMap = new Texture("Textures/z.png");
	scene->AddTexture(heightMap);

	// Initiate Models
	/*
	Model* cube = new Cube();
	scene->AddModel(cube);
	*/
	Model* sphere = new Sphere(24);
	scene->AddModel(sphere);
	Model3DS* imported = new Model3DS("Model/pine_green_v3.3DS");
	scene->AddModel(imported);
	Model* plane = new Plane(2.0f, 2.0f, 64, 64);
	scene->AddModel(plane);

	Model* heightMapPlane = new HeightMappedPlane(2.0f, 2.0f, 5.0f, 64, 64, heightMap);

	// Initiate TextureSets
	TextureSet* brickBlend = new TextureSet();
	brickBlend->Add(mudBrickTexture, 2.0f);
	brickBlend->Add(crackedBrickTexture, 2.0f);

	TextureSet* blankTextureSet = new TextureSet();

	TextureSet* brickBlendNormals = new TextureSet();
	brickBlendNormals->Add(mudBrickNormals, 2.0f);
	brickBlendNormals->Add(crackedBrickNormals, 2.0f);

	TextureSet* smallBricks = new TextureSet();
	smallBricks->Add(crackedBrickTexture, 0.25f);
	TextureSet* smallBrickNormals = new TextureSet();
	smallBrickNormals->Add(crackedBrickNormals, 0.25f);

	// Initiate Nodes
	//EulerNode* ground = new EulerNode(plane, brickMaterial, brickBlend);
	EulerNode* ground = new EulerNode(heightMapPlane, brickMaterial, brickBlend);
	ground->Position = vec3(0.0f, -10.0f, 0.0f);
	ground->SetNormalMaps(brickBlendNormals);
	
	TextureSwitcher* textureSwitcher = new TextureSwitcher(ground);
	textureSwitcher->AddTextures(mudBrickTexture, mudBrickNormals);
	textureSwitcher->AddTextures(crackedBrickTexture, crackedBrickNormals);
	textureSwitcher->AddTextures(sandTexture, sandNormals);
	scene->AddNode(textureSwitcher);
	
	EulerNode* orb = new EulerNode(sphere, metalMaterial, blankTextureSet);
	//EulerNode* orb = new EulerNode(sphere, metalMaterial, smallBricks);
	orb->Position = vec3(0.0f, 5.0f, 0.0f);
	orb->SetNormalMaps(blankTextureSet);
	//orb->SetNormalMaps(smallBrickNormals);
	orb->Size = 5;
	ground->AddChild(orb);
	
	// Initiate Lights
	PointLight* pointLight = new PointLight();
	SpotLight* spotLight = new SpotLight();
	spotLight->Ambient = vec4(0.3f, 0.3f, 0.3f, 1.0);
	spotLight->Diffuse = vec4(0.5f, 0.5f, 0.3f, 0.0);
	spotLight->Specular = vec4(1.0f, 1.0f, 1.0f, 1.0);
	spotLight->Angle = 55.0f;
	spotLight->Direction = vec3(0.0f, -1.0f, 0.0f);

	scene->AddLight(pointLight);
	scene->AddLight(spotLight);

	EulerNode* spotLightModelNode = new EulerNode(sphere, sunMaterial, blankTextureSet);
	spotLightModelNode->Position = vec3(50.0f, 100.0f, 50.0f);
	spotLightModelNode->SetNormalMaps(blankTextureSet);
	spotLightModelNode->Position = vec3(spotLight->Position);
	scene->AddNode(spotLightModelNode);

	MouseNode* spotLightMover = new MouseNode(spotLightModelNode, GLUT_LEFT_BUTTON, true);
	LightNode* spotLightNode = new LightNode(spotLight, spotLightMover);
	spotLightMover->SetPosition(vec3(5.0f, 5.0f, 5.0f));
	scene->AddNode(spotLightNode);

	EulerNode* pointLightModelNode = new EulerNode(sphere, sunMaterial, blankTextureSet);
	pointLightModelNode->Position = vec3(50.0f, 50.0f, 50.0f);
	pointLightModelNode->SetNormalMaps(blankTextureSet);
	pointLightModelNode->Position = vec3(pointLight->Position);
	scene->AddNode(pointLightModelNode);

	MouseNode* pointLightMover = new MouseNode(pointLightModelNode, GLUT_RIGHT_BUTTON, false);
	LightNode* pointLightNode = new LightNode(pointLight, pointLightMover);
	pointLightMover->SetPosition(vec3(0.0f, 5.0f, 0.0f));
	scene->AddNode(pointLightNode);

	Node* globalControls = new GlobalControls();
	scene->AddNode(globalControls);

	return scene;
}