Bläddra i källkod

wip, primities, dedocahedron

Alexander Rose 6 år sedan
förälder
incheckning
51eece0ee2

+ 10 - 0
src/mol-geo/primitive/cage.ts

@@ -0,0 +1,10 @@
+/**
+ * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
+ */
+
+export interface Cage {
+    vertices: ArrayLike<number>
+    edges: ArrayLike<number>
+}

+ 47 - 0
src/mol-geo/primitive/dodecahedron.ts

@@ -0,0 +1,47 @@
+/**
+ * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
+ */
+
+import { createPrimitive, Primitive } from './primitive';
+
+const t = (1 + Math.sqrt(5)) / 2;
+
+const a = 0.5;
+const b = 0.5 * 1 / t;
+const c = 0.5 * (2 - t);
+
+const dodecahedronVertices: ReadonlyArray<number> = [
+     c, 0, a,    -c, 0, a,    -b, b, b,    0, a, c,     b, b, b,
+     b, -b, b,    0, -a, c,   -b, -b, b,   c, 0, -a,   -c, 0, -a,
+    -b, -b, -b,   0, -a, -c,   b, -b, -b,  b,  b, -b,   0, a, -c,
+    -b, b, -b,    a, c, 0,    -a, c, 0,   -a, -c, 0,    a, -c, 0
+];
+
+const dodecahedronIndices: ReadonlyArray<number> = [
+    4, 3, 2,      2, 1, 0,     4, 2, 0,    // 4, 3, 2, 1, 0
+    7, 6, 5,      5, 0, 1,     7, 5, 1,    // 7, 6, 5, 0, 1
+    12, 11, 10,  10, 9, 8,    12, 10, 8,   // 12, 11, 10, 9, 8
+    15, 14, 13,  13, 8, 9,    15, 13, 9,   // 15, 14, 13, 8, 9
+    14, 3, 4,     4, 16, 13,  14, 4, 13,   // 14, 3, 4, 16, 13
+    3, 14, 15,   15, 17, 2,    3, 15, 2,   // 3, 14, 15, 17, 2
+    11, 6, 7,     7, 18, 10,  11, 7, 10,   // 11, 6, 7, 18, 10
+    6, 11, 12,   12, 19, 5,    6, 12, 5,   // 6, 11, 12, 19, 5
+    4, 0, 5,      5, 19, 16,   4, 5, 16,   // 4, 0, 5, 19, 16
+    12, 8, 13,   13, 16, 19,  12, 13, 19,  // 12, 8, 13, 16, 19
+    15, 9, 10,   10, 18, 17,  15, 10, 17,  // 15, 9, 10, 18, 17
+    7, 1, 2,      2, 17, 18,   7, 2, 18,   // 7, 1, 2, 17, 18
+];
+
+// const dodecahedronEdgeIndices: ReadonlyArray<number> = [
+//     0, 1,   0, 4,   0, 5,   1, 2,   1, 7,   2, 3,   2, 17,  3, 4,   3, 14,  4, 16,
+//     5, 6,   5, 19,  6, 7,   6, 11,  7, 18,  8, 9,   8, 12,  8, 13,  9, 10,  9, 15,
+//     0, 11,  0, 18,  1, 12,  2, 19,  3, 14,  3, 16,  4, 15,  5, 17,  6, 19,  7, 18,
+// ]
+
+let dodecahedron: Primitive
+export function Dodecahedron(): Primitive {
+    if (!dodecahedron) dodecahedron = createPrimitive(dodecahedronVertices, dodecahedronIndices)
+    return dodecahedron
+}

+ 6 - 4
src/mol-geo/primitive/icosahedron.ts

@@ -6,7 +6,7 @@
 
 import { createPrimitive, Primitive } from './primitive';
 
-const t = ( 1 + Math.sqrt( 5 ) ) / 2;
+const t = (1 + Math.sqrt(5)) / 2;
 
 const icosahedronVertices: ReadonlyArray<number> = [
     -1, t, 0,   1, t, 0,  -1, -t, 0,   1, -t, 0,
@@ -21,6 +21,8 @@ const icosahedronIndices: ReadonlyArray<number> = [
     4, 9, 5,   2, 4, 11,   6, 2, 10,   8, 6, 7,   9, 8, 1
 ];
 
-const icosahedron = createPrimitive(icosahedronVertices, icosahedronIndices)
-
-export function Icosahedron(): Primitive { return icosahedron }
+let icosahedron: Primitive
+export function Icosahedron(): Primitive {
+    if (!icosahedron) icosahedron = createPrimitive(icosahedronVertices, icosahedronIndices)
+    return icosahedron
+}

+ 2 - 1
src/tests/browser/render-shape.ts

@@ -15,6 +15,7 @@ import { ColorNames } from 'mol-util/color/tables';
 import { Mesh } from 'mol-geo/geometry/mesh/mesh';
 import { labelFirst } from 'mol-theme/label';
 import { RuntimeContext, Progress } from 'mol-task';
+import { Dodecahedron } from 'mol-geo/primitive/dodecahedron';
 
 const parent = document.getElementById('app')!
 parent.style.width = '100%'
@@ -56,7 +57,7 @@ async function getSphereMesh(ctx: RuntimeContext, centers: number[], mesh?: Mesh
     const builderState = MeshBuilder.createState(centers.length * 128, centers.length * 128 / 2, mesh)
     const t = Mat4.identity()
     const v = Vec3.zero()
-    const sphere = Sphere(2)
+    const sphere = Dodecahedron() // Sphere(2)
     builderState.currentGroup = 0
     for (let i = 0, il = centers.length / 3; i < il; ++i) {
         // for production, calls to update should be guarded by `if (ctx.shouldUpdate)`