three-gpu-pathtracer 0.0.3 → 0.0.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-gpu-pathtracer",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Path tracing renderer and utilities for three.js built on top of three-mesh-bvh.",
5
5
  "module": "src/index.js",
6
6
  "main": "build/index.umd.cjs",
@@ -34,7 +34,7 @@
34
34
  "parcel": "^2.4.0",
35
35
  "process": "^0.11.10",
36
36
  "rollup": "^2.70.0",
37
- "three": "^0.139.2"
37
+ "three": "^0.141.0"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "three": "^0.139.2",
@@ -1,106 +1,106 @@
1
- import { BufferGeometry } from 'three';
2
- import { StaticGeometryGenerator, MeshBVH } from 'three-mesh-bvh';
3
- import { setCommonAttributes, getGroupMaterialIndicesAttribute } from '../utils/GeometryPreparationUtils.js';
4
-
5
- export class DynamicPathTracingSceneGenerator {
6
-
7
- get initialized() {
8
-
9
- return Boolean( this.bvh );
10
-
11
- }
12
-
13
- constructor( scene ) {
14
-
15
- this.scene = scene;
16
- this.bvh = null;
17
- this.geometry = new BufferGeometry();
18
- this.materials = null;
19
- this.textures = null;
20
- this.staticGeometryGenerator = new StaticGeometryGenerator( scene );
21
-
22
- }
23
-
24
- reset() {
25
-
26
- this.bvh = null;
27
- this.geometry.dispose();
28
- this.geometry = new BufferGeometry();
29
- this.materials = null;
30
- this.textures = null;
31
- this.staticGeometryGenerator = new StaticGeometryGenerator( this.scene );
32
-
33
- }
34
-
35
- dispose() {}
36
-
37
- generate() {
38
-
39
- const { scene, staticGeometryGenerator, geometry } = this;
40
- if ( this.bvh === null ) {
41
-
42
- const attributes = [ 'position', 'normal', 'tangent', 'uv' ];
43
- scene.traverse( c => {
44
-
45
- if ( c.isMesh ) {
46
-
47
- const normalMapRequired = ! ! c.material.normalMap;
48
- setCommonAttributes( c.geometry, { attributes, normalMapRequired } );
49
-
50
- }
51
-
52
- } );
53
-
54
- const textureSet = new Set();
55
- const materials = staticGeometryGenerator.getMaterials();
56
- materials.forEach( material => {
57
-
58
- for ( const key in material ) {
59
-
60
- const value = material[ key ];
61
- if ( value && value.isTexture ) {
62
-
63
- textureSet.add( value );
64
-
65
- }
66
-
67
- }
68
-
69
- } );
70
-
71
- staticGeometryGenerator.attributes = attributes;
72
- staticGeometryGenerator.generate( geometry );
73
-
74
- const materialIndexAttribute = getGroupMaterialIndicesAttribute( geometry, materials, materials );
75
- geometry.setAttribute( 'materialIndex', materialIndexAttribute );
76
- geometry.clearGroups();
77
-
78
- this.bvh = new MeshBVH( geometry );
79
- this.materials = materials;
80
- this.textures = Array.from( textureSet );
81
-
82
- return {
83
- bvh: this.bvh,
84
- materials: this.materials,
85
- textures: this.textures,
86
- scene,
87
- };
88
-
89
- } else {
90
-
91
- const { bvh } = this;
92
- staticGeometryGenerator.generate( geometry );
93
- bvh.refit();
94
- return {
95
- bvh: this.bvh,
96
- materials: this.materials,
97
- textures: this.textures,
98
- scene,
99
- };
100
-
101
- }
102
-
103
- }
104
-
105
-
106
- }
1
+ import { BufferGeometry } from 'three';
2
+ import { StaticGeometryGenerator, MeshBVH } from 'three-mesh-bvh';
3
+ import { setCommonAttributes, getGroupMaterialIndicesAttribute } from '../utils/GeometryPreparationUtils.js';
4
+
5
+ export class DynamicPathTracingSceneGenerator {
6
+
7
+ get initialized() {
8
+
9
+ return Boolean( this.bvh );
10
+
11
+ }
12
+
13
+ constructor( scene ) {
14
+
15
+ this.scene = scene;
16
+ this.bvh = null;
17
+ this.geometry = new BufferGeometry();
18
+ this.materials = null;
19
+ this.textures = null;
20
+ this.staticGeometryGenerator = new StaticGeometryGenerator( scene );
21
+
22
+ }
23
+
24
+ reset() {
25
+
26
+ this.bvh = null;
27
+ this.geometry.dispose();
28
+ this.geometry = new BufferGeometry();
29
+ this.materials = null;
30
+ this.textures = null;
31
+ this.staticGeometryGenerator = new StaticGeometryGenerator( this.scene );
32
+
33
+ }
34
+
35
+ dispose() {}
36
+
37
+ generate() {
38
+
39
+ const { scene, staticGeometryGenerator, geometry } = this;
40
+ if ( this.bvh === null ) {
41
+
42
+ const attributes = [ 'position', 'normal', 'tangent', 'uv' ];
43
+ scene.traverse( c => {
44
+
45
+ if ( c.isMesh ) {
46
+
47
+ const normalMapRequired = ! ! c.material.normalMap;
48
+ setCommonAttributes( c.geometry, { attributes, normalMapRequired } );
49
+
50
+ }
51
+
52
+ } );
53
+
54
+ const textureSet = new Set();
55
+ const materials = staticGeometryGenerator.getMaterials();
56
+ materials.forEach( material => {
57
+
58
+ for ( const key in material ) {
59
+
60
+ const value = material[ key ];
61
+ if ( value && value.isTexture ) {
62
+
63
+ textureSet.add( value );
64
+
65
+ }
66
+
67
+ }
68
+
69
+ } );
70
+
71
+ staticGeometryGenerator.attributes = attributes;
72
+ staticGeometryGenerator.generate( geometry );
73
+
74
+ const materialIndexAttribute = getGroupMaterialIndicesAttribute( geometry, materials, materials );
75
+ geometry.setAttribute( 'materialIndex', materialIndexAttribute );
76
+ geometry.clearGroups();
77
+
78
+ this.bvh = new MeshBVH( geometry );
79
+ this.materials = materials;
80
+ this.textures = Array.from( textureSet );
81
+
82
+ return {
83
+ bvh: this.bvh,
84
+ materials: this.materials,
85
+ textures: this.textures,
86
+ scene,
87
+ };
88
+
89
+ } else {
90
+
91
+ const { bvh } = this;
92
+ staticGeometryGenerator.generate( geometry );
93
+ bvh.refit();
94
+ return {
95
+ bvh: this.bvh,
96
+ materials: this.materials,
97
+ textures: this.textures,
98
+ scene,
99
+ };
100
+
101
+ }
102
+
103
+ }
104
+
105
+
106
+ }