Skip to content

Commit afe5db3

Browse files
committed
Clean up, class names, parameter names
1 parent 64e62ff commit afe5db3

File tree

3 files changed

+44
-28
lines changed

3 files changed

+44
-28
lines changed

src/materials/PhysicalPathTracingMaterial.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { PhysicalCameraUniform } from '../uniforms/PhysicalCameraUniform.js';
1616
import { EquirectHdrInfoUniform } from '../uniforms/EquirectHdrInfoUniform.js';
1717
import { LightsInfoUniformStruct } from '../uniforms/LightsInfoUniformStruct.js';
1818
import { IESProfilesTexture } from '../uniforms/IESProfilesTexture.js';
19-
import { ComboAttributesTextureArray } from '../uniforms/ComboAttributesTextureArray.js';
19+
import { AttributesTextureArray } from '../uniforms/AttributesTextureArray.js';
2020

2121
export class PhysicalPathTracingMaterial extends MaterialBase {
2222

@@ -57,7 +57,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
5757
physicalCamera: { value: new PhysicalCameraUniform() },
5858

5959
bvh: { value: new MeshBVHUniformStruct() },
60-
attributesArray: { value: new ComboAttributesTextureArray() },
60+
attributesArray: { value: new AttributesTextureArray() },
6161
materialIndexAttribute: { value: new UIntVertexAttributeTexture() },
6262
materials: { value: new MaterialsTexture() },
6363
textures: { value: new RenderTarget2DArray().texture },

src/uniforms/ComboAttributesTextureArray.js renamed to src/uniforms/AttributesTextureArray.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import { FloatAttributeTextureArray } from './FloatAttributeTextureArray.js';
22

3-
export class ComboAttributesTextureArray extends FloatAttributeTextureArray {
3+
export class AttributesTextureArray extends FloatAttributeTextureArray {
44

5-
setNormalAttribute( attr ) {
5+
updateNormalAttribute( attr ) {
66

77
this.updateAttribute( 0, attr );
88

99
}
1010

11-
setTangentAttribute( attr ) {
11+
updateTangentAttribute( attr ) {
1212

1313
this.updateAttribute( 1, attr );
1414

1515
}
1616

17-
setUvAttribute( attr ) {
17+
updateUvAttribute( attr ) {
1818

1919
this.updateAttribute( 2, attr );
2020

2121
}
2222

23-
setColorAttribute( attr ) {
23+
updateColorAttribute( attr ) {
2424

2525
this.updateAttribute( 3, attr );
2626

src/uniforms/FloatAttributeTextureArray.js

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import { DataArrayTexture, FloatType, RGBAFormat } from 'three';
22
import { FloatVertexAttributeTexture } from 'three-mesh-bvh';
33

4-
function copyArrayToArray( fromArray, fromStride, toArray, offset ) {
4+
function copyArrayToArray( fromArray, fromStride, toArray, toStride, offset ) {
5+
6+
if ( fromStride > toStride ) {
7+
8+
throw new Error();
9+
10+
}
511

612
const count = fromArray.length / fromStride;
713
for ( let i = 0; i < count; i ++ ) {
814

915
const i4 = 4 * i;
1016
const is = fromStride * i;
11-
toArray[ offset + i4 + 0 ] = fromArray[ is + 0 ];
12-
toArray[ offset + i4 + 1 ] = fromStride >= 2 ? fromArray[ is + 1 ] : 0;
13-
toArray[ offset + i4 + 2 ] = fromStride >= 3 ? fromArray[ is + 2 ] : 0;
14-
toArray[ offset + i4 + 3 ] = fromStride >= 4 ? fromArray[ is + 3 ] : 0;
17+
for ( let j = 0; j < toStride; j ++ ) {
18+
19+
toArray[ offset + i4 + j ] = fromStride >= j + 1 ? fromArray[ is + j ] : 0;
20+
21+
}
1522

1623
}
1724

@@ -29,13 +36,23 @@ export class FloatAttributeTextureArray extends DataArrayTexture {
2936

3037
}
3138

32-
updateTexture( index, attr ) {
39+
updateAttribute( index, attr ) {
3340

34-
// update all textures
41+
// update the texture
3542
const tex = this._textures[ index ];
3643
tex.updateFrom( attr );
3744

38-
const { width, height, data } = this.image;
45+
// ensure compatibility
46+
const baseImage = tex.image;
47+
const image = this.image;
48+
if ( baseImage.width !== image.width || baseImage.height !== image.height ) {
49+
50+
throw new Error( 'FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.' );
51+
52+
}
53+
54+
// update the image
55+
const { width, height, data } = image;
3956
const length = width * height * 4;
4057
const offset = length * index;
4158
let itemSize = attr.itemSize;
@@ -45,7 +62,8 @@ export class FloatAttributeTextureArray extends DataArrayTexture {
4562

4663
}
4764

48-
copyArrayToArray( tex.image.data, itemSize, data, offset );
65+
// copy the data
66+
copyArrayToArray( tex.image.data, itemSize, data, 4, offset );
4967

5068
this.dispose();
5169
this.needsUpdate = true;
@@ -90,23 +108,21 @@ export class FloatAttributeTextureArray extends DataArrayTexture {
90108
}
91109

92110
// determine if we need to create a new array
93-
const rootTexture = textures[ 0 ];
94-
let { data, width, depth, height } = this.image;
95-
if ( rootTexture.image.width !== width || rootTexture.image.height !== height || depth !== attrsLength ) {
111+
const baseTexture = textures[ 0 ];
112+
const baseImage = baseTexture.image;
113+
const image = this.image;
96114

97-
width = rootTexture.image.width;
98-
height = rootTexture.image.height;
99-
depth = attrsLength;
100-
data = new Float32Array( width * height * depth * 4 );
115+
if ( baseImage.width !== image.width || baseImage.height !== image.height || baseImage.depth !== attrsLength ) {
101116

102-
this.image.width = width;
103-
this.image.height = height;
104-
this.image.depth = depth;
105-
this.image.data = data;
117+
image.width = baseImage.width;
118+
image.height = baseImage.height;
119+
image.depth = attrsLength;
120+
image.data = new Float32Array( image.width * image.height * image.depth * 4 );
106121

107122
}
108123

109124
// copy the other texture data into the data array texture
125+
const { data, width, height } = image;
110126
for ( let i = 0, l = attrsLength; i < l; i ++ ) {
111127

112128
const tex = textures[ i ];
@@ -120,7 +136,7 @@ export class FloatAttributeTextureArray extends DataArrayTexture {
120136

121137
}
122138

123-
copyArrayToArray( tex.image.data, itemSize, data, offset );
139+
copyArrayToArray( tex.image.data, itemSize, data, 4, offset );
124140

125141
}
126142

0 commit comments

Comments
 (0)