Skip to content
Snippets Groups Projects
Commit ad968f10 authored by Alexander Rose's avatar Alexander Rose
Browse files

wip, cage primitives

parent 147f1fb6
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@
import { Vec3 } from 'mol-math/linear-algebra'
import { Primitive, PrimitiveBuilder } from './primitive';
import { polygon } from './polygon'
import { Cage, createCage } from './cage';
const a = Vec3.zero(), b = Vec3.zero(), c = Vec3.zero(), d = Vec3.zero()
const points = polygon(4, true)
......@@ -56,3 +57,27 @@ export function PerforatedBox() {
if (!perforatedBox) perforatedBox = createBox(true)
return perforatedBox
}
let boxCage: Cage
export function BoxCage() {
if (!boxCage) {
boxCage = createCage(
[
0.5, 0.5, -0.5, // bottom
-0.5, 0.5, -0.5,
-0.5, -0.5, -0.5,
0.5, -0.5, -0.5,
0.5, 0.5, 0.5, // top
-0.5, 0.5, 0.5,
-0.5, -0.5, 0.5,
0.5, -0.5, 0.5
],
[
0, 4, 1, 5, 2, 6, 3, 7, // sides
0, 1, 1, 2, 2, 3, 3, 0, // bottom base
4, 5, 5, 6, 6, 7, 7, 4 // top base
]
)
}
return boxCage
}
\ No newline at end of file
......@@ -35,7 +35,7 @@ const dodecahedronIndices: ReadonlyArray<number> = [ // pentagonal faces
7, 1, 2, 2, 17, 18, 7, 2, 18, // 7, 1, 2, 17, 18
];
const dodecahedronEdgeIndices: ReadonlyArray<number> = [
const dodecahedronEdges: 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,
10, 11, 10, 18, 11, 12, 12, 19, 13, 14, 13, 16, 14, 15, 15, 17, 16, 19, 17, 18,
......@@ -47,7 +47,7 @@ export function Dodecahedron(): Primitive {
return dodecahedron
}
const dodecahedronCage = createCage(dodecahedronVertices, dodecahedronEdgeIndices)
const dodecahedronCage = createCage(dodecahedronVertices, dodecahedronEdges)
export function DodecahedronCage(): Cage {
return dodecahedronCage
}
\ No newline at end of file
......@@ -5,6 +5,7 @@
*/
import { createPrimitive, Primitive } from './primitive';
import { Cage, createCage } from './cage';
const t = (1 + Math.sqrt(5)) / 2;
......@@ -21,8 +22,19 @@ const icosahedronIndices: ReadonlyArray<number> = [
4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
];
const icosahedronEdges: ReadonlyArray<number> = [
0, 11, 5, 11, 0, 5, 1, 5, 0, 1, 1, 7, 0, 7, 7, 10, 0, 10, 10, 11,
5, 9, 4, 11, 2, 10, 6, 7, 1, 8, 3, 9, 4, 9, 3, 4, 2, 4, 2, 3,
2, 6, 3, 6, 6, 8, 3, 8, 8, 9, 4, 5, 2, 11, 6, 10, 7, 8, 1, 9
]
let icosahedron: Primitive
export function Icosahedron(): Primitive {
if (!icosahedron) icosahedron = createPrimitive(icosahedronVertices, icosahedronIndices)
return icosahedron
}
const icosahedronCage = createCage(icosahedronVertices, icosahedronEdges)
export function IcosahedronCage(): Cage {
return icosahedronCage
}
\ No newline at end of file
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
* Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { createPrimitive, Primitive } from './primitive';
import { createCage, Cage } from './cage';
export const octahedronVertices: ReadonlyArray<number> = [
0.5, 0, 0, -0.5, 0, 0, 0, 0.5, 0,
0, -0.5, 0, 0, 0, 0.5, 0, 0, -0.5
];
export const octahedronIndices: ReadonlyArray<number> = [
0, 2, 4, 0, 4, 3, 0, 3, 5,
0, 5, 2, 1, 2, 5, 1, 5, 3,
1, 3, 4, 1, 4, 2
];
export const perforatedOctahedronIndices: ReadonlyArray<number> = [
0, 2, 4, 0, 4, 3,
// 0, 3, 5, 0, 5, 2,
......@@ -22,8 +25,25 @@ export const perforatedOctahedronIndices: ReadonlyArray<number> = [
// 1, 3, 4, 1, 4, 2
];
const octahedron = createPrimitive(octahedronVertices, octahedronIndices)
const perforatedOctahedron = createPrimitive(octahedronVertices, perforatedOctahedronIndices)
const octahedronEdges: ReadonlyArray<number> = [
0, 2, 1, 3, 2, 1, 3, 0,
0, 4, 1, 4, 2, 4, 3, 4,
0, 5, 1, 5, 2, 5, 3, 5,
]
let octahedron: Primitive
export function Octahedron(): Primitive {
if (!octahedron) octahedron = createPrimitive(octahedronVertices, octahedronIndices)
return octahedron
}
let perforatedOctahedron: Primitive
export function PerforatedOctahedron(): Primitive {
if (!perforatedOctahedron) perforatedOctahedron = createPrimitive(octahedronVertices, perforatedOctahedronIndices)
return perforatedOctahedron
}
export function Octahedron(): Primitive { return octahedron }
export function PerforatedOctahedron(): Primitive { return perforatedOctahedron }
\ No newline at end of file
const octahedronCage = createCage(octahedronVertices, octahedronEdges)
export function OctahedronCage(): Cage {
return octahedronCage
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment