From 0e07062bbfa4f8e94c4e63c12404dfa6dcf9328d Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Sat, 1 Dec 2018 20:40:14 -0800 Subject: [PATCH] added color to bounding sphere helper --- .../helper/bounding-sphere-helper.ts | 16 +++++++++------- src/mol-geo/geometry/mesh/mesh.ts | 7 +++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/mol-canvas3d/helper/bounding-sphere-helper.ts b/src/mol-canvas3d/helper/bounding-sphere-helper.ts index 58204e881..b0bf34749 100644 --- a/src/mol-canvas3d/helper/bounding-sphere-helper.ts +++ b/src/mol-canvas3d/helper/bounding-sphere-helper.ts @@ -13,6 +13,8 @@ import Scene from 'mol-gl/scene'; import { WebGLContext } from 'mol-gl/webgl/context'; import { Sphere3D } from 'mol-math/geometry'; import { Vec3, Mat4 } from 'mol-math/linear-algebra'; +import { Color } from 'mol-util/color'; +import { ColorNames } from 'mol-util/color/tables'; export const DebugHelperParams = { sceneBoundingSpheres: PD.Boolean(false, { description: 'Show scene bounding spheres.' }), @@ -39,18 +41,18 @@ export class BoundingSphereHelper { } update() { - const newSceneData = updateBoundingSphereData(this.scene, this.parent.boundingSphere, this.sceneData) + const newSceneData = updateBoundingSphereData(this.scene, this.parent.boundingSphere, this.sceneData, ColorNames.grey) if (newSceneData) this.sceneData = newSceneData const oldRO = new Set<RenderObject>() this.parent.forEach((r, ro) => { const objectData = this.objectsData.get(ro) - const newObjectData = updateBoundingSphereData(this.scene, r.boundingSphere, objectData) + const newObjectData = updateBoundingSphereData(this.scene, r.boundingSphere, objectData, ColorNames.tomato) if (newObjectData) this.objectsData.set(ro, newObjectData) if (ro.type === 'mesh' || ro.type === 'lines' || ro.type === 'points') { const instanceData = this.instancesData.get(ro) - const newInstanceData = updateBoundingSphereData(this.scene, ro.values.invariantBoundingSphere.ref.value, instanceData, ro.values.aTransform.ref.value, ro.values.instanceCount.ref.value) + const newInstanceData = updateBoundingSphereData(this.scene, ro.values.invariantBoundingSphere.ref.value, instanceData, ColorNames.skyblue, ro.values.aTransform.ref.value, ro.values.instanceCount.ref.value) if (newInstanceData) this.instancesData.set(ro, newInstanceData) } @@ -96,10 +98,10 @@ export class BoundingSphereHelper { } } -function updateBoundingSphereData(scene: Scene, boundingSphere: Sphere3D, data: BoundingSphereData | undefined, transform?: Float32Array, transformCount?: number) { +function updateBoundingSphereData(scene: Scene, boundingSphere: Sphere3D, data: BoundingSphereData | undefined, color: Color, transform?: Float32Array, transformCount?: number) { if (!data || !Sphere3D.exactEquals(data.boundingSphere, boundingSphere)) { if (data) scene.remove(data.renderObject) - const renderObject = createBoundingSphereRenderObject(boundingSphere, transform, transformCount) + const renderObject = createBoundingSphereRenderObject(boundingSphere, color, transform, transformCount) scene.add(renderObject) return { boundingSphere, renderObject } } @@ -107,7 +109,7 @@ function updateBoundingSphereData(scene: Scene, boundingSphere: Sphere3D, data: const tmpCenter = Vec3.zero() const tmpM = Mat4.identity() -function createBoundingSphereRenderObject(boundingSphere: Sphere3D, transform?: Float32Array, transformCount?: number) { +function createBoundingSphereRenderObject(boundingSphere: Sphere3D, color: Color, transform?: Float32Array, transformCount?: number) { const builderState = MeshBuilder.createState(1024, 512) if (transform && transformCount) { // TODO create instanced mesh? @@ -120,6 +122,6 @@ function createBoundingSphereRenderObject(boundingSphere: Sphere3D, transform?: if (boundingSphere.radius) addSphere(builderState, boundingSphere.center, boundingSphere.radius, 2) } const mesh = MeshBuilder.getMesh(builderState) - const values = Mesh.createValuesSimple(mesh, { alpha: 0.1, doubleSided: false }) + const values = Mesh.createValuesSimple(mesh, { alpha: 0.1, doubleSided: false }, color) return createMeshRenderObject(values, { visible: true, pickable: false, opaque: false }) } \ No newline at end of file diff --git a/src/mol-geo/geometry/mesh/mesh.ts b/src/mol-geo/geometry/mesh/mesh.ts index c638c8fa6..f5e8180ba 100644 --- a/src/mol-geo/geometry/mesh/mesh.ts +++ b/src/mol-geo/geometry/mesh/mesh.ts @@ -19,8 +19,7 @@ import { ParamDefinition as PD } from 'mol-util/param-definition'; import { calculateBoundingSphere } from 'mol-gl/renderable/util'; import { Theme } from 'mol-theme/theme'; import { MeshValues } from 'mol-gl/renderable/mesh'; -import { ColorTheme } from 'mol-theme/color'; -import { NullLocation } from 'mol-model/location'; +import { ColorNames } from 'mol-util/color/tables'; export interface Mesh { readonly kind: 'mesh', @@ -379,10 +378,10 @@ export namespace Mesh { } } - export function createValuesSimple(mesh: Mesh, props: Partial<PD.Values<Params>>): MeshValues { + export function createValuesSimple(mesh: Mesh, props: Partial<PD.Values<Params>>, colorValue = ColorNames.grey): MeshValues { const p = { ...PD.getDefaultValues(Params), ...props } const transform = createIdentityTransform() - const color = createValueColor(ColorTheme.Empty.color(NullLocation, false)) + const color = createValueColor(colorValue) const marker = createMarkers(1) const counts = { drawCount: mesh.triangleCount * 3, groupCount: 1, instanceCount: 1 } -- GitLab