HTML
xxxxxxxxxx
1
<!-- Navbar -->
2
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-2">
3
<!-- Container wrapper -->
4
<div class="container-fluid">
5
<div class="d-flex">
6
<!-- Toggle button -->
7
<button
8
class="navbar-toggler"
9
type="button"
10
data-mdb-toggle="collapse"
11
data-mdb-target="#navbarSupportedContent"
12
aria-controls="navbarSupportedContent"
13
aria-expanded="false"
14
aria-label="Toggle navigation"
15
>
16
<i class="fas fa-bars"></i>
17
</button>
18
19
<!-- Navbar brand -->
20
<a class="navbar-brand ms-3" href="#">
21
<i class="fas fa-gem text-primary"></i>
22
</a>
23
</div>
24
25
<!-- Collapsible wrapper -->
26
<div class="collapse navbar-collapse" id="navbarSupportedContent">
27
<!-- Left links -->
28
<ul class="navbar-nav me-auto mb-2 ms-2 ps-1 ms-lg-0 ps-lg-0 mb-lg-0">
29
<li class="nav-item">
30
<a class="nav-link" href="#">Dashboard</a>
31
</li>
32
<li class="nav-item">
33
<a class="nav-link" href="#">Team</a>
34
</li>
35
<li class="nav-item">
36
<a class="nav-link" href="#">Projects</a>
37
</li>
38
</ul>
39
<!-- Left links -->
40
</div>
41
<!-- Collapsible wrapper -->
42
43
<!-- Right elements -->
44
<div class="d-flex align-items-center">
45
<button type="button" class="btn btn-link px-3 mb-1 me-2">
46
Login
47
</button>
48
49
<button type="button" class="btn btn-primary mb-1 me-lg-3">
50
Sign up <span class="d-none d-lg-inline-block">for free</span>
51
</button>
52
</div>
53
<!-- Right elements -->
54
</div>
55
<!-- Container wrapper -->
56
</nav>
57
<!-- Navbar -->
58
59
<div id="three-container"></div>
60
61
<!-- Background image -->
62
<div id="intro" class="bg-image">
63
<div class="mask" style="background-color: rgba(0, 0, 0, 0.7)">
64
<div
65
class="container d-flex align-items-center justify-content-center text-center h-100"
66
>
67
<div class="text-white">
68
<h1 class="mb-3">Learn Bootstrap 5 with MDB</h1>
69
<h5 class="mb-4">Best & free guide of responsive web design</h5>
70
<a
71
class="btn btn-outline-light btn-lg m-2"
72
href="https://www.youtube.com/watch?v=c9B4TPnak1A"
73
role="button"
74
rel="nofollow"
75
target="_blank"
76
>Start tutorial</a
77
>
78
<a
79
class="btn btn-outline-light btn-lg m-2"
80
href="https://mdbootstrap.com/docs/standard/"
81
target="_blank"
82
role="button"
83
>Download MDB UI KIT</a
84
>
85
</div>
86
</div>
87
</div>
88
</div>
89
<!-- Background image -->
90
91
<!--Main layout-->
92
<main class="mt-5">
93
<div class="container">
94
<!--Section: Content-->
95
<section>
96
<div class="row">
97
<div class="col-md-6 gx-5 mb-4">
98
<div class="bg-image hover-overlay ripple shadow-2-strong rounded-5" data-mdb-ripple-color="light">
99
<img src="https://mdbootstrap.com/img/new/slides/031.jpg" class="img-fluid" />
100
<a href="#!">
101
<div class="mask" style="background-color: rgba(251, 251, 251, 0.15);"></div>
102
</a>
103
</div>
104
</div>
105
106
<div class="col-md-6 gx-5 mb-4">
107
<h4><strong>Facilis consequatur eligendi</strong></h4>
108
<p class="text-muted">
109
Lorem ipsum dolor sit amet consectetur adipisicing elit. Facilis consequatur
110
eligendi quisquam doloremque vero ex debitis veritatis placeat unde animi laborum
111
sapiente illo possimus, commodi dignissimos obcaecati illum maiores corporis.
112
</p>
113
<p><strong>Doloremque vero ex debitis veritatis?</strong></p>
114
<p class="text-muted">
115
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quod itaque voluptate
116
nesciunt laborum incidunt. Officia, quam consectetur. Earum eligendi aliquam illum
117
alias, unde optio accusantium soluta, iusto molestiae adipisci et?
118
</p>
119
</div>
120
</div>
121
</section>
122
<!--Section: Content-->
123
124
<hr class="my-5" />
125
126
<!--Section: Content-->
127
<section class="text-center">
128
<h4 class="mb-5"><strong>Facilis consequatur eligendi</strong></h4>
129
130
<div class="row">
131
<div class="col-lg-4 col-md-12 mb-4">
132
<div class="card">
133
<div class="bg-image hover-overlay ripple" data-mdb-ripple-color="light">
134
<img src="https://mdbootstrap.com/img/new/standard/nature/184.jpg" class="img-fluid" />
135
<a href="#!">
136
<div class="mask" style="background-color: rgba(251, 251, 251, 0.15);"></div>
137
</a>
138
</div>
139
<div class="card-body">
140
<h5 class="card-title">Card title</h5>
141
<p class="card-text">
142
Some quick example text to build on the card title and make up the bulk of the
143
card's content.
144
</p>
145
<a href="#!" class="btn btn-primary">Button</a>
146
</div>
147
</div>
148
</div>
149
150
<div class="col-lg-4 col-md-6 mb-4">
151
<div class="card">
152
<div class="bg-image hover-overlay ripple" data-mdb-ripple-color="light">
153
<img src="https://mdbootstrap.com/img/new/standard/nature/023.jpg" class="img-fluid" />
154
<a href="#!">
155
<div class="mask" style="background-color: rgba(251, 251, 251, 0.15);"></div>
156
</a>
157
</div>
158
<div class="card-body">
159
<h5 class="card-title">Card title</h5>
160
<p class="card-text">
161
Some quick example text to build on the card title and make up the bulk of the
162
card's content.
163
</p>
164
<a href="#!" class="btn btn-primary">Button</a>
165
</div>
166
</div>
167
</div>
168
169
<div class="col-lg-4 col-md-6 mb-4">
170
<div class="card">
171
<div class="bg-image hover-overlay ripple" data-mdb-ripple-color="light">
172
<img src="https://mdbootstrap.com/img/new/standard/nature/111.jpg" class="img-fluid" />
173
<a href="#!">
174
<div class="mask" style="background-color: rgba(251, 251, 251, 0.15);"></div>
175
</a>
176
</div>
177
<div class="card-body">
178
<h5 class="card-title">Card title</h5>
179
<p class="card-text">
180
Some quick example text to build on the card title and make up the bulk of the
181
card's content.
182
</p>
183
<a href="#!" class="btn btn-primary">Button</a>
184
</div>
185
</div>
186
</div>
187
</div>
188
</section>
189
<!--Section: Content-->
190
191
<hr class="my-5" />
192
193
<!--Section: Content-->
194
<section class="mb-5">
195
<h4 class="mb-5 text-center"><strong>Facilis consequatur eligendi</strong></h4>
196
197
<div class="row d-flex justify-content-center">
198
<div class="col-md-6">
199
<form>
200
<!-- 2 column grid layout with text inputs for the first and last names -->
201
<div class="row mb-4">
202
<div class="col">
203
<div class="form-outline">
204
<input type="text" id="form3Example1" class="form-control" />
205
<label class="form-label" for="form3Example1">First name</label>
206
</div>
207
</div>
208
<div class="col">
209
<div class="form-outline">
210
<input type="text" id="form3Example2" class="form-control" />
211
<label class="form-label" for="form3Example2">Last name</label>
212
</div>
213
</div>
214
</div>
215
216
<!-- Email input -->
217
<div class="form-outline mb-4">
218
<input type="email" id="form3Example3" class="form-control" />
219
<label class="form-label" for="form3Example3">Email address</label>
220
</div>
221
222
<!-- Password input -->
223
<div class="form-outline mb-4">
224
<input type="password" id="form3Example4" class="form-control" />
225
<label class="form-label" for="form3Example4">Password</label>
226
</div>
227
228
<!-- Checkbox -->
229
<div class="form-check d-flex justify-content-center mb-4">
230
<input class="form-check-input me-2" type="checkbox" value="" id="form2Example3" checked />
231
<label class="form-check-label" for="form2Example3">
232
Subscribe to our newsletter
233
</label>
234
</div>
235
236
<!-- Submit button -->
237
<button type="submit" class="btn btn-primary btn-block mb-4">
238
Sign up
239
</button>
240
241
<!-- Register buttons -->
242
<div class="text-center">
243
<p>or sign up with:</p>
244
<button type="button" class="btn btn-primary btn-floating mx-1">
245
<i class="fab fa-facebook-f"></i>
246
</button>
247
248
<button type="button" class="btn btn-primary btn-floating mx-1">
249
<i class="fab fa-google"></i>
250
</button>
251
252
<button type="button" class="btn btn-primary btn-floating mx-1">
253
<i class="fab fa-twitter"></i>
254
</button>
255
256
<button type="button" class="btn btn-primary btn-floating mx-1">
257
<i class="fab fa-github"></i>
258
</button>
259
</div>
260
</form>
261
</div>
262
</div>
263
</section>
264
<!--Section: Content-->
265
</div>
266
</main>
267
<!--Main layout-->
268
269
<!--Footer-->
270
<footer class="bg-light text-lg-start">
271
<div class="py-4 text-center">
272
<a role="button" class="btn btn-primary btn-lg m-2"
273
href="https://www.youtube.com/channel/UC5CF7mLQZhvx8O5GODZAhdA" rel="nofollow" target="_blank">
274
Learn Bootstrap 5
275
</a>
276
<a role="button" class="btn btn-primary btn-lg m-2" href="https://mdbootstrap.com/docs/standard/" target="_blank">
277
Download MDB UI KIT
278
</a>
279
</div>
280
281
<hr class="m-0" />
282
283
<div class="text-center py-4 align-items-center">
284
<p>Follow MDB on social media</p>
285
<a href="https://www.youtube.com/channel/UC5CF7mLQZhvx8O5GODZAhdA" class="btn btn-primary m-1" role="button"
286
rel="nofollow" target="_blank">
287
<i class="fab fa-youtube"></i>
288
</a>
289
<a href="https://www.facebook.com/mdbootstrap" class="btn btn-primary m-1" role="button" rel="nofollow"
290
target="_blank">
291
<i class="fab fa-facebook-f"></i>
292
</a>
293
<a href="https://twitter.com/MDBootstrap" class="btn btn-primary m-1" role="button" rel="nofollow"
294
target="_blank">
295
<i class="fab fa-twitter"></i>
296
</a>
297
<a href="https://github.com/mdbootstrap/mdb-ui-kit" class="btn btn-primary m-1" role="button" rel="nofollow"
298
target="_blank">
299
<i class="fab fa-github"></i>
300
</a>
301
</div>
302
303
<!-- Copyright -->
304
<div class="text-center p-3" style="background-color: rgba(0, 0, 0, 0.2);">
305
© 2020 Copyright:
306
<a class="text-dark" href="https://mdbootstrap.com/">MDBootstrap.com</a>
307
</div>
308
<!-- Copyright -->
309
</footer>
310
<!--Footer-->
CSS
xxxxxxxxxx
1
#three-container {
2
z-index: -2;
3
position: absolute;
4
overflow: hidden;
5
width: 100%;
6
height: 100vh;
7
margin-top: -58.59px;
8
}
9
10
#intro {
11
height: 100vh;
12
margin-top: -58.59px;
13
z-index: -1;
14
}
JS
xxxxxxxxxx
1
// Credits to: https://codepen.io/zadvorsky/pen/qOYqGv
2
3
var mContainer;
4
var mCamera, mRenderer;
5
var mControls;
6
7
var mScene;
8
9
var mParticleCount = 100000; // <-- change this number!
10
var mParticleSystem;
11
12
var mTime = 0.0;
13
var mTimeStep = 1 / 60;
14
var mDuration = 20;
15
16
window.onload = function () {
17
init();
18
};
19
20
function init() {
21
initTHREE();
22
initControls();
23
initParticleSystem();
24
25
requestAnimationFrame(tick);
26
window.addEventListener("resize", resize, false);
27
}
28
29
function initTHREE() {
30
mRenderer = new THREE.WebGLRenderer({ antialias: true });
31
mRenderer.setSize(window.innerWidth, window.innerHeight);
32
33
mContainer = document.getElementById("three-container");
34
mContainer.appendChild(mRenderer.domElement);
35
36
mCamera = new THREE.PerspectiveCamera(
37
60,
38
window.innerWidth / window.innerHeight,
39
0.1,
40
5000
41
);
42
mCamera.position.set(0, 600, 600);
43
44
mScene = new THREE.Scene();
45
46
var light;
47
48
light = new THREE.PointLight(0xffffff, 4, 1000, 2);
49
light.position.set(0, 400, 0);
50
mScene.add(light);
51
}
52
53
function initControls() {
54
mControls = new THREE.OrbitControls(mCamera, mRenderer.domElement);
55
}
56
57
function initParticleSystem() {
58
var prefabGeometry = new THREE.PlaneGeometry(4, 4);
59
var bufferGeometry = new THREE.BAS.PrefabBufferGeometry(
60
prefabGeometry,
61
mParticleCount
62
);
63
64
bufferGeometry.computeVertexNormals();
65
66
// generate additional geometry data
67
var aOffset = bufferGeometry.createAttribute("aOffset", 1);
68
var aStartPosition = bufferGeometry.createAttribute("aStartPosition", 3);
69
var aControlPoint1 = bufferGeometry.createAttribute("aControlPoint1", 3);
70
var aControlPoint2 = bufferGeometry.createAttribute("aControlPoint2", 3);
71
var aEndPosition = bufferGeometry.createAttribute("aEndPosition", 3);
72
var aAxisAngle = bufferGeometry.createAttribute("aAxisAngle", 4);
73
var aColor = bufferGeometry.createAttribute("color", 3);
74
75
var i, j, offset;
76
77
// buffer time offset
78
var delay;
79
80
for (i = 0, offset = 0; i < mParticleCount; i++) {
81
delay = (i / mParticleCount) * mDuration;
82
83
for (j = 0; j < prefabGeometry.vertices.length; j++) {
84
aOffset.array[offset++] = delay;
85
}
86
}
87
88
// buffer start positions
89
var x, y, z;
90
91
for (i = 0, offset = 0; i < mParticleCount; i++) {
92
x = -1000;
93
y = 0;
94
z = 0;
95
96
for (j = 0; j < prefabGeometry.vertices.length; j++) {
97
aStartPosition.array[offset++] = x;
98
aStartPosition.array[offset++] = y;
99
aStartPosition.array[offset++] = z;
100
}
101
}
102
103
// buffer control points
104
105
for (i = 0, offset = 0; i < mParticleCount; i++) {
106
x = THREE.Math.randFloat(-400, 400);
107
y = THREE.Math.randFloat(400, 600);
108
z = THREE.Math.randFloat(-1200, -800);
109
110
for (j = 0; j < prefabGeometry.vertices.length; j++) {
111
aControlPoint1.array[offset++] = x;
112
aControlPoint1.array[offset++] = y;
113
aControlPoint1.array[offset++] = z;
114
}
115
}
116
117
for (i = 0, offset = 0; i < mParticleCount; i++) {
118
x = THREE.Math.randFloat(-400, 400);
119
y = THREE.Math.randFloat(-600, -400);
120
z = THREE.Math.randFloat(800, 1200);
121
122
for (j = 0; j < prefabGeometry.vertices.length; j++) {
123
aControlPoint2.array[offset++] = x;
124
aControlPoint2.array[offset++] = y;
125
aControlPoint2.array[offset++] = z;
126
}
127
}
128
129
// buffer end positions
130
131
for (i = 0, offset = 0; i < mParticleCount; i++) {
132
x = 1000;
133
y = 0;
134
z = 0;
135
136
for (j = 0; j < prefabGeometry.vertices.length; j++) {
137
aEndPosition.array[offset++] = x;
138
aEndPosition.array[offset++] = y;
139
aEndPosition.array[offset++] = z;
140
}
141
}
142
143
// buffer axis angle
144
var axis = new THREE.Vector3();
145
var angle = 0;
146
147
for (i = 0, offset = 0; i < mParticleCount; i++) {
148
axis.x = THREE.Math.randFloatSpread(2);
149
axis.y = THREE.Math.randFloatSpread(2);
150
axis.z = THREE.Math.randFloatSpread(2);
151
axis.normalize();
152
153
angle = Math.PI * THREE.Math.randInt(16, 32);
154
155
for (j = 0; j < prefabGeometry.vertices.length; j++) {
156
aAxisAngle.array[offset++] = axis.x;
157
aAxisAngle.array[offset++] = axis.y;
158
aAxisAngle.array[offset++] = axis.z;
159
aAxisAngle.array[offset++] = angle;
160
}
161
}
162
163
// buffer color
164
var color = new THREE.Color();
165
var h, s, l;
166
167
for (i = 0, offset = 0; i < mParticleCount; i++) {
168
h = i / mParticleCount;
169
s = THREE.Math.randFloat(0.4, 0.6);
170
l = THREE.Math.randFloat(0.4, 0.6);
171
172
color.setHSL(h, s, l);
173
174
for (j = 0; j < prefabGeometry.vertices.length; j++) {
175
aColor.array[offset++] = color.r;
176
aColor.array[offset++] = color.g;
177
aColor.array[offset++] = color.b;
178
}
179
}
180
181
var material = new THREE.BAS.PhongAnimationMaterial(
182
// custom parameters & THREE.MeshPhongMaterial parameters
183
{
184
vertexColors: THREE.VertexColors,
185
shading: THREE.FlatShading,
186
side: THREE.DoubleSide,
187
uniforms: {
188
uTime: { type: "f", value: 0 },
189
uDuration: { type: "f", value: mDuration },
190
},
191
shaderFunctions: [
192
THREE.BAS.ShaderChunk["quaternion_rotation"],
193
THREE.BAS.ShaderChunk["cubic_bezier"],
194
],
195
shaderParameters: [
196
"uniform float uTime;",
197
"uniform float uDuration;",
198
"attribute float aOffset;",
199
"attribute vec3 aStartPosition;",
200
"attribute vec3 aControlPoint1;",
201
"attribute vec3 aControlPoint2;",
202
"attribute vec3 aEndPosition;",
203
"attribute vec4 aAxisAngle;",
204
],
205
shaderVertexInit: [
206
"float tProgress = mod((uTime + aOffset), uDuration) / uDuration;",
207
208
"float angle = aAxisAngle.w * tProgress;",
209
"vec4 tQuat = quatFromAxisAngle(aAxisAngle.xyz, angle);",
210
],
211
shaderTransformNormal: [
212
"objectNormal = rotateVector(tQuat, objectNormal);",
213
],
214
shaderTransformPosition: [
215
"transformed = rotateVector(tQuat, transformed);",
216
"transformed += cubicBezier(aStartPosition, aControlPoint1, aControlPoint2, aEndPosition, tProgress);",
217
],
218
},
219
// THREE.MeshPhongMaterial uniforms
220
{
221
specular: 0xff0000,
222
shininess: 20,
223
}
224
);
225
226
mParticleSystem = new THREE.Mesh(bufferGeometry, material);
227
// because the bounding box of the particle system does not reflect its on-screen size
228
// set this to false to prevent the whole thing from disappearing on certain angles
229
mParticleSystem.frustumCulled = false;
230
231
mScene.add(mParticleSystem);
232
}
233
234
function tick() {
235
update();
236
render();
237
238
mTime += mTimeStep;
239
mTime %= mDuration;
240
241
requestAnimationFrame(tick);
242
}
243
244
function update() {
245
mControls.update();
246
247
mParticleSystem.material.uniforms["uTime"].value = mTime;
248
}
249
250
function render() {
251
mRenderer.render(mScene, mCamera);
252
}
253
254
function resize() {
255
mCamera.aspect = window.innerWidth / window.innerHeight;
256
mCamera.updateProjectionMatrix();
257
258
mRenderer.setSize(window.innerWidth, window.innerHeight);
259
}
260
261
/////////////////////////////
262
// buffer animation system
263
/////////////////////////////
264
265
THREE.BAS = {};
266
267
THREE.BAS.ShaderChunk = {};
268
269
THREE.BAS.ShaderChunk["animation_time"] =
270
"float tDelay = aAnimation.x;\nfloat tDuration = aAnimation.y;\nfloat tTime = clamp(uTime - tDelay, 0.0, tDuration);\nfloat tProgress = ease(tTime, 0.0, 1.0, tDuration);\n";
271
272
THREE.BAS.ShaderChunk["cubic_bezier"] =
273
"vec3 cubicBezier(vec3 p0, vec3 c0, vec3 c1, vec3 p1, float t)\n{\n vec3 tp;\n float tn = 1.0 - t;\n\n tp.xyz = tn * tn * tn * p0.xyz + 3.0 * tn * tn * t * c0.xyz + 3.0 * tn * t * t * c1.xyz + t * t * t * p1.xyz;\n\n return tp;\n}\n";
274
275
THREE.BAS.ShaderChunk["ease_in_cubic"] =
276
"float ease(float t, float b, float c, float d) {\n return c*(t/=d)*t*t + b;\n}\n";
277
278
THREE.BAS.ShaderChunk["ease_in_quad"] =
279
"float ease(float t, float b, float c, float d) {\n return c*(t/=d)*t + b;\n}\n";
280
281
THREE.BAS.ShaderChunk["ease_out_cubic"] =
282
"float ease(float t, float b, float c, float d) {\n return c*((t=t/d - 1.0)*t*t + 1.0) + b;\n}\n";
283
284
THREE.BAS.ShaderChunk["quaternion_rotation"] =
285
"vec3 rotateVector(vec4 q, vec3 v)\n{\n return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);\n}\n\nvec4 quatFromAxisAngle(vec3 axis, float angle)\n{\n float halfAngle = angle * 0.5;\n return vec4(axis.xyz * sin(halfAngle), cos(halfAngle));\n}\n";
286
287
THREE.BAS.PrefabBufferGeometry = function (prefab, count) {
288
THREE.BufferGeometry.call(this);
289
290
this.prefabGeometry = prefab;
291
this.prefabCount = count;
292
this.prefabVertexCount = prefab.vertices.length;
293
294
this.bufferDefaults();
295
};
296
THREE.BAS.PrefabBufferGeometry.prototype = Object.create(
297
THREE.BufferGeometry.prototype
298
);
299
THREE.BAS.PrefabBufferGeometry.prototype.constructor =
300
THREE.BAS.PrefabBufferGeometry;
301
302
THREE.BAS.PrefabBufferGeometry.prototype.bufferDefaults = function () {
303
var prefabFaceCount = this.prefabGeometry.faces.length;
304
var prefabIndexCount = this.prefabGeometry.faces.length * 3;
305
var prefabVertexCount = (this.prefabVertexCount =
306
this.prefabGeometry.vertices.length);
307
var prefabIndices = [];
308
309
//console.log('prefabCount', this.prefabCount);
310
//console.log('prefabFaceCount', prefabFaceCount);
311
//console.log('prefabIndexCount', prefabIndexCount);
312
//console.log('prefabVertexCount', prefabVertexCount);
313
//console.log('triangles', prefabFaceCount * this.prefabCount);
314
315
for (var h = 0; h < prefabFaceCount; h++) {
316
var face = this.prefabGeometry.faces[h];
317
prefabIndices.push(face.a, face.b, face.c);
318
}
319
320
var indexBuffer = new Uint32Array(this.prefabCount * prefabIndexCount);
321
var positionBuffer = new Float32Array(
322
this.prefabCount * prefabVertexCount * 3
323
);
324
325
this.setIndex(new THREE.BufferAttribute(indexBuffer, 1));
326
this.addAttribute("position", new THREE.BufferAttribute(positionBuffer, 3));
327
328
for (var i = 0, offset = 0; i < this.prefabCount; i++) {
329
for (var j = 0; j < prefabVertexCount; j++, offset += 3) {
330
var prefabVertex = this.prefabGeometry.vertices[j];
331
332
positionBuffer[offset] = prefabVertex.x;
333
positionBuffer[offset + 1] = prefabVertex.y;
334
positionBuffer[offset + 2] = prefabVertex.z;
335
}
336
337
for (var k = 0; k < prefabIndexCount; k++) {
338
indexBuffer[i * prefabIndexCount + k] =
339
prefabIndices[k] + i * prefabVertexCount;
340
}
341
}
342
};
343
344
// todo test
345
THREE.BAS.PrefabBufferGeometry.prototype.bufferUvs = function () {
346
var prefabFaceCount = this.prefabGeometry.faces.length;
347
var prefabVertexCount = (this.prefabVertexCount =
348
this.prefabGeometry.vertices.length);
349
var prefabUvs = [];
350
351
for (var h = 0; h < prefabFaceCount; h++) {
352
var face = this.prefabGeometry.faces[h];
353
var uv = this.prefabGeometry.faceVertexUvs[0][h];
354
355
prefabUvs[face.a] = uv[0];
356
prefabUvs[face.b] = uv[1];
357
prefabUvs[face.c] = uv[2];
358
}
359
360
var uvBuffer = this.createAttribute("uv", 2);
361
362
for (var i = 0, offset = 0; i < this.prefabCount; i++) {
363
for (var j = 0; j < prefabVertexCount; j++, offset += 2) {
364
var prefabUv = prefabUvs[j];
365
366
uvBuffer.array[offset] = prefabUv.x;
367
uvBuffer.array[offset + 1] = prefabUv.y;
368
}
369
}
370
};
371
372
/**
373
* based on BufferGeometry.computeVertexNormals
374
* calculate vertex normals for a prefab, and repeat the data in the normal buffer
375
*/
376
THREE.BAS.PrefabBufferGeometry.prototype.computeVertexNormals = function () {
377
var index = this.index;
378
var attributes = this.attributes;
379
var positions = attributes.position.array;
380
381
if (attributes.normal === undefined) {
382
this.addAttribute(
383
"normal",
384
new THREE.BufferAttribute(new Float32Array(positions.length), 3)
385
);
386
}
387
388
var normals = attributes.normal.array;
389
390
var vA,
391
vB,
392
vC,
393
pA = new THREE.Vector3(),
394
pB = new THREE.Vector3(),
395
pC = new THREE.Vector3(),
396
cb = new THREE.Vector3(),
397
ab = new THREE.Vector3();
398
399
var indices = index.array;
400
var prefabIndexCount = this.prefabGeometry.faces.length * 3;
401
402
for (var i = 0; i < prefabIndexCount; i += 3) {
403
vA = indices[i + 0] * 3;
404
vB = indices[i + 1] * 3;
405
vC = indices[i + 2] * 3;
406
407
pA.fromArray(positions, vA);
408
pB.fromArray(positions, vB);
409
pC.fromArray(positions, vC);
410
411
cb.subVectors(pC, pB);
412
ab.subVectors(pA, pB);
413
cb.cross(ab);
414
415
normals[vA] += cb.x;
416
normals[vA + 1] += cb.y;
417
normals[vA + 2] += cb.z;
418
419
normals[vB] += cb.x;
420
normals[vB + 1] += cb.y;
421
normals[vB + 2] += cb.z;
422
423
normals[vC] += cb.x;
424
normals[vC + 1] += cb.y;
425
normals[vC + 2] += cb.z;
426
}
427
428
for (var j = 1; j < this.prefabCount; j++) {
429
for (var k = 0; k < prefabIndexCount; k++) {
430
normals[j * prefabIndexCount + k] = normals[k];
431
}
432
}
433
434
this.normalizeNormals();
435
436
attributes.normal.needsUpdate = true;
437
};
438
439
THREE.BAS.PrefabBufferGeometry.prototype.createAttribute = function (
440
name,
441
itemSize
442
) {
443
var buffer = new Float32Array(
444
this.prefabCount * this.prefabVertexCount * itemSize
445
);
446
var attribute = new THREE.BufferAttribute(buffer, itemSize);
447
448
this.addAttribute(name, attribute);
449
450
return attribute;
451
};
452
453
THREE.BAS.PrefabBufferGeometry.prototype.setAttribute4 = function (name, data) {
454
var offset = 0;
455
var array = this.geometry.attributes[name].array;
456
var i, j;
457
458
for (i = 0; i < data.length; i++) {
459
var v = data[i];
460
461
for (j = 0; j < this.prefabVertexCount; j++) {
462
array[offset++] = v.x;
463
array[offset++] = v.y;
464
array[offset++] = v.z;
465
array[offset++] = v.w;
466
}
467
}
468
469
this.geometry.attributes[name].needsUpdate = true;
470
};
471
THREE.BAS.PrefabBufferGeometry.prototype.setAttribute3 = function (name, data) {
472
var offset = 0;
473
var array = this.geometry.attributes[name].array;
474
var i, j;
475
476
for (i = 0; i < data.length; i++) {
477
var v = data[i];
478
479
for (j = 0; j < this.prefabVertexCount; j++) {
480
array[offset++] = v.x;
481
array[offset++] = v.y;
482
array[offset++] = v.z;
483
}
484
}
485
486
this.geometry.attributes[name].needsUpdate = true;
487
};
488
THREE.BAS.PrefabBufferGeometry.prototype.setAttribute2 = function (name, data) {
489
var offset = 0;
490
var array = this.geometry.attributes[name].array;
491
var i, j;
492
493
for (i = 0; i < this.prefabCount; i++) {
494
var v = data[i];
495
496
for (j = 0; j < this.prefabVertexCount; j++) {
497
array[offset++] = v.x;
498
array[offset++] = v.y;
499
}
500
}
501
502
this.geometry.attributes[name].needsUpdate = true;
503
};
504
505
THREE.BAS.BaseAnimationMaterial = function (parameters) {
506
THREE.ShaderMaterial.call(this);
507
508
this.shaderFunctions = [];
509
this.shaderParameters = [];
510
this.shaderVertexInit = [];
511
this.shaderTransformNormal = [];
512
this.shaderTransformPosition = [];
513
514
this.setValues(parameters);
515
};
516
THREE.BAS.BaseAnimationMaterial.prototype = Object.create(
517
THREE.ShaderMaterial.prototype
518
);
519
THREE.BAS.BaseAnimationMaterial.prototype.constructor =
520
THREE.BAS.BaseAnimationMaterial;
521
522
// abstract
523
THREE.BAS.BaseAnimationMaterial.prototype._concatVertexShader = function () {
524
return "";
525
};
526
527
THREE.BAS.BaseAnimationMaterial.prototype._concatFunctions = function () {
528
return this.shaderFunctions.join("\n");
529
};
530
THREE.BAS.BaseAnimationMaterial.prototype._concatParameters = function () {
531
return this.shaderParameters.join("\n");
532
};
533
THREE.BAS.BaseAnimationMaterial.prototype._concatVertexInit = function () {
534
return this.shaderVertexInit.join("\n");
535
};
536
THREE.BAS.BaseAnimationMaterial.prototype._concatTransformNormal = function () {
537
return this.shaderTransformNormal.join("\n");
538
};
539
THREE.BAS.BaseAnimationMaterial.prototype._concatTransformPosition =
540
function () {
541
return this.shaderTransformPosition.join("\n");
542
};
543
544
THREE.BAS.BaseAnimationMaterial.prototype.setUniformValues = function (values) {
545
for (var key in values) {
546
if (key in this.uniforms) {
547
var uniform = this.uniforms[key];
548
var value = values[key];
549
550
// todo add matrix uniform types
551
switch (uniform.type) {
552
case "c": // color
553
uniform.value.set(value);
554
break;
555
case "v2": // vectors
556
case "v3":
557
case "v4":
558
uniform.value.copy(value);
559
break;
560
case "f": // float
561
case "t": // texture
562
uniform.value = value;
563
}
564
}
565
}
566
};
567
568
THREE.BAS.PhongAnimationMaterial = function (parameters, uniformValues) {
569
THREE.BAS.BaseAnimationMaterial.call(this, parameters);
570
571
var phongShader = THREE.ShaderLib["phong"];
572
573
this.uniforms = THREE.UniformsUtils.merge([
574
phongShader.uniforms,
575
this.uniforms,
576
]);
577
this.lights = true;
578
this.vertexShader = this._concatVertexShader();
579
this.fragmentShader = phongShader.fragmentShader;
580
581
// todo add missing default defines
582
uniformValues.map && (this.defines["USE_MAP"] = "");
583
uniformValues.normalMap && (this.defines["USE_NORMALMAP"] = "");
584
585
this.setUniformValues(uniformValues);
586
};
587
THREE.BAS.PhongAnimationMaterial.prototype = Object.create(
588
THREE.BAS.BaseAnimationMaterial.prototype
589
);
590
THREE.BAS.PhongAnimationMaterial.prototype.constructor =
591
THREE.BAS.PhongAnimationMaterial;
592
593
THREE.BAS.PhongAnimationMaterial.prototype._concatVertexShader = function () {
594
// based on THREE.ShaderLib.phong
595
return [
596
"#define PHONG",
597
598
"varying vec3 vViewPosition;",
599
600
"#ifndef FLAT_SHADED",
601
602
" varying vec3 vNormal;",
603
604
"#endif",
605
606
THREE.ShaderChunk["common"],
607
THREE.ShaderChunk["uv_pars_vertex"],
608
THREE.ShaderChunk["uv2_pars_vertex"],
609
THREE.ShaderChunk["displacementmap_pars_vertex"],
610
THREE.ShaderChunk["envmap_pars_vertex"],
611
THREE.ShaderChunk["lights_phong_pars_vertex"],
612
THREE.ShaderChunk["color_pars_vertex"],
613
THREE.ShaderChunk["morphtarget_pars_vertex"],
614
THREE.ShaderChunk["skinning_pars_vertex"],
615
THREE.ShaderChunk["shadowmap_pars_vertex"],
616
THREE.ShaderChunk["logdepthbuf_pars_vertex"],
617
618
this._concatFunctions(),
619
620
this._concatParameters(),
621
622
"void main() {",
623
624
this._concatVertexInit(),
625
626
THREE.ShaderChunk["uv_vertex"],
627
THREE.ShaderChunk["uv2_vertex"],
628
THREE.ShaderChunk["color_vertex"],
629
THREE.ShaderChunk["beginnormal_vertex"],
630
631
this._concatTransformNormal(),
632
633
THREE.ShaderChunk["morphnormal_vertex"],
634
THREE.ShaderChunk["skinbase_vertex"],
635
THREE.ShaderChunk["skinnormal_vertex"],
636
THREE.ShaderChunk["defaultnormal_vertex"],
637
638
"#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
639
640
" vNormal = normalize( transformedNormal );",
641
642
"#endif",
643
644
THREE.ShaderChunk["begin_vertex"],
645
646
this._concatTransformPosition(),
647
648
THREE.ShaderChunk["displacementmap_vertex"],
649
THREE.ShaderChunk["morphtarget_vertex"],
650
THREE.ShaderChunk["skinning_vertex"],
651
THREE.ShaderChunk["project_vertex"],
652
THREE.ShaderChunk["logdepthbuf_vertex"],
653
654
" vViewPosition = - mvPosition.xyz;",
655
656
THREE.ShaderChunk["worldpos_vertex"],
657
THREE.ShaderChunk["envmap_vertex"],
658
THREE.ShaderChunk["lights_phong_vertex"],
659
THREE.ShaderChunk["shadowmap_vertex"],
660
661
"}",
662
].join("\n");
663
};
664
Console errors: 0