framework2

Форк
0
88 строк · 2.7 Кб
1
//
2
//  ofxAssimpMeshHelper.cpp
3
//  Created by Lukasz Karluk on 4/12/12.
4
//
5

6
#include "ofxAssimpMeshHelper.h"
7
#include "ofxAssimpUtils.h"
8

9
using std::make_shared;
10
using std::shared_ptr;
11

12
void ofxAssimpMeshHelper::addTexture(ofxAssimpTexture & aAssimpTex){
13

14
	if( aAssimpTex.getTextureType() == aiTextureType_DIFFUSE ){
15
		bool bNeedsDiffuseAdd = false;
16
		if( !hasTexture(aiTextureType_DIFFUSE) ){
17
			bNeedsDiffuseAdd = true;
18
		}
19

20
		//we do this so we can have the diffuse texture in the meshTextures vector but also accessible via the old approach .assimpTexture;
21
		//wouldn't need to do this if we had protected vars :P
22
		assimpTexture = aAssimpTex;
23
		if( bNeedsDiffuseAdd ){
24
			meshTextures.push_back(shared_ptr<ofxAssimpTexture>(&assimpTexture,[](ofxAssimpTexture*){}));
25
		}
26
	}else{
27
		auto otherTex = make_shared<ofxAssimpTexture>();
28
		(*otherTex.get()) = aAssimpTex;
29

30
		meshTextures.push_back(otherTex);
31
	}
32

33
	auto ttype = meshTextures.back()->getTextureType();
34

35
	bool bAmbientOcclusion = false;
36
	bAmbientOcclusion = ttype == 17; //17 = aiTextureType_AMBIENT_OCCLUSION; //use this when we want to support newer assimp only
37

38
	if( ttype == aiTextureType_EMISSIVE ){
39
		material.setEmissiveTexture(meshTextures.back()->getTextureRef());
40
	}
41
	else if( ttype == aiTextureType_NORMALS ){
42
		material.setNormalTexture(meshTextures.back()->getTextureRef());
43
	}
44
	else if( ttype == aiTextureType_LIGHTMAP || bAmbientOcclusion ){
45
		material.setOcclusionTexture(meshTextures.back()->getTextureRef());
46
	}
47
	else if( ttype == aiTextureType_AMBIENT ){
48
		material.setAmbientTexture(meshTextures.back()->getTextureRef());
49
	}
50
	else if( ttype == aiTextureType_SPECULAR ){
51
		material.setSpecularTexture(meshTextures.back()->getTextureRef());
52
	} else if( ttype == 15 ) { //aiTextureType_METALNESS
53
		material.setMetallicTexture(meshTextures.back()->getTextureRef());
54
	} else if(ttype == 16 ) { //aiTextureType_DIFFUSE_ROUGHNESS
55
		material.setRoughnessTexture(meshTextures.back()->getTextureRef());
56
	} else if( ttype == aiTextureType_DISPLACEMENT ) {
57
		material.setDisplacementTexture(meshTextures.back()->getTextureRef());
58
	}
59
}
60

61
bool ofxAssimpMeshHelper::hasTexture(aiTextureType aTexType){
62
	if( aTexType == aiTextureType_DIFFUSE ){
63
		return assimpTexture.hasTexture();
64
	}else{
65
		for( auto & tex : meshTextures ){
66
			if( tex && tex->getTextureType() == aTexType){
67
				return tex->hasTexture();
68
			}
69
		}
70
	}
71
	return false;
72
}
73

74

75
ofTexture & ofxAssimpMeshHelper::getTextureRef(aiTextureType aTexType) {
76

77
	if( aTexType == aiTextureType_DIFFUSE ){
78
		return assimpTexture.getTextureRef();
79
	}else{
80
		for( auto & tex : meshTextures ){
81
			if( tex && tex->getTextureType() == aTexType){
82
				return tex->getTextureRef();
83
			}
84
		}
85
	}
86

87
	return assimpTexture.getTextureRef();
88
}
89

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.