@damienmortini/three 0.1.193 → 0.1.195

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,8 @@
1
- import { Object3D, BufferGeometry, BufferAttribute, AnimationMixer, DataTexture, RGBAFormat, FloatType, RGBFormat, Points, Color, Matrix4 } from '../../../three/src/Three.js'
2
- import { quaternionFromMatrix } from '@damienmortini/core/shader/TransformShader.js'
3
- import THREEGPGPUSystem from '../../three/gpgpu/THREEGPGPUSystem.js'
4
- import THREEShaderMaterial from '../../three/material/THREEShaderMaterial.js'
1
+ import { quaternionFromMatrix } from '@damienmortini/core/shader/TransformShader.js';
2
+
3
+ import { AnimationMixer, BufferAttribute, BufferGeometry, Color, DataTexture, FloatType, Matrix4, Object3D, Points, RGBAFormat, RGBFormat } from '../../../three/src/Three.js';
4
+ import THREEGPGPUSystem from '../../three/gpgpu/THREEGPGPUSystem.js';
5
+ import THREEShaderMaterial from '../../three/material/THREEShaderMaterial.js';
5
6
 
6
7
  export default class THREEMotionVectorObject extends Object3D {
7
8
  constructor({
@@ -22,53 +23,54 @@ export default class THREEMotionVectorObject extends Object3D {
22
23
  }),
23
24
  pointCount = undefined,
24
25
  }) {
25
- super()
26
+ super();
26
27
 
27
- this.loop = false
28
+ this.loop = false;
28
29
 
29
- this._pointCount = pointCount
30
+ this._pointCount = pointCount;
30
31
 
31
- this._initialized = false
32
+ this._initialized = false;
32
33
 
33
- const object = gltfData.scene
34
- this._mesh = object
34
+ const object = gltfData.scene;
35
+ this._mesh = object;
35
36
  object.traverse((object) => {
36
37
  if (object.skeleton) {
37
- this._mesh = object
38
- this._mesh.frustumCulled = false
38
+ this._mesh = object;
39
+ this._mesh.frustumCulled = false;
39
40
  }
40
- })
41
+ });
41
42
  // this._mesh.visible = false;
42
- this._mesh.scale.set(0, 0, 0)
43
+ this._mesh.scale.set(0, 0, 0);
43
44
  if (!pointsAttributes) {
44
- pointsAttributes = new Map()
45
+ pointsAttributes = new Map();
45
46
  for (const [name, value] of Object.entries(this._mesh.geometry.attributes)) {
46
47
  pointsAttributes.set(name, {
47
48
  data: value.array,
48
49
  size: value.itemSize,
49
- })
50
+ });
50
51
  }
51
52
  }
52
- this.add(object)
53
+ this.add(object);
53
54
 
54
55
  if (this._pointCount) {
55
56
  for (const attributeData of pointsAttributes.values()) {
56
- const newArray = new attributeData.data.constructor(this._pointCount * attributeData.size)
57
- const stride = attributeData.size
58
- const difference = Math.floor(attributeData.data.length / newArray.length)
57
+ const newArray = new attributeData.data.constructor(this._pointCount * attributeData.size);
58
+ const stride = attributeData.size;
59
+ const difference = Math.floor(attributeData.data.length / newArray.length);
59
60
  for (let index = 0; index < this._pointCount; index++) {
60
61
  for (let componentIndex = 0; componentIndex < stride; componentIndex++) {
61
- newArray[index * stride + componentIndex] = attributeData.data[index * stride * difference + componentIndex]
62
+ newArray[index * stride + componentIndex] = attributeData.data[index * stride * difference + componentIndex];
62
63
  }
63
64
  }
64
- attributeData.data = newArray
65
+ attributeData.data = newArray;
65
66
  }
66
- } else {
67
- const firstAttribute = pointsAttributes.values().next().value
68
- this._pointCount = firstAttribute.data.length / firstAttribute.size
67
+ }
68
+ else {
69
+ const firstAttribute = pointsAttributes.values().next().value;
70
+ this._pointCount = firstAttribute.data.length / firstAttribute.size;
69
71
  }
70
72
 
71
- this._skeleton = this._mesh.skeleton
73
+ this._skeleton = this._mesh.skeleton;
72
74
 
73
75
  // Create bonesTexture manually
74
76
  // https://github.com/mrdoob/three.js/blob/cd41804aa436bb2cfd79797c04985f75c4c63e63/src/renderers/WebGLRenderer.js#L1632
@@ -93,34 +95,34 @@ export default class THREEMotionVectorObject extends Object3D {
93
95
 
94
96
  //
95
97
 
96
- const geometry = new BufferGeometry()
98
+ const geometry = new BufferGeometry();
97
99
 
98
100
  for (const [name, attributeData] of pointsAttributes) {
99
- geometry.setAttribute(name, new BufferAttribute(attributeData.data, attributeData.size))
101
+ geometry.setAttribute(name, new BufferAttribute(attributeData.data, attributeData.size));
100
102
  }
101
103
 
102
- this._points = new Points(geometry, material)
103
- this._points.isSkinnedMesh = true
104
- this._points.skeleton = this._skeleton
105
- this._points.bindMatrix = new Matrix4()
106
- this._points.bindMatrixInverse = new Matrix4()
107
- this._points.visible = false
108
- this._points.frustumCulled = false
109
- this.add(this._points)
110
-
111
- const animation = gltfData.animations[0]
112
- this._animationMixer = new AnimationMixer(object)
113
- this._animationClip = animation
114
- this._animationAction = this._animationMixer.clipAction(this._animationClip)
115
- this._animationAction.play()
116
-
117
- const pointTextures = new Map()
118
- const pointTextureSize = Math.ceil(Math.sqrt(this._pointCount))
104
+ this._points = new Points(geometry, material);
105
+ this._points.isSkinnedMesh = true;
106
+ this._points.skeleton = this._skeleton;
107
+ this._points.bindMatrix = new Matrix4();
108
+ this._points.bindMatrixInverse = new Matrix4();
109
+ this._points.visible = false;
110
+ this._points.frustumCulled = false;
111
+ this.add(this._points);
112
+
113
+ const animation = gltfData.animations[0];
114
+ this._animationMixer = new AnimationMixer(object);
115
+ this._animationClip = animation;
116
+ this._animationAction = this._animationMixer.clipAction(this._animationClip);
117
+ this._animationAction.play();
118
+
119
+ const pointTextures = new Map();
120
+ const pointTextureSize = Math.ceil(Math.sqrt(this._pointCount));
119
121
  for (const [name, attributeData] of pointsAttributes) {
120
- const textureData = new Float32Array(pointTextureSize * pointTextureSize * attributeData.size)
121
- textureData.set(attributeData.data)
122
- const texture = new DataTexture(textureData, pointTextureSize, pointTextureSize, attributeData.size === 3 ? RGBFormat : RGBAFormat, FloatType)
123
- pointTextures.set(name, texture)
122
+ const textureData = new Float32Array(pointTextureSize * pointTextureSize * attributeData.size);
123
+ textureData.set(attributeData.data);
124
+ const texture = new DataTexture(textureData, pointTextureSize, pointTextureSize, attributeData.size === 3 ? RGBFormat : RGBAFormat, FloatType);
125
+ pointTextures.set(name, texture);
124
126
  }
125
127
 
126
128
  this._gpgpuSystem = new THREEGPGPUSystem({
@@ -216,69 +218,70 @@ export default class THREEMotionVectorObject extends Object3D {
216
218
  gl_FragColor = data;
217
219
  `],
218
220
  ],
219
- })
221
+ });
220
222
  this._gpgpuSystem.onBeforeRender = () => {
221
- this._gpgpuSystem.material.boneTexture = this._skeleton.boneTexture
222
- this._gpgpuSystem.material.boneTextureSize = this._skeleton.boneTextureSize
223
- }
223
+ this._gpgpuSystem.material.boneTexture = this._skeleton.boneTexture;
224
+ this._gpgpuSystem.material.boneTextureSize = this._skeleton.boneTextureSize;
225
+ };
224
226
  }
225
227
 
226
228
  get pointCount() {
227
- return this._pointCount
229
+ return this._pointCount;
228
230
  }
229
231
 
230
232
  get dataTexture() {
231
- return this._gpgpuSystem.dataTexture
233
+ return this._gpgpuSystem.dataTexture;
232
234
  }
233
235
 
234
236
  get dataTextureStride() {
235
- return this._gpgpuSystem.stride
237
+ return this._gpgpuSystem.stride;
236
238
  }
237
239
 
238
240
  get dataTextureSize() {
239
- return this._gpgpuSystem.dataTextureSize
241
+ return this._gpgpuSystem.dataTextureSize;
240
242
  }
241
243
 
242
244
  get meshVisible() {
243
- return this._mesh.visible
245
+ return this._mesh.visible;
244
246
  }
245
247
 
246
248
  set meshVisible(value) {
247
- this._mesh.visible = value
249
+ this._mesh.visible = value;
248
250
  }
249
251
 
250
252
  get pointsVisible() {
251
- return this._points.visible
253
+ return this._points.visible;
252
254
  }
253
255
 
254
256
  set pointsVisible(value) {
255
- this._points.visible = value
257
+ this._points.visible = value;
256
258
  }
257
259
 
258
260
  get currentTime() {
259
- return this._animationMixer.time
261
+ return this._animationMixer.time;
260
262
  }
261
263
 
262
264
  set currentTime(value) {
263
265
  if (value >= this._animationClip.duration) {
264
266
  if (this.loop) {
265
- value = 0
266
- } else {
267
- value = this._animationClip.duration
267
+ value = 0;
268
+ }
269
+ else {
270
+ value = this._animationClip.duration;
268
271
  }
269
272
  }
270
- this._animationMixer.setTime(Math.min(value, this._animationClip.duration - .01))
271
- this._update()
273
+ this._animationMixer.setTime(Math.min(value, this._animationClip.duration - 0.01));
274
+ this._update();
272
275
  }
273
276
 
274
277
  _update() {
275
278
  if (!this._points.visible && !this._mesh.visible) {
276
- this._skeleton.update()
279
+ this._skeleton.update();
277
280
  }
278
281
  if (!this._initialized) {
279
- this._gpgpuSystem.update()
280
- this._initialized = true
282
+ this._gpgpuSystem.update();
283
+ this._initialized = true;
281
284
  }
282
- this._gpgpuSystem.update()
285
+ this._gpgpuSystem.update();
283
286
  }
284
287
  }
@@ -1,10 +1,9 @@
1
+ import FrenetSerretFrame from '@damienmortini/math/FrenetSerretFrame.js';
2
+
1
3
  import {
2
4
  Vector3,
3
- } from '../../../three/src/Three.js'
4
-
5
- import THREELine from './THREELine.js'
6
-
7
- import FrenetSerretFrame from '@damienmortini/math/FrenetSerretFrame.js'
5
+ } from '../../../three/src/Three.js';
6
+ import THREELine from './THREELine.js';
8
7
 
9
8
  export default class THREERibbon extends THREELine {
10
9
  constructor({
@@ -20,30 +19,30 @@ export default class THREERibbon extends THREELine {
20
19
  detail,
21
20
  geometry,
22
21
  material,
23
- })
22
+ });
24
23
 
25
- this.head = points[this.points.length - 1].clone()
24
+ this.head = points[this.points.length - 1].clone();
26
25
  }
27
26
 
28
27
  update() {
29
28
  if (!this._initialized) {
30
- super.update()
31
- this._initialized = true
32
- return
29
+ super.update();
30
+ this._initialized = true;
31
+ return;
33
32
  }
34
33
 
35
- this.userData._linePositions.copyWithin(0, 3)
36
- this.userData._lineNormals.copyWithin(0, 3)
34
+ this.userData._linePositions.copyWithin(0, 3);
35
+ this.userData._lineNormals.copyWithin(0, 3);
37
36
 
38
- const headId = this.points.length - 1
39
- this.userData._linePositions[headId * 3] = this.head.x
40
- this.userData._linePositions[headId * 3 + 1] = this.head.y
41
- this.userData._linePositions[headId * 3 + 2] = this.head.z
37
+ const headId = this.points.length - 1;
38
+ this.userData._linePositions[headId * 3] = this.head.x;
39
+ this.userData._linePositions[headId * 3 + 1] = this.head.y;
40
+ this.userData._linePositions[headId * 3 + 2] = this.head.z;
42
41
 
43
42
  FrenetSerretFrame.compute({
44
43
  positions: this.userData._linePositions,
45
44
  normals: this.userData._lineNormals,
46
45
  range: [headId - 3, headId],
47
- })
46
+ });
48
47
  }
49
48
  }
@@ -1,12 +1,13 @@
1
+ import GradientNoiseShader from '@damienmortini/core/shader/noise/GradientNoiseShader.js';
2
+ import SkyShader from '@damienmortini/core/shader/SkyShader.js';
3
+
1
4
  import {
2
5
  BackSide,
6
+ IcosahedronBufferGeometry,
3
7
  Mesh,
4
8
  Vector3,
5
- IcosahedronBufferGeometry,
6
- } from '../../../three/src/Three.js'
7
- import THREEShaderMaterial from '../material/THREEShaderMaterial.js'
8
- import SkyShader from '@damienmortini/core/shader/SkyShader.js'
9
- import GradientNoiseShader from '@damienmortini/core/shader/noise/GradientNoiseShader.js'
9
+ } from '../../../three/src/Three.js';
10
+ import THREEShaderMaterial from '../material/THREEShaderMaterial.js';
10
11
 
11
12
  const skyShader = {
12
13
  uniforms: {
@@ -97,7 +98,7 @@ const skyShader = {
97
98
  gl_FragColor = vec4(skyColor, 1.);
98
99
  `],
99
100
  ],
100
- }
101
+ };
101
102
 
