|
@@ -7,12 +7,13 @@
|
|
|
import { Vec3 } from 'mol-math/linear-algebra'
|
|
|
import { Primitive, PrimitiveBuilder } from './primitive';
|
|
|
import { polygon } from './polygon'
|
|
|
+import { Cage } from './cage';
|
|
|
|
|
|
const on = Vec3.create(0, 0, -0.5), op = Vec3.create(0, 0, 0.5)
|
|
|
const a = Vec3.zero(), b = Vec3.zero(), c = Vec3.zero(), d = Vec3.zero()
|
|
|
|
|
|
/**
|
|
|
- * Create a prism with a polygonal base of 4 or more points
|
|
|
+ * Create a prism with a base of 4 or more points
|
|
|
*/
|
|
|
export function Prism(points: ArrayLike<number>): Primitive {
|
|
|
const sideCount = points.length / 3
|
|
@@ -62,4 +63,58 @@ let hexagonalPrism: Primitive
|
|
|
export function HexagonalPrism() {
|
|
|
if (!hexagonalPrism) hexagonalPrism = Prism(polygon(6, true))
|
|
|
return hexagonalPrism
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+
|
|
|
+/**
|
|
|
+ * Create a prism cage
|
|
|
+ */
|
|
|
+export function PrismCage(points: ArrayLike<number>): Cage {
|
|
|
+ const sideCount = points.length / 3
|
|
|
+
|
|
|
+ // const count = 4 * sideCount
|
|
|
+ const vertices: number[] = []
|
|
|
+ const edges: number[] = []
|
|
|
+
|
|
|
+ let offset = 0
|
|
|
+
|
|
|
+ // vertices and side edges
|
|
|
+ for (let i = 0; i < sideCount; ++i) {
|
|
|
+ vertices.push(
|
|
|
+ points[i * 3], points[i * 3 + 1], -0.5,
|
|
|
+ points[i * 3], points[i * 3 + 1], 0.5
|
|
|
+ )
|
|
|
+ edges.push(offset, offset + 1)
|
|
|
+ offset += 2
|
|
|
+ }
|
|
|
+
|
|
|
+ // bases edges
|
|
|
+ for (let i = 0; i < sideCount; ++i) {
|
|
|
+ const ni = (i + 1) % sideCount
|
|
|
+ edges.push(
|
|
|
+ i * 2, ni * 2,
|
|
|
+ i * 2 + 1, ni * 2 + 1
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ return { vertices, edges }
|
|
|
+}
|
|
|
+
|
|
|
+let diamondCage: Cage
|
|
|
+export function DiamondPrismCage() {
|
|
|
+ if (!diamondCage) diamondCage = PrismCage(polygon(4, false))
|
|
|
+ return diamondCage
|
|
|
+}
|
|
|
+
|
|
|
+let pentagonalPrismCage: Cage
|
|
|
+export function PentagonalPrismCage() {
|
|
|
+ if (!pentagonalPrismCage) pentagonalPrismCage = PrismCage(polygon(5, false))
|
|
|
+ return pentagonalPrismCage
|
|
|
+}
|
|
|
+
|
|
|
+let hexagonalPrismCage: Cage
|
|
|
+export function HexagonalPrismCage() {
|
|
|
+ if (!hexagonalPrismCage) hexagonalPrismCage = PrismCage(polygon(6, true))
|
|
|
+ return hexagonalPrismCage
|
|
|
}
|