Browse Source

cleanup level, light, clip assignments

Alexander Rose 2 years ago
parent
commit
e243d71abf
3 changed files with 20 additions and 17 deletions
  1. 5 4
      src/mol-canvas3d/passes/postprocessing.ts
  2. 5 4
      src/mol-gl/renderer.ts
  3. 10 9
      src/mol-util/clip.ts

+ 5 - 4
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 {

+ 5 - 4
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 {

+ 10 - 9
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 }
         };
     }