102
103
  export default class Sky extends Mesh {
103
104
  constructor({
@@ -108,174 +109,174 @@ export default class Sky extends Mesh {
108
109
  type: 'basic',
109
110
  side: BackSide,
110
111
  shaders,
111
- }, skyShader)))
112
+ }, skyShader)));
112
113
 
113
- this._radius = radius
114
+ this._radius = radius;
114
115
 
115
- this.sunInclination = Math.PI * .5
116
- this.sunAzimuth = 0
116
+ this.sunInclination = Math.PI * 0.5;
117
+ this.sunAzimuth = 0;
117
118
 
118
- this.moonInclination = Math.PI * .5
119
- this.moonAzimuth = Math.PI
119
+ this.moonInclination = Math.PI * 0.5;
120
+ this.moonAzimuth = Math.PI;
120
121
  }
121
122
 
122
123
  get radius() {
123
- return this._radius
124
+ return this._radius;
124
125
  }
125
126
 
126
127
  _updatePositionFromInclinationAzimuth(position, inclination, azimuth) {
127
- const theta = inclination
128
- const phi = azimuth + Math.PI * .5
129
- position.x = this._radius * Math.cos(phi) * Math.cos(theta)
130
- position.y = this._radius * Math.sin(theta)
131
- position.z = this._radius * Math.sin(phi) * Math.cos(theta)
128
+ const theta = inclination;
129
+ const phi = azimuth + Math.PI * 0.5;
130
+ position.x = this._radius * Math.cos(phi) * Math.cos(theta);
131
+ position.y = this._radius * Math.sin(theta);
132
+ position.z = this._radius * Math.sin(phi) * Math.cos(theta);
132
133
  }
