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

added pyramide primitive

parent 5d36a925
Branches
Tags
No related merge requests found
...@@ -8,6 +8,7 @@ import { Vec3 } from 'mol-math/linear-algebra' ...@@ -8,6 +8,7 @@ import { Vec3 } from 'mol-math/linear-algebra'
import { Primitive, PrimitiveBuilder } from './primitive'; import { Primitive, PrimitiveBuilder } from './primitive';
import { polygon } from './polygon' import { polygon } from './polygon'
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() const a = Vec3.zero(), b = Vec3.zero(), c = Vec3.zero(), d = Vec3.zero()
/** /**
...@@ -58,12 +59,10 @@ export function Prism(points: ArrayLike<number>): Primitive { ...@@ -58,12 +59,10 @@ export function Prism(points: ArrayLike<number>): Primitive {
const ni = (i + 1) % sideCount const ni = (i + 1) % sideCount
Vec3.set(a, points[i * 2], points[i * 2 + 1], -0.5) Vec3.set(a, points[i * 2], points[i * 2 + 1], -0.5)
Vec3.set(b, points[ni * 2], points[ni * 2 + 1], -0.5) Vec3.set(b, points[ni * 2], points[ni * 2 + 1], -0.5)
Vec3.set(c, 0, 0, -0.5) builder.add(a, b, on)
builder.add(a, b, c)
Vec3.set(a, points[i * 2], points[i * 2 + 1], 0.5) Vec3.set(a, points[i * 2], points[i * 2 + 1], 0.5)
Vec3.set(b, points[ni * 2], points[ni * 2 + 1], 0.5) Vec3.set(b, points[ni * 2], points[ni * 2 + 1], 0.5)
Vec3.set(c, 0, 0, 0.5) builder.add(op, b, a)
builder.add(c, b, a)
} }
} }
......
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { Vec3 } from 'mol-math/linear-algebra'
import { Primitive, PrimitiveBuilder } from './primitive';
import { polygon } from './polygon'
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 pyramide with a poligonal base
*/
export function Pyramide(points: ArrayLike<number>): Primitive {
const sideCount = points.length / 2
const baseCount = sideCount === 3 ? 1 : sideCount === 4 ? 2 : sideCount
const count = 2 * baseCount + 2 * sideCount
const builder = PrimitiveBuilder(count)
// create sides
for (let i = 0; i < sideCount; ++i) {
const ni = (i + 1) % sideCount
Vec3.set(a, points[i * 2], points[i * 2 + 1], -0.5)
Vec3.set(b, points[ni * 2], points[ni * 2 + 1], -0.5)
builder.add(a, b, op)
}
// create base
if (sideCount === 3) {
Vec3.set(a, points[0], points[1], -0.5)
Vec3.set(b, points[2], points[3], -0.5)
Vec3.set(c, points[4], points[5], -0.5)
builder.add(a, b, c)
} else if (sideCount === 4) {
Vec3.set(a, points[0], points[1], -0.5)
Vec3.set(b, points[2], points[3], -0.5)
Vec3.set(c, points[4], points[5], -0.5)
Vec3.set(d, points[6], points[7], -0.5)
builder.add(a, b, c)
builder.add(c, d, a)
} else {
for (let i = 0; i < sideCount; ++i) {
const ni = (i + 1) % sideCount
Vec3.set(a, points[i * 2], points[i * 2 + 1], -0.5)
Vec3.set(b, points[ni * 2], points[ni * 2 + 1], -0.5)
builder.add(a, b, on)
}
}
return builder.getPrimitive()
}
let octagonalPyramide: Primitive
export function OctagonalPyramide() {
if (!octagonalPyramide) octagonalPyramide = Pyramide(polygon(8, true))
return octagonalPyramide
}
\ No newline at end of file
...@@ -28,8 +28,6 @@ const t = Mat4.identity() ...@@ -28,8 +28,6 @@ const t = Mat4.identity()
const sVec = Vec3.zero() const sVec = Vec3.zero()
const p = Vec3.zero() const p = Vec3.zero()
const pd = Vec3.zero() const pd = Vec3.zero()
const p1 = Vec3.zero()
const p2 = Vec3.zero()
async function createCarbohydrateSymbolMesh(ctx: RuntimeContext, structure: Structure, mesh?: Mesh) { async function createCarbohydrateSymbolMesh(ctx: RuntimeContext, structure: Structure, mesh?: Mesh) {
const builder = MeshBuilder.create(256, 128, mesh) const builder = MeshBuilder.create(256, 128, mesh)
...@@ -44,7 +42,6 @@ async function createCarbohydrateSymbolMesh(ctx: RuntimeContext, structure: Stru ...@@ -44,7 +42,6 @@ async function createCarbohydrateSymbolMesh(ctx: RuntimeContext, structure: Stru
const side = 1.75 * 2 * 0.806; // 0.806 == Math.cos(Math.PI / 4) const side = 1.75 * 2 * 0.806; // 0.806 == Math.cos(Math.PI / 4)
const radius = 1.75 const radius = 1.75
const coneParams = { radiusTop: radius, radiusBottom: 0.0, topCap: true }
const linkParams = { radiusTop: 0.4, radiusBottom: 0.4 } const linkParams = { radiusTop: 0.4, radiusBottom: 0.4 }
...@@ -71,15 +68,15 @@ async function createCarbohydrateSymbolMesh(ctx: RuntimeContext, structure: Stru ...@@ -71,15 +68,15 @@ async function createCarbohydrateSymbolMesh(ctx: RuntimeContext, structure: Stru
builder.addBox(t) builder.addBox(t)
break; break;
case SaccharideShapes.FilledCone: case SaccharideShapes.FilledCone:
Vec3.scaleAndSub(p1, cGeo.center, cGeo.direction, radius) centerAlign(cGeo.center, cGeo.normal, cGeo.direction)
Vec3.scaleAndAdd(p2, cGeo.center, cGeo.direction, radius) Mat4.scaleUniformly(t, t, side * 1.2)
builder.addCylinder(p1, p2, 1, coneParams) builder.addOctagonalPyramid(t)
break break
case SaccharideShapes.DevidedCone: case SaccharideShapes.DevidedCone:
// TODO split // TODO split
Vec3.scaleAndSub(p1, cGeo.center, cGeo.direction, radius) centerAlign(cGeo.center, cGeo.normal, cGeo.direction)
Vec3.scaleAndAdd(p2, cGeo.center, cGeo.direction, radius) Mat4.scaleUniformly(t, t, side * 1.2)
builder.addCylinder(p1, p2, 1, coneParams) builder.addOctagonalPyramid(t)
break break
case SaccharideShapes.FlatBox: case SaccharideShapes.FlatBox:
centerAlign(cGeo.center, cGeo.normal, cGeo.direction) centerAlign(cGeo.center, cGeo.normal, cGeo.direction)
......
...@@ -19,6 +19,7 @@ import { StarProps, Star } from '../primitive/star'; ...@@ -19,6 +19,7 @@ import { StarProps, Star } from '../primitive/star';
import { Octahedron } from '../primitive/octahedron'; import { Octahedron } from '../primitive/octahedron';
import { Primitive } from '../primitive/primitive'; import { Primitive } from '../primitive/primitive';
import { Wedge, Box, DiamondPrism, PentagonalPrism, HexagonalPrism } from '../primitive/prism'; import { Wedge, Box, DiamondPrism, PentagonalPrism, HexagonalPrism } from '../primitive/prism';
import { OctagonalPyramide } from '../primitive/pyramid';
export interface MeshBuilderState { export interface MeshBuilderState {
vertices: ChunkedArray<number, 3> vertices: ChunkedArray<number, 3>
...@@ -34,6 +35,7 @@ export interface MeshBuilder { ...@@ -34,6 +35,7 @@ export interface MeshBuilder {
addDiamondPrism(t: Mat4): void addDiamondPrism(t: Mat4): void
addPentagonalPrism(t: Mat4): void addPentagonalPrism(t: Mat4): void
addHexagonalPrism(t: Mat4): void addHexagonalPrism(t: Mat4): void
addOctagonalPyramid(t: Mat4): void
addStar(t: Mat4, props?: StarProps): void addStar(t: Mat4, props?: StarProps): void
addOctahedron(t: Mat4): void addOctahedron(t: Mat4): void
addCylinder(start: Vec3, end: Vec3, lengthScale: number, props: CylinderProps): void addCylinder(start: Vec3, end: Vec3, lengthScale: number, props: CylinderProps): void
...@@ -158,6 +160,10 @@ export namespace MeshBuilder { ...@@ -158,6 +160,10 @@ export namespace MeshBuilder {
const { vertices, normals, indices } = HexagonalPrism() const { vertices, normals, indices } = HexagonalPrism()
add(t, vertices, normals, indices) add(t, vertices, normals, indices)
}, },
addOctagonalPyramid: (t: Mat4) => {
const { vertices, normals, indices } = OctagonalPyramide()
add(t, vertices, normals, indices)
},
addStar: (t: Mat4, props?: StarProps) => { addStar: (t: Mat4, props?: StarProps) => {
const { vertices, normals, indices } = Star(props) const { vertices, normals, indices } = Star(props)
add(t, vertices, normals, indices) add(t, vertices, normals, indices)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment