From e243d71abfd1196428e446d1c63efcd030120c40 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Wed, 29 Mar 2023 23:19:27 -0700 Subject: [PATCH] cleanup level, light, clip assignments --- src/mol-canvas3d/passes/postprocessing.ts | 9 +++++---- src/mol-gl/renderer.ts | 9 +++++---- src/mol-util/clip.ts | 19 ++++++++++--------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/mol-canvas3d/passes/postprocessing.ts b/src/mol-canvas3d/passes/postprocessing.ts index 2d130e622..4ec19e94f 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 c1132d310..46c03c3ca 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 b9d0d7cc1..0965f312d 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 } }; } -- GitLab