133
134
 
134
135
  get displaySun() {
135
- return this.material.displaySun === 1
136
+ return this.material.displaySun === 1;
136
137
  }
137
138
 
138
139
  set displaySun(value) {
139
- this.material.displaySun = value ? 1 : 0
140
+ this.material.displaySun = value ? 1 : 0;
140
141
  }
141
142
 
142
143
  get displayMoon() {
143
- return this.material.displayMoon === 1
144
+ return this.material.displayMoon === 1;
144
145
  }
145
146
 
146
147
  set displayMoon(value) {
147
- this.material.displayMoon = value ? 1 : 0
148
+ this.material.displayMoon = value ? 1 : 0;
148
149
  }
149
150
 
150
151
  get sunInclination() {
151
- return this._sunInclination
152
+ return this._sunInclination;
152
153
  }
153
154
 
154
155
  set sunInclination(value) {
155
- this._sunInclination = value
156
- this._updatePositionFromInclinationAzimuth(this.sunPosition, this.sunInclination, this.sunAzimuth)
156
+ this._sunInclination = value;
157
+ this._updatePositionFromInclinationAzimuth(this.sunPosition, this.sunInclination, this.sunAzimuth);
157
158
  }
158
159
 
159
160
  get sunAzimuth() {
160
- return this._sunAzimuth
161
+ return this._sunAzimuth;
161
162
  }
162
163
 
163
164
  set sunAzimuth(value) {
164
- this._sunAzimuth = value
165
- this._updatePositionFromInclinationAzimuth(this.sunPosition, this.sunInclination, this.sunAzimuth)
165
+ this._sunAzimuth = value;
166
+ this._updatePositionFromInclinationAzimuth(this.sunPosition, this.sunInclination, this.sunAzimuth);
166
167
  }
167
168
 
168
169
  get sunPosition() {
169
- return this.material.sunPosition
170
+ return this.material.sunPosition;
170
171
  }
171
172
 
172
173
  set sunPosition(value) {
173
- this.material.sunPosition = value
174
+ this.material.sunPosition = value;
174
175
  }
175
176
 
176
177
  get sunRayleigh() {
177
- return this.material.sunRayleigh
178
+ return this.material.sunRayleigh;
178
179
  }
179
180
 
180
181
  set sunRayleigh(value) {
181
- this.material.sunRayleigh = value
182
+ this.material.sunRayleigh = value;
182
183
  }
