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

avoid getters on renderable objects

parent a16b1d59
No related branches found
No related tags found
No related merge requests found
...@@ -50,12 +50,12 @@ export class BoundingSphereHelper { ...@@ -50,12 +50,12 @@ export class BoundingSphereHelper {
this.parent.forEach((r, ro) => { this.parent.forEach((r, ro) => {
const objectData = this.objectsData.get(ro) const objectData = this.objectsData.get(ro)
const newObjectData = updateBoundingSphereData(this.scene, r.boundingSphere, objectData, ColorNames.tomato) const newObjectData = updateBoundingSphereData(this.scene, r.values.boundingSphere.ref.value, objectData, ColorNames.tomato)
if (newObjectData) this.objectsData.set(ro, newObjectData) if (newObjectData) this.objectsData.set(ro, newObjectData)
if (ro.type === 'mesh' || ro.type === 'lines' || ro.type === 'points') { if (ro.type === 'mesh' || ro.type === 'lines' || ro.type === 'points') {
const instanceData = this.instancesData.get(ro) const instanceData = this.instancesData.get(ro)
const newInstanceData = updateBoundingSphereData(this.scene, r.invariantBoundingSphere, instanceData, ColorNames.skyblue, { const newInstanceData = updateBoundingSphereData(this.scene, r.values.invariantBoundingSphere.ref.value, instanceData, ColorNames.skyblue, {
aTransform: ro.values.aTransform, aTransform: ro.values.aTransform,
transform: ro.values.transform, transform: ro.values.transform,
uInstanceCount: ro.values.uInstanceCount, uInstanceCount: ro.values.uInstanceCount,
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
import { Program } from './webgl/program'; import { Program } from './webgl/program';
import { RenderableValues, Values, RenderableSchema } from './renderable/schema'; import { RenderableValues, Values, RenderableSchema } from './renderable/schema';
import { RenderVariant, RenderItem } from './webgl/render-item'; import { RenderVariant, RenderItem } from './webgl/render-item';
import { Sphere3D } from 'mol-math/geometry';
import { Vec3 } from 'mol-math/linear-algebra';
import { ValueCell } from 'mol-util'; import { ValueCell } from 'mol-util';
import { idFactory } from 'mol-util/id-factory'; import { idFactory } from 'mol-util/id-factory';
...@@ -24,9 +22,6 @@ export interface Renderable<T extends RenderableValues> { ...@@ -24,9 +22,6 @@ export interface Renderable<T extends RenderableValues> {
readonly id: number readonly id: number
readonly values: T readonly values: T
readonly state: RenderableState readonly state: RenderableState
readonly boundingSphere: Sphere3D
readonly invariantBoundingSphere: Sphere3D
readonly z: number
render: (variant: RenderVariant) => void render: (variant: RenderVariant) => void
getProgram: (variant: RenderVariant) => Program getProgram: (variant: RenderVariant) => Program
...@@ -35,28 +30,10 @@ export interface Renderable<T extends RenderableValues> { ...@@ -35,28 +30,10 @@ export interface Renderable<T extends RenderableValues> {
} }
export function createRenderable<T extends Values<RenderableSchema>>(renderItem: RenderItem, values: T, state: RenderableState): Renderable<T> { export function createRenderable<T extends Values<RenderableSchema>>(renderItem: RenderItem, values: T, state: RenderableState): Renderable<T> {
const boundingSphere: Sphere3D = Sphere3D.create(Vec3.zero(), 0)
const invariantBoundingSphere: Sphere3D = Sphere3D.create(Vec3.zero(), 0)
return { return {
id: getNextRenderableId(), id: getNextRenderableId(),
values, values,
state, state,
get boundingSphere () {
if (values.boundingSphere) {
Sphere3D.copy(boundingSphere, values.boundingSphere.ref.value)
}
return boundingSphere
},
get invariantBoundingSphere () {
if (values.invariantBoundingSphere) {
Sphere3D.copy(invariantBoundingSphere, values.invariantBoundingSphere.ref.value)
}
return invariantBoundingSphere
},
get z () {
return boundingSphere.center[2]
},
render: (variant: RenderVariant) => { render: (variant: RenderVariant) => {
if (values.uPickable) { if (values.uPickable) {
......
...@@ -18,15 +18,15 @@ function calculateBoundingSphere(renderables: Renderable<RenderableValues & Base ...@@ -18,15 +18,15 @@ function calculateBoundingSphere(renderables: Renderable<RenderableValues & Base
boundaryHelper.reset(0.1); boundaryHelper.reset(0.1);
for (let i = 0, il = renderables.length; i < il; ++i) { for (let i = 0, il = renderables.length; i < il; ++i) {
const r = renderables[i] const boundingSphere = renderables[i].values.boundingSphere.ref.value
if (!r.boundingSphere.radius) continue; if (!boundingSphere.radius) continue;
boundaryHelper.boundaryStep(r.boundingSphere.center, r.boundingSphere.radius); boundaryHelper.boundaryStep(boundingSphere.center, boundingSphere.radius);
} }
boundaryHelper.finishBoundaryStep(); boundaryHelper.finishBoundaryStep();
for (let i = 0, il = renderables.length; i < il; ++i) { for (let i = 0, il = renderables.length; i < il; ++i) {
const r = renderables[i] const boundingSphere = renderables[i].values.boundingSphere.ref.value
if (!r.boundingSphere.radius) continue; if (!boundingSphere.radius) continue;
boundaryHelper.extendStep(r.boundingSphere.center, r.boundingSphere.radius); boundaryHelper.extendStep(boundingSphere.center, boundingSphere.radius);
} }
Vec3.copy(boundingSphere.center, boundaryHelper.center); Vec3.copy(boundingSphere.center, boundaryHelper.center);
...@@ -35,16 +35,18 @@ function calculateBoundingSphere(renderables: Renderable<RenderableValues & Base ...@@ -35,16 +35,18 @@ function calculateBoundingSphere(renderables: Renderable<RenderableValues & Base
return boundingSphere; return boundingSphere;
} }
function renderableSort(a: Renderable<any>, b: Renderable<any>) { function renderableSort(a: Renderable<RenderableValues & BaseValues>, b: Renderable<RenderableValues & BaseValues>) {
const drawProgramIdA = a.getProgram('draw').id const drawProgramIdA = a.getProgram('draw').id
const drawProgramIdB = b.getProgram('draw').id const drawProgramIdB = b.getProgram('draw').id
const zA = a.values.boundingSphere.ref.value.center[2]
const zB = a.values.boundingSphere.ref.value.center[2]
if (drawProgramIdA !== drawProgramIdB) { if (drawProgramIdA !== drawProgramIdB) {
return drawProgramIdA - drawProgramIdB; // sort by program id to minimize gl state changes return drawProgramIdA - drawProgramIdB; // sort by program id to minimize gl state changes
} else if (a.z !== b.z) { } else if (zA !== zB) {
return a.state.opaque return a.state.opaque
? a.z - b.z // when opaque draw closer elements first to minimize overdraw ? zA - zB // when opaque draw closer elements first to minimize overdraw
: b.z - a.z // when transparent draw elements last to maximize partial visibility : zB - zA // when transparent draw elements last to maximize partial visibility
} else { } else {
return a.id - b.id; return a.id - b.id;
} }
...@@ -60,7 +62,7 @@ interface Scene extends Object3D { ...@@ -60,7 +62,7 @@ interface Scene extends Object3D {
remove: (o: RenderObject) => void remove: (o: RenderObject) => void
has: (o: RenderObject) => boolean has: (o: RenderObject) => boolean
clear: () => void clear: () => void
forEach: (callbackFn: (value: Renderable<any>, key: RenderObject) => void) => void forEach: (callbackFn: (value: Renderable<RenderableValues & BaseValues>, key: RenderObject) => void) => void
} }
namespace Scene { namespace Scene {
......
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