diff --git a/src/mol-canvas3d/passes/postprocessing.ts b/src/mol-canvas3d/passes/postprocessing.ts index 2d130e622382e47667abf8fa66d233eafaee5bcb..4ec19e94fbd1707db6bb42745f60bb9653201df0 100644 --- a/src/mol-canvas3d/passes/postprocessing.ts +++ b/src/mol-canvas3d/passes/postprocessing.ts @@ -411,17 +411,18 @@ type Levels = { } function getLevels(props: { radius: number, bias: number }[], levels?: Levels): Levels { + const count = props.length; const { radius, bias } = levels || { - radius: (new Array(5 * 3)).fill(0), - bias: (new Array(5 * 3)).fill(0), + radius: (new Array(count * 3)).fill(0), + bias: (new Array(count * 3)).fill(0), }; props = props.slice().sort((a, b) => a.radius - b.radius); - for (let i = 0, il = props.length; i < il; ++i) { + for (let i = 0; i < count; ++i) { const p = props[i]; radius[i] = Math.pow(2, p.radius); bias[i] = p.bias; } - return { count: props.length, radius, bias }; + return { count, radius, bias }; } export class PostprocessingPass { diff --git a/src/mol-gl/renderer.ts b/src/mol-gl/renderer.ts index c1132d310e464de6dcdc6e1946186d67c311ac71..46c03c3cab6c529a8a05681ef0a6c9e66385b748 100644 --- a/src/mol-gl/renderer.ts +++ b/src/mol-gl/renderer.ts @@ -131,18 +131,19 @@ export type Light = { const tmpDir = Vec3(); const tmpColor = Vec3(); function getLight(props: RendererProps['light'], light?: Light): Light { + const count = props.length; const { direction, color } = light || { - direction: (new Array(5 * 3)).fill(0), - color: (new Array(5 * 3)).fill(0), + direction: (new Array(count * 3)).fill(0), + color: (new Array(count * 3)).fill(0), }; - for (let i = 0, il = props.length; i < il; ++i) { + for (let i = 0; i < count; ++i) { const p = props[i]; Vec3.directionFromSpherical(tmpDir, degToRad(p.inclination), degToRad(p.azimuth), 1); Vec3.toArray(tmpDir, direction, i * 3); Vec3.scale(tmpColor, Color.toVec3Normalized(tmpColor, p.color), p.intensity); Vec3.toArray(tmpColor, color, i * 3); } - return { count: props.length, direction, color }; + return { count, direction, color }; } namespace Renderer { diff --git a/src/mol-util/clip.ts b/src/mol-util/clip.ts index b9d0d7cc1f2cb4bc5f75448fdeaf2f8a07c43358..0965f312d99a9530d82fdab7b9111d18a125dcb8 100644 --- a/src/mol-util/clip.ts +++ b/src/mol-util/clip.ts @@ -56,14 +56,14 @@ export namespace Clip { export type Params = typeof Params export type Props = PD.Values<Params> - function createClipObjects() { + function createClipObjects(count: number) { return { count: 0, - type: (new Array(5)).fill(1), - invert: (new Array(5)).fill(false), - position: (new Array(5 * 3)).fill(0), - rotation: (new Array(5 * 4)).fill(0), - scale: (new Array(5 * 3)).fill(1), + type: (new Array(count)).fill(1), + invert: (new Array(count)).fill(false), + position: (new Array(count * 3)).fill(0), + rotation: (new Array(count * 4)).fill(0), + scale: (new Array(count * 3)).fill(1), }; } @@ -73,8 +73,9 @@ export namespace Clip { const vB = Vec3(); export function getClip(props: Props, clip?: Clip): Clip { - const { type, invert, position, rotation, scale } = clip?.objects || createClipObjects(); - for (let i = 0, il = props.objects.length; i < il; ++i) { + const count = props.objects.length; + const { type, invert, position, rotation, scale } = clip?.objects || createClipObjects(count); + for (let i = 0; i < count; ++i) { const p = props.objects[i]; type[i] = Type[p.type]; invert[i] = p.invert; @@ -84,7 +85,7 @@ export namespace Clip { } return { variant: props.variant, - objects: { count: props.objects.length, type, invert, position, rotation, scale } + objects: { count, type, invert, position, rotation, scale } }; }