framework2
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//--------------------------------------------------------------
11void ofxFBXMeshMaterial::setup( ofxFBXSource::MeshMaterial* aSrcMat ) {
12setEmissiveColor( aSrcMat->getEmissiveColor() );
13setAmbientColor( aSrcMat->getAmbientColor() );
14setDiffuseColor( aSrcMat->getDiffuseColor() );
15setSpecularColor( aSrcMat->getSpecularColor() );
16setShininess( aSrcMat->getShininess() );
17_name = aSrcMat->getName();
18
19if( aSrcMat->hasTexture() ) {
20mSrcTexture = aSrcMat->getTexturePtr();
21}
22}
23
24//--------------------------------------------------------------
25void ofxFBXMeshMaterial::setTexture( shared_ptr<ofTexture> aUserTex ) {
26mUserTex = aUserTex;
27}
28
29//--------------------------------------------------------------
30void ofxFBXMeshMaterial::begin() {
31if( !isEnabled() ) return;
32if( areMaterialsEnabled() ) ofMaterial::begin();
33if( 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();
38if( mUserTex && mUserTex->isAllocated() ) mUserTex->bind();
39else if( mSrcTexture && mSrcTexture->isAllocated() ) mSrcTexture->bind();
40}
41}
42
43//--------------------------------------------------------------
44void ofxFBXMeshMaterial::end() {
45if( !isEnabled() ) return;
46if( areMaterialsEnabled() ) ofMaterial::end();
47if( hasTexture() && areTexturesEnabled() ) {
48if( mUserTex && mUserTex->isAllocated() ) mUserTex->unbind();
49else if( mSrcTexture && mSrcTexture->isAllocated() ) mSrcTexture->unbind();
50// mSrcTexture->unbind();
51// glBindTexture( GL_TEXTURE_2D, 0);
52// glDisable( GL_TEXTURE_2D );
53}
54}
55
56//--------------------------------------------------------------
57bool ofxFBXMeshMaterial::hasTexture() {
58// return mSrcTexture != NULL;
59if( mUserTex ) return true;
60if( mSrcTexture ) return true;
61return false;//texture;// != NULL;
62}
63
64//--------------------------------------------------------------
65bool ofxFBXMeshMaterial::hasSourceTexture() {
66if( mSrcTexture ) return true;
67return false;
68}
69
70//--------------------------------------------------------------
71bool ofxFBXMeshMaterial::hasUserTexture() {
72if( mUserTex ) return true;
73return false;
74}
75
76//--------------------------------------------------------------
77shared_ptr<ofTexture> ofxFBXMeshMaterial::getUserTexture() {
78return mUserTex;
79}
80
81//--------------------------------------------------------------
82shared_ptr<ofxFBXSource::MeshTexture> ofxFBXMeshMaterial::getSrcTexture() {
83return mSrcTexture;
84}
85
86//--------------------------------------------------------------
87void ofxFBXMeshMaterial::enableTextures() {
88_bTexturesEnabled = true;
89}
90
91//--------------------------------------------------------------
92void ofxFBXMeshMaterial::disableTextures() {
93_bTexturesEnabled = false;
94}
95
96//--------------------------------------------------------------
97bool ofxFBXMeshMaterial::areTexturesEnabled() {
98return _bTexturesEnabled;
99}
100
101//--------------------------------------------------------------
102void ofxFBXMeshMaterial::enableMaterials() {
103_bMaterialsEnabled = true;
104}
105
106//--------------------------------------------------------------
107void ofxFBXMeshMaterial::disableMaterials() {
108_bMaterialsEnabled = false;
109}
110
111//--------------------------------------------------------------
112bool ofxFBXMeshMaterial::areMaterialsEnabled() {
113return _bMaterialsEnabled;
114}
115
116//--------------------------------------------------------------
117void ofxFBXMeshMaterial::enable() {
118_bEnabled = true;
119}
120
121//--------------------------------------------------------------
122void ofxFBXMeshMaterial::disable() {
123_bEnabled = false;
124}
125
126//--------------------------------------------------------------
127bool ofxFBXMeshMaterial::isEnabled() {
128return _bEnabled;
129}
130
131//--------------------------------------------------------------
132string ofxFBXMeshMaterial::getName() {
133return _name;
134}
135
136//--------------------------------------------------------------
137string ofxFBXMeshMaterial::getInfoAsString() {
138stringstream ss;
139ss << "-- " << getName() << " Material enabled: " << isEnabled() << " material enabled: " << areMaterialsEnabled() << " ----------------------" << endl;
140ss << "emissive = " << getEmissiveColor() << endl;
141ss << "ambient = " << getAmbientColor() << endl;
142ss << "diffuse = " << getDiffuseColor() << endl;
143ss << "specular = " << getSpecularColor() << endl;
144ss << "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
148return ss.str();
149}
150