framework2

Форк
0
149 строк · 4.9 Кб
1
//
2
//  ofxFBXMeshMaterial.cpp
3
//  example-BoneControl
4
//
5
//  Created by Nick Hardeman on 7/15/19.
6
//
7

8
#include "ofxFBXMeshMaterial.h"
9

10
//--------------------------------------------------------------
11
void ofxFBXMeshMaterial::setup( ofxFBXSource::MeshMaterial* aSrcMat ) {
12
    setEmissiveColor( aSrcMat->getEmissiveColor() );
13
    setAmbientColor( aSrcMat->getAmbientColor() );
14
    setDiffuseColor( aSrcMat->getDiffuseColor() );
15
    setSpecularColor( aSrcMat->getSpecularColor() );
16
    setShininess( aSrcMat->getShininess() );
17
    _name = aSrcMat->getName();
18
    
19
    if( aSrcMat->hasTexture() ) {
20
        mSrcTexture = aSrcMat->getTexturePtr();
21
    }
22
}
23

24
//--------------------------------------------------------------
25
void ofxFBXMeshMaterial::setTexture( shared_ptr<ofTexture> aUserTex ) {
26
    mUserTex = aUserTex;
27
}
28

29
//--------------------------------------------------------------
30
void ofxFBXMeshMaterial::begin() {
31
    if( !isEnabled() ) return;
32
    if( areMaterialsEnabled() ) ofMaterial::begin();
33
    if( hasTexture() && areTexturesEnabled() ) {
34
//        cout << "ofxFBXMeshMaterial :: " << getName() << " binding the texture " << areMaterialsEnabled() << endl;
35
//        glEnable( GL_TEXTURE_2D );
36
//        glBindTexture(GL_TEXTURE_2D, texture->getTextureData().textureID);
37
//        mSrcTexture->bind();
38
        if( mUserTex && mUserTex->isAllocated() ) mUserTex->bind();
39
        else if( mSrcTexture && mSrcTexture->isAllocated() ) mSrcTexture->bind();
40
    }
41
}
42

43
//--------------------------------------------------------------
44
void ofxFBXMeshMaterial::end() {
45
    if( !isEnabled() ) return;
46
    if( areMaterialsEnabled() ) ofMaterial::end();
47
    if( hasTexture() && areTexturesEnabled() ) {
48
        if( mUserTex && mUserTex->isAllocated() ) mUserTex->unbind();
49
        else if( mSrcTexture && mSrcTexture->isAllocated() ) mSrcTexture->unbind();
50
//        mSrcTexture->unbind();
51
//        glBindTexture( GL_TEXTURE_2D, 0);
52
//        glDisable( GL_TEXTURE_2D );
53
    }
54
}
55

56
//--------------------------------------------------------------
57
bool ofxFBXMeshMaterial::hasTexture() {
58
//    return mSrcTexture != NULL;
59
    if( mUserTex ) return true;
60
    if( mSrcTexture ) return true;
61
    return false;//texture;// != NULL;
62
}
63

64
//--------------------------------------------------------------
65
bool ofxFBXMeshMaterial::hasSourceTexture() {
66
    if( mSrcTexture ) return true;
67
    return false;
68
}
69

70
//--------------------------------------------------------------
71
bool ofxFBXMeshMaterial::hasUserTexture() {
72
    if( mUserTex ) return true;
73
    return false;
74
}
75

76
//--------------------------------------------------------------
77
shared_ptr<ofTexture> ofxFBXMeshMaterial::getUserTexture() {
78
    return mUserTex;
79
}
80

81
//--------------------------------------------------------------
82
shared_ptr<ofxFBXSource::MeshTexture> ofxFBXMeshMaterial::getSrcTexture() {
83
    return mSrcTexture;
84
}
85

86
//--------------------------------------------------------------
87
void ofxFBXMeshMaterial::enableTextures() {
88
    _bTexturesEnabled = true;
89
}
90

91
//--------------------------------------------------------------
92
void ofxFBXMeshMaterial::disableTextures() {
93
    _bTexturesEnabled = false;
94
}
95

96
//--------------------------------------------------------------
97
bool ofxFBXMeshMaterial::areTexturesEnabled() {
98
    return _bTexturesEnabled;
99
}
100

101
//--------------------------------------------------------------
102
void ofxFBXMeshMaterial::enableMaterials() {
103
    _bMaterialsEnabled = true;
104
}
105

106
//--------------------------------------------------------------
107
void ofxFBXMeshMaterial::disableMaterials() {
108
    _bMaterialsEnabled = false;
109
}
110

111
//--------------------------------------------------------------
112
bool ofxFBXMeshMaterial::areMaterialsEnabled() {
113
    return _bMaterialsEnabled;
114
}
115

116
//--------------------------------------------------------------
117
void ofxFBXMeshMaterial::enable() {
118
    _bEnabled = true;
119
}
120

121
//--------------------------------------------------------------
122
void ofxFBXMeshMaterial::disable() {
123
    _bEnabled = false;
124
}
125

126
//--------------------------------------------------------------
127
bool ofxFBXMeshMaterial::isEnabled() {
128
    return _bEnabled;
129
}
130

131
//--------------------------------------------------------------
132
string ofxFBXMeshMaterial::getName() {
133
    return _name;
134
}
135

136
//--------------------------------------------------------------
137
string ofxFBXMeshMaterial::getInfoAsString() {
138
    stringstream ss;
139
    ss << "-- " << getName() << " Material enabled: " << isEnabled() << " material enabled: " << areMaterialsEnabled() << " ----------------------" << endl;
140
    ss << "emissive = " << getEmissiveColor() << endl;
141
    ss << "ambient = " << getAmbientColor() << endl;
142
    ss << "diffuse = " << getDiffuseColor() << endl;
143
    ss << "specular = " << getSpecularColor() << endl;
144
    ss << "shininess = " << getShininess() << endl;
145
    // lets determine if there is a pointer to the src texture //
146
//    ss << "texture = " << _textureName << " enabled: " << areTexturesEnabled() << " has texture: " << hasTexture() << endl;
147
    
148
    return ss.str();
149
}
150

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

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

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

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