Skip to content

Commit 2cd8fec

Browse files
committed
Support single and doubled sided faces
1 parent b00bc14 commit 2cd8fec

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

demosys/scene/loaders/gltf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def load_materials(self):
180180
for mat in self.meta.materials:
181181
m = Material(mat.name)
182182
m.color = mat.baseColorFactor
183+
m.double_sided = mat.doubleSided
183184
if mat.baseColorTexture is not None:
184185
m.mat_texture = self.textures[mat.baseColorTexture['index']]
185186

demosys/scene/shaders.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import os
2+
23
from pyrr import Matrix33
4+
35
from demosys.conf import settings
46
from demosys.resources import shaders
57

8+
from OpenGL import GL
9+
610
settings.add_shader_dir(os.path.join(os.path.dirname(__file__), 'shaders'))
711

812

@@ -51,10 +55,16 @@ def draw(self, mesh, proj_mat, view_mat):
5155

5256
mesh.vao.bind(self.shader)
5357

54-
if mesh.material and mesh.material.color:
55-
self.shader.uniform_4fv("color", mesh.material.color)
56-
else:
57-
self.shader.uniform_4fv("color", [1.0, 1.0, 1.0, 1.0])
58+
if mesh.material:
59+
if mesh.material.double_sided:
60+
GL.glDisable(GL.GL_CULL_FACE)
61+
else:
62+
GL.glEnable(GL.GL_CULL_FACE)
63+
64+
if mesh.material.color:
65+
self.shader.uniform_4fv("color", mesh.material.color)
66+
else:
67+
self.shader.uniform_4fv("color", [1.0, 1.0, 1.0, 1.0])
5868

5969
self.shader.uniform_mat4("m_proj", proj_mat)
6070
self.shader.uniform_mat4("m_mv", view_mat)
@@ -81,6 +91,11 @@ def __init__(self, shader=None, **kwargs):
8191
def draw(self, mesh, proj_mat, view_mat):
8292
m_normal = self.create_normal_matrix(view_mat)
8393

94+
if mesh.material.double_sided:
95+
GL.glDisable(GL.GL_CULL_FACE)
96+
else:
97+
GL.glEnable(GL.GL_CULL_FACE)
98+
8499
mesh.vao.bind(self.shader)
85100
self.shader.uniform_sampler_2d(0, "texture0", mesh.material.mat_texture.texture,
86101
sampler=mesh.material.mat_texture.sampler)

0 commit comments

Comments
 (0)