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

added color to bounding sphere helper

parent 0815ca69
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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 }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment