16 this->
setName(
"ObjMeshRenderer");
18 this->varMaterialIndex()->attach(std::make_shared<FCallBackFunc>(
20 uint idx = this->varMaterialIndex()->getValue();
26 this->varAlpha()->setValue(material->alpha);
27 this->varMetallic()->setValue(material->metallic);
28 this->varRoughness()->setValue(material->roughness);
29 this->varBaseColor()->setValue(
Color(material->baseColor.x, material->baseColor.y, material->baseColor.z));
33 this->varMetallic()->attach(
34 std::make_shared<FCallBackFunc>(
36 uint idx = this->varMaterialIndex()->getValue();
42 material->metallic = this->varMetallic()->getValue();
46 this->varRoughness()->attach(
47 std::make_shared<FCallBackFunc>(
49 uint idx = this->varMaterialIndex()->getValue();
55 material->roughness = this->varRoughness()->getValue();
59 this->varAlpha()->attach(
60 std::make_shared<FCallBackFunc>(
62 uint idx = this->varMaterialIndex()->getValue();
68 material->roughness = this->varAlpha()->getValue();
73 mTangentSpaceConstructor = std::make_shared<ConstructTangentSpace>();
74 this->inTextureMesh()->connect(mTangentSpaceConstructor->inTextureMesh());
142 if (this->inTextureMesh()->isModified()) {
143 mTextureMesh.load(this->inTextureMesh()->constDataPtr());
144 this->varMaterialIndex()->setRange(0,
mTextureMesh.materials().size() - 1);
148 auto texMesh = this->inTextureMesh()->constDataPtr();
149 if (texMesh->materials().size() > 0)
151 mTangentSpaceConstructor->update();
153 if (!mTangentSpaceConstructor->outTangent()->isEmpty())
155 mTangent.load(mTangentSpaceConstructor->outTangent()->constData());
156 mBitangent.load(mTangentSpaceConstructor->outBitangent()->constData());
178 if (normals.count() > 0
181 && normals.count() ==
mTangent.count()
185 normals.bindBufferBase(9);
194 vertices.bindBufferBase(8);
195 texCoords.bindBufferBase(10);
198 for (
int i = 0; i < shapes.size(); i++)
200 auto shape = shapes[i];
201 if (shape->material !=
nullptr)
203 auto mtl = shape->material;
217 pbr.color = { mtl->baseColor.x, mtl->baseColor.y, mtl->baseColor.z };
218 pbr.metallic = mtl->metallic;
219 pbr.roughness = mtl->roughness;
220 pbr.alpha = mtl->alpha;
228 glActiveTexture(GL_TEXTURE10);
229 glBindTexture(GL_TEXTURE_2D, 0);
230 glActiveTexture(GL_TEXTURE11);
231 glBindTexture(GL_TEXTURE_2D, 0);
233 if (mtl->texColor.isValid()) {
235 mtl->texColor.bind(GL_TEXTURE10);
238 mtl->texColor.unbind();
242 if (mtl->texBump.isValid()) {
243 mtl->texBump.bind(GL_TEXTURE11);
265 auto color = this->varBaseColor()->getValue();
266 pbr.color = { color.r, color.g, color.b };
267 pbr.metallic = this->varMetallic()->getValue();
268 pbr.roughness = this->varRoughness()->getValue();
269 pbr.alpha = this->varAlpha()->getValue();
277 int numTriangles = shape->glVertexIndex.count();
284 shape->glVertexIndex.bind();
285 glEnableVertexAttribArray(0);
286 glVertexAttribIPointer(0, 1, GL_INT,
sizeof(
int), (
void*)0);
288 if (shape->glNormalIndex.count() == numTriangles) {
289 shape->glNormalIndex.bind();
290 glEnableVertexAttribArray(1);
291 glVertexAttribIPointer(1, 1, GL_INT,
sizeof(
int), (
void*)0);
295 glDisableVertexAttribArray(1);
296 glVertexAttribI4i(1, -1, -1, -1, -1);
299 if (shape->glTexCoordIndex.count() == numTriangles) {
300 shape->glTexCoordIndex.bind();
301 glEnableVertexAttribArray(2);
302 glVertexAttribIPointer(2, 1, GL_INT,
sizeof(
int), (
void*)0);
306 glDisableVertexAttribArray(2);
307 glVertexAttribI4i(2, -1, -1, -1, -1);
311 glDrawArrays(GL_TRIANGLES, 0, numTriangles * 3);