183
184
 
184
185
  get sunTurbidity() {
185
- return this.material.sunTurbidity
186
+ return this.material.sunTurbidity;
186
187
  }
187
188
 
188
189
  set sunTurbidity(value) {
189
- this.material.sunTurbidity = value
190
+ this.material.sunTurbidity = value;
190
191
  }
191
192
 
192
193
  get sunLuminance() {
193
- return this.material.sunLuminance
194
+ return this.material.sunLuminance;
194
195
  }
195
196
 
196
197
  set sunLuminance(value) {
197
- this.material.sunLuminance = value
198
+ this.material.sunLuminance = value;
198
199
  }
199
200
 
200
201
  get sunMieCoefficient() {
201
- return this.material.sunMieCoefficient
202
+ return this.material.sunMieCoefficient;
202
203
  }
203
204
 
204
205
  set sunMieCoefficient(value) {
205
- this.material.sunMieCoefficient = value
206
+ this.material.sunMieCoefficient = value;
206
207
  }
207
208
 
208
209
  get sunMieDirectionalG() {
209
- return this.material.sunMieDirectionalG
210
+ return this.material.sunMieDirectionalG;
210
211
  }
211
212
 
212
213
  set sunMieDirectionalG(value) {
213
- this.material.sunMieDirectionalG = value
214
+ this.material.sunMieDirectionalG = value;
214
215
  }
215
216
 
216
217
  get moonInclination() {
217
- return this._moonInclination
218
+ return this._moonInclination;
218
219
  }
219
220
 
220
221
  set moonInclination(value) {
221
- this._moonInclination = value
222
- this._updatePositionFromInclinationAzimuth(this.moonPosition, this.moonInclination, this.moonAzimuth)
222
+ this._moonInclination = value;
223
+ this._updatePositionFromInclinationAzimuth(this.moonPosition, this.moonInclination, this.moonAzimuth);
223
224
  }
224
225
 
225
226
  get moonAzimuth() {
226
- return this._moonAzimuth
227
+ return this._moonAzimuth;
227
228
  }
228
229
 
229
230
  set moonAzimuth(value) {
230
- this._moonAzimuth = value
231
- this._updatePositionFromInclinationAzimuth(this.moonPosition, this.moonInclination, this.moonAzimuth)
231
+ this._moonAzimuth = value;
232
+ this._updatePositionFromInclinationAzimuth(this.moonPosition, this.moonInclination, this.moonAzimuth);
232
233
  }
233
234
 
234
235
  get moonPosition() {
235
- return this.material.moonPosition
236
+ return this.material.moonPosition;
236
237
  }
237
238
 
238
239
  set moonPosition(value) {
239
- this.material.moonPosition = value
240
+ this.material.moonPosition = value;
240
241
  }
241
242
 
242
243
  get moonRayleigh() {
243
- return this.material.moonRayleigh
244
+ return this.material.moonRayleigh;
244
245
  }
245
246
 
246
247
  set moonRayleigh(value) {
247
- this.material.moonRayleigh = value
248
+ this.material.moonRayleigh = value;
248
249
  }
249
250
 
250
251
  get moonTurbidity() {
251
- return this.material.moonTurbidity
252
+ return this.material.moonTurbidity;
252
253
  }
253
254
 
254
255
  set moonTurbidity(value) {
255
- this.material.moonTurbidity = value
256
+ this.material.moonTurbidity = value;
256
257
  }
257
258
 
258
259
  get moonLuminance() {
259
- return this.material.moonLuminance
260
+ return this.material.moonLuminance;
260
261
  }
261
262
 
262
263
  set moonLuminance(value) {
263
- this.material.moonLuminance = value
264
+ this.material.moonLuminance = value;
264
265
  }
265
266
 
266
267
  get moonMieCoefficient() {
267
- return this.material.moonMieCoefficient
268
+ return this.material.moonMieCoefficient;
268
269
  }
269
270
 
270
271
  set moonMieCoefficient(value) {
271
- this.material.moonMieCoefficient = value
272
+ this.material.moonMieCoefficient = value;
272
273
  }
273
274
 
274
275
  get moonMieDirectionalG() {
275
- return this.material.moonMieDirectionalG
276
+ return this.material.moonMieDirectionalG;
276
277
  }
277
278
 
278
279
  set moonMieDirectionalG(value) {
279
- this.material.moonMieDirectionalG = value
280
+ this.material.moonMieDirectionalG = value;
280
281
  }
281
282
  }