Skip to content

Commit b66b26d

Browse files
authored
Merge pull request #490 from redcamel/dev
-
2 parents 5b58df4 + 1682dbb commit b66b26d

File tree

7 files changed

+249
-24
lines changed

7 files changed

+249
-24
lines changed

example/loader/gltf/RedGLTFLoader_polly.html

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232
// 씬 생성
3333
tScene = RedScene(redGL);
3434
// 카메라 생성
35-
tController = RedObitController(redGL);
36-
tController.pan = 25;
37-
tController.tilt = -15;
38-
tController.distance = 5;
39-
tController.speedDistance = 0.1;
35+
tController = RedCamera()
36+
// tController = RedObitController(redGL);
37+
// tController.pan = 25;
38+
// tController.tilt = -15;
39+
// tController.distance = 5;
40+
// tController.speedDistance = 0.1;
4041
// 렌더러 생성
4142
tRenderer = RedRenderer();
4243
// 뷰생성 및 적용
@@ -60,6 +61,11 @@
6061
testDLight.y = 2
6162
testDLight.z = 3
6263
tScene.addLight(testDLight);
64+
testDLight = RedDirectionalLight(redGL)
65+
testDLight.x = 3
66+
testDLight.y = 2
67+
testDLight.z = -3
68+
tScene.addLight(testDLight);
6369
tShadow = RedDirectionalShadow(redGL, testDLight)
6470
tScene.shadowManager.directionalShadow = tShadow
6571
tShadow.size = 500
@@ -68,6 +74,23 @@
6874
testDLight.x = Math.sin(time / 1500) * 1250
6975
testDLight.y = 3500
7076
testDLight.z = Math.cos(time / 1500) * 1250
77+
78+
var tCamera = tView.camera
79+
var cameraMesh = tCamera['_cameraMesh']
80+
var targetMesh = tCamera['_targetMesh']
81+
var parentMesh = tCamera['_parentMesh']
82+
if (cameraMesh) {
83+
tCamera.autoUpdateMatrix = false
84+
tCamera.x = targetMesh.localToWorld(0, 0, 0)[0]
85+
tCamera.y = targetMesh.localToWorld(0, 0, 0)[1]
86+
tCamera.z = targetMesh.localToWorld(0, 0, 0)[2]
87+
tCamera.lookAt(
88+
targetMesh.localToWorld(0, 0, -0.1)[0],
89+
targetMesh.localToWorld(0, 0, -0.1)[1],
90+
targetMesh.localToWorld(0, 0, -0.1)[2]
91+
)
92+
93+
}
7194
});
7295
// 렌더 디버거 활성화
7396
tRenderer.setDebugButton();
@@ -79,6 +102,8 @@
79102
// GLTF 로딩
80103
RedGLTFLoader(this, 'https://cdn.rawgit.com/KhronosGroup/glTF-Blender-Exporter/0e23c773bf27dad67d2c25f060370d6fa012d87d/polly/', 'project_polly.gltf', function (v) {
81104
tScene.addChild(v['resultMesh'])
105+
tView.camera = v['parsingResult']['cameras'][1]
106+
tView.camera.nearClipping = 0.1
82107
})
83108
} else {
84109
console.log('초기화 실패!')

release/RedGL.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8781,10 +8781,11 @@ var RedPBRMaterial_System;
87818781
//#REDGL_DEFINE#roughnessTexture# tRoughnessPower *= roughnessColor.g; // 거칠기 산출 roughnessColor.g
87828782

87838783
// diffuse 색상 산출
8784-
texelColor = u_useVertexColor_0 ? vVertexColor_0 * uBaseColorFactor : uBaseColorFactor;
8784+
texelColor = u_useVertexColor_0 ? clamp(vVertexColor_0,0.0,1.0) * uBaseColorFactor : uBaseColorFactor;
87858785
//#REDGL_DEFINE#diffuseTexture# texelColor *= texture2D(u_diffuseTexture, u_diffuseTexCoord);
87868786
//#REDGL_DEFINE#diffuseTexture# texelColor.rgb *= texelColor.a;
87878787

8788+
87888789
// 노멀값 계산
87898790
N = normalize(vVertexNormal);
87908791
//#REDGL_DEFINE#useMaterialDoubleSide# vec3 fdx = dFdx(vVertexPosition.xyz);
@@ -13031,18 +13032,18 @@ var RedGLTFLoader;
1303113032
// console.log('tAlphaCutoff', tAlphaCutoff)
1303213033
switch (tAlphaMode) {
1303313034
// TODO
13034-
case 'OPAQUE' :
13035-
tMesh.useBlendMode = false
13036-
break
13035+
1303713036
case 'BLEND' :
1303813037
tMesh['useTransparentSort'] = true
1303913038
break
1304013039
case 'MASK' :
13040+
tMesh.useBlendMode = false
1304113041
tMesh['useTransparentSort'] = true
1304213042
tMaterial.cutOff = tAlphaCutoff
1304313043
break
1304413044
default :
1304513045
tMesh.useBlendMode = false
13046+
tMaterial._cutOff = -0.1
1304613047
// tMesh.useBlendMode = false
1304713048
}
1304813049
if (verticesColor_0.length) tMaterial.useVertexColor_0 = true
@@ -23546,4 +23547,4 @@ var RedGLOffScreen;
2354623547
}
2354723548
RedWorkerCode = RedWorkerCode.toString().replace(/^function ?. ?\) ?\{|\}\;?$/g, '');
2354823549
})();
23549-
})();var RedGL_VERSION = {version : 'RedGL Release. last update( 2019-01-21 21:53:18)' };console.log(RedGL_VERSION);
23550+
})();var RedGL_VERSION = {version : 'RedGL Release. last update( 2019-01-26 20:12:37)' };console.log(RedGL_VERSION);

release/RedGL.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rnd/gltfInterpolation_cubic/RedGLTFLoader_InterpolationTest.html

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,25 @@
6868
// assetPath + 'cubemap/SwedishRoyalCastle/pz.jpg',
6969
// assetPath + 'cubemap/SwedishRoyalCastle/nz.jpg'
7070
// ])
71-
// RedGLTFLoader(this, 'https://rawcdn.githack.com/BabylonJS/Exporters/9bc140006be149687be045f60b4a25cdb45ce4fc/Maya/Samples/glTF 2.0/T-Rex/', 'trex_running.gltf', function (v) {
72-
// tScene.addChild(v['resultMesh'])
73-
// })
71+
RedGLTFLoader(this, 'https://cdn.rawgit.com/ft-lab/ft-lab.github.io/c56ef016/gltf/grass/', 'rocks_trees_ao.glb', function (v) {
72+
tScene.addChild(v['resultMesh'])
73+
v['resultMesh'].x = -2
74+
})
75+
RedGLTFLoader(this, 'https://cdn.rawgit.com/mrdoob/three.js/dev/examples/models/gltf/', 'PrimaryIonDrive.glb', function (v) {
76+
tScene.addChild(v['resultMesh'])
77+
v['resultMesh'].x = 2
78+
})
79+
RedGLTFLoader(this, assetPath + 'glTF/basic/', 'VertexColorTest.gltf', function (v) {
80+
tScene.addChild(v['resultMesh'])
81+
v['resultMesh'].z = -4
82+
v['resultMesh'].x = -2
83+
})
84+
RedGLTFLoader(this, 'https://cx20.github.io/gltf-test/sampleModels/BoxVertexColors/glTF-Binary/', 'BoxVertexColors.glb', function (v) {
7485

86+
tScene.addChild(v['resultMesh'])
87+
v['resultMesh'].z = -4
88+
v['resultMesh'].x = 2
89+
})
7590
// RedGLTFLoader(this, 'https://cdn.rawgit.com/mrdoob/rome-gltf/784089b4/files/models/life_soup/', 'quadruped_fox.gltf', function (v) {
7691
// tScene.addChild(v['resultMesh'])
7792
// })
@@ -88,13 +103,19 @@
88103
// v['resultMesh'].z = 2
89104
// })
90105
//
91-
//
92-
RedGLTFLoader(this, assetPath + 'glTF/basic/', 'TextureSettingsTest.gltf', function (v) {
93-
console.log('호잇!', v)
106+
RedGLTFLoader(this, 'https://rawcdn.githack.com/BabylonJS/Exporters/9bc140006be149687be045f60b4a25cdb45ce4fc/Maya/Samples/glTF 2.0/T-Rex/', 'trex_running.gltf', function (v) {
94107
tScene.addChild(v['resultMesh'])
95108

96-
// v['resultMesh'].x = 5
109+
v['resultMesh'].scaleX = v['resultMesh'].scaleY = v['resultMesh'].scaleZ = 0.001
110+
v['resultMesh'].x = -1
97111
})
112+
//
113+
// RedGLTFLoader(this, assetPath + 'glTF/basic/', 'TextureSettingsTest.gltf', function (v) {
114+
// console.log('호잇!', v)
115+
// tScene.addChild(v['resultMesh'])
116+
//
117+
// // v['resultMesh'].x = 5
118+
// })
98119
} else {
99120
console.log('초기화 실패!')
100121
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<html>
2+
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>html</title>
6+
<meta name="apple-mobile-web-app-capable" content="yes"/>
7+
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
8+
<meta name="viewport"
9+
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi"
10+
/>
11+
<style>
12+
html,
13+
body {
14+
margin: 0;
15+
padding: 0;
16+
overflow: hidden;
17+
}
18+
</style>
19+
<script src="../../example/dat.gui.min.js"></script>
20+
<script src="../../release/RedGL.min.js"></script>
21+
22+
23+
</head>
24+
25+
<body>
26+
<canvas id="test" style="border: none;"></canvas>
27+
<script>
28+
document.getElementById('test')
29+
RedGL(document.getElementById('test'), function (v) {
30+
console.log(v)
31+
var tGL;
32+
var tWorld, tScene3D, tCamera
33+
var tRenderer;
34+
var self;
35+
self = this
36+
tGL = this.gl;
37+
this.world = tWorld = RedWorld();
38+
tScene3D = RedScene(this);
39+
tCamera = RedObitController(this);
40+
tCamera.speedDistance = 500
41+
tCamera.distance = 5000
42+
tRenderer = RedRenderer();
43+
tRenderer.setDebugButton()
44+
tWorld.addView(RedView('test', this, tScene3D, tCamera));
45+
RedView('test').setSize('100%', '100%')
46+
RedView('test').setLocation('0%', '0%')
47+
this.renderScale = 1
48+
var testDLight;
49+
testDLight = RedDirectionalLight(this)
50+
testDLight.x = -1500
51+
testDLight.y = 1500
52+
testDLight.z = 1500
53+
testDLight.intensity = 1
54+
tScene3D.addLight(testDLight)
55+
56+
57+
tScene3D.skyBox =
58+
RedSkyBox(this, [
59+
'../../asset/cubemap/SwedishRoyalCastle/px.jpg',
60+
'../../asset/cubemap/SwedishRoyalCastle/nx.jpg',
61+
'../../asset/cubemap/SwedishRoyalCastle/py.jpg',
62+
'../../asset/cubemap/SwedishRoyalCastle/ny.jpg',
63+
'../../asset/cubemap/SwedishRoyalCastle/pz.jpg',
64+
'../../asset/cubemap/SwedishRoyalCastle/nz.jpg'
65+
]);
66+
67+
RedGLTFLoader(self, '../../asset/glTF/breakDance/', 'scene.gltf', function (v) {
68+
console.log('호잇!', v)
69+
var i = 100
70+
71+
while (i--) {
72+
var tMesh = RedMesh(self)
73+
tMesh.children = v['resultMesh'].children
74+
tScene3D.addChild(tMesh)
75+
tMesh.x = Math.random() * 5000 - 2500
76+
tMesh.z = Math.random() * 5000 - 2500
77+
tMesh.rotationY = Math.random() * 360
78+
tMesh.scaleX = tMesh.scaleY = tMesh.scaleZ = 0.3
79+
}
80+
81+
})
82+
83+
84+
RedGLTFLoader(self, '../../asset/glTF/breakDance/', 'scene.gltf', function (v) {
85+
console.log('호잇!', v)
86+
tScene3D.addChild(v['resultMesh'])
87+
var tRoot = v['resultMesh']
88+
89+
var testUI = function (redGL, tScene) {
90+
var gui = self['gui'] = new dat.GUI({
91+
name: 'test'
92+
});
93+
var folder = gui.addFolder('animations')
94+
var testAnimation = {
95+
material: '...'
96+
}
97+
var tList = [
98+
'...',
99+
'RedColorMaterial',
100+
'RedColorPhongMaterial',
101+
'RedColorPhongTextureMaterial',
102+
'RedBitmapMaterial',
103+
'RedStandardMaterial',
104+
'RedEnvironmentMaterial',
105+
'RedSheetMaterial',
106+
'RedVideoMaterial'
107+
]
108+
109+
var targetMaterial
110+
var setMaterial = function (target, reculsive) {
111+
var self = this
112+
if (reculsive) target.children.forEach(function (v) {
113+
if (v['material']) {
114+
v.material = targetMaterial
115+
}
116+
setMaterial(v, reculsive)
117+
})
118+
119+
};
120+
folder.add(testAnimation, 'material', tList).onChange(function (v) {
121+
switch (v) {
122+
case 'RedColorMaterial' :
123+
targetMaterial = RedColorMaterial(self)
124+
break
125+
case 'RedColorPhongMaterial' :
126+
targetMaterial = RedColorPhongMaterial(self)
127+
break
128+
case 'RedColorPhongTextureMaterial' :
129+
targetMaterial = RedColorPhongTextureMaterial(self)
130+
targetMaterial.normalTexture = RedBitmapTexture(self, '../../asset/brick/Brick03_nrm.jpg')
131+
break
132+
case 'RedBitmapMaterial' :
133+
targetMaterial = RedBitmapMaterial(self, RedBitmapTexture(self, '../../asset/glTF/breakDance/textures/Material_baseColor.jpeg'))
134+
break
135+
case 'RedStandardMaterial':
136+
targetMaterial = RedStandardMaterial(self, RedBitmapTexture(self, '../../asset/glTF/breakDance/textures/Material_baseColor.jpeg'))
137+
break
138+
case 'RedEnvironmentMaterial' :
139+
targetMaterial = RedEnvironmentMaterial(
140+
self,
141+
RedBitmapTexture(self, null),
142+
RedBitmapCubeTexture(self, [
143+
'../../asset/cubemap/SwedishRoyalCastle/px.jpg',
144+
'../../asset/cubemap/SwedishRoyalCastle/nx.jpg',
145+
'../../asset/cubemap/SwedishRoyalCastle/py.jpg',
146+
'../../asset/cubemap/SwedishRoyalCastle/ny.jpg',
147+
'../../asset/cubemap/SwedishRoyalCastle/pz.jpg',
148+
'../../asset/cubemap/SwedishRoyalCastle/nz.jpg'
149+
])
150+
)
151+
break
152+
case 'RedSheetMaterial' :
153+
targetMaterial = RedSheetMaterial(self, RedBitmapTexture(self, '../../asset/sheet/spriteSheet.png'), 24, 5, 3, 15)
154+
break
155+
case 'RedVideoMaterial' :
156+
targetMaterial = RedVideoMaterial(self, RedVideoTexture(self, '../../asset/mov_bbb.mp4'))
157+
break
158+
159+
}
160+
tScene3D.children.forEach(function (v) {
161+
setMaterial(v, true)
162+
})
163+
164+
})
165+
///////////////////////////////////////////////
166+
folder.open()
167+
}
168+
testUI()
169+
})
170+
tRenderer.start(this, function (time) {
171+
}
172+
)
173+
})
174+
</script>
175+
</body>
176+
177+
</html>

src/loader/gltf/RedGLTFLoader.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,18 +1646,18 @@ var RedGLTFLoader;
16461646
// console.log('tAlphaCutoff', tAlphaCutoff)
16471647
switch (tAlphaMode) {
16481648
// TODO
1649-
case 'OPAQUE' :
1650-
tMesh.useBlendMode = false
1651-
break
1649+
16521650
case 'BLEND' :
16531651
tMesh['useTransparentSort'] = true
16541652
break
16551653
case 'MASK' :
1654+
tMesh.useBlendMode = false
16561655
tMesh['useTransparentSort'] = true
16571656
tMaterial.cutOff = tAlphaCutoff
16581657
break
16591658
default :
16601659
tMesh.useBlendMode = false
1660+
tMaterial._cutOff = -0.1
16611661
// tMesh.useBlendMode = false
16621662
}
16631663
if (verticesColor_0.length) tMaterial.useVertexColor_0 = true

src/material/system/RedPBRMaterial_System.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,11 @@ var RedPBRMaterial_System;
136136
//#REDGL_DEFINE#roughnessTexture# tRoughnessPower *= roughnessColor.g; // 거칠기 산출 roughnessColor.g
137137
138138
// diffuse 색상 산출
139-
texelColor = u_useVertexColor_0 ? vVertexColor_0 * uBaseColorFactor : uBaseColorFactor;
139+
texelColor = u_useVertexColor_0 ? clamp(vVertexColor_0,0.0,1.0) * uBaseColorFactor : uBaseColorFactor;
140140
//#REDGL_DEFINE#diffuseTexture# texelColor *= texture2D(u_diffuseTexture, u_diffuseTexCoord);
141141
//#REDGL_DEFINE#diffuseTexture# texelColor.rgb *= texelColor.a;
142142
143+
143144
// 노멀값 계산
144145
N = normalize(vVertexNormal);
145146
//#REDGL_DEFINE#useMaterialDoubleSide# vec3 fdx = dFdx(vVertexPosition.xyz);

0 commit comments

Comments
 (0)