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

various small tweaks and cleanup

parent 331db15b
No related branches found
No related tags found
No related merge requests found
......@@ -92,11 +92,11 @@ export namespace Geometry {
ValueCell.updateIfChanged(values.dUseFog, props.useFog)
}
export function createRenderableState(props: PD.Values<Params>): RenderableState {
export function createRenderableState(props: Partial<PD.Values<Params>> = {}): RenderableState {
return {
visible: true,
pickable: true,
opaque: props.alpha === 1
opaque: props.alpha === undefined ? true : props.alpha === 1
}
}
......
......@@ -15,21 +15,21 @@ export interface PointsBuilder {
export namespace PointsBuilder {
export function create(initialCount = 2048, chunkSize = 1024, points?: Points): PointsBuilder {
const vertices = ChunkedArray.create(Float32Array, 3, chunkSize, points ? points.centerBuffer.ref.value : initialCount);
const centers = ChunkedArray.create(Float32Array, 3, chunkSize, points ? points.centerBuffer.ref.value : initialCount);
const groups = ChunkedArray.create(Float32Array, 1, chunkSize, points ? points.groupBuffer.ref.value : initialCount);
return {
add: (x: number, y: number, z: number, group: number) => {
ChunkedArray.add3(vertices, x, y, z);
ChunkedArray.add3(centers, x, y, z);
ChunkedArray.add(groups, group);
},
getPoints: () => {
const vb = ChunkedArray.compact(vertices, true) as Float32Array
const cb = ChunkedArray.compact(centers, true) as Float32Array
const gb = ChunkedArray.compact(groups, true) as Float32Array
return {
kind: 'points',
pointCount: vertices.elementCount,
centerBuffer: points ? ValueCell.update(points.centerBuffer, vb) : ValueCell.create(vb),
pointCount: centers.elementCount,
centerBuffer: points ? ValueCell.update(points.centerBuffer, cb) : ValueCell.create(cb),
groupBuffer: points ? ValueCell.update(points.groupBuffer, gb) : ValueCell.create(gb),
}
}
......
......@@ -25,7 +25,7 @@ export interface Points {
readonly kind: 'points',
/** Number of vertices in the point cloud */
pointCount: number,
/** Vertex buffer as array of xyz values wrapped in a value cell */
/** Center buffer as array of xyz values wrapped in a value cell */
readonly centerBuffer: ValueCell<Float32Array>,
/** Group buffer as array of group ids for each vertex wrapped in a value cell */
readonly groupBuffer: ValueCell<Float32Array>,
......
......@@ -34,6 +34,27 @@ export function createTextureImage(n: number, itemSize: number): TextureImage<Ui
return { array: new Uint8Array(length), width, height }
}
export function printImageData(imageData: ImageData, scale = 1) {
const canvas = document.createElement('canvas')
canvas.width = imageData.width
canvas.height = imageData.height
const ctx = canvas.getContext('2d')
if (!ctx) throw new Error('Could not create canvas 2d context')
ctx.putImageData(imageData, 0, 0)
canvas.toBlob(imgBlob => {
const objectURL = window.URL.createObjectURL(imgBlob)
const img = document.createElement('img')
img.src = objectURL
img.style.width = imageData.width * scale + 'px'
img.style.height = imageData.height * scale + 'px'
img.style.position = 'absolute'
img.style.top = '0px'
img.style.left = '0px'
img.style.border = 'solid grey'
document.body.appendChild(img)
}, 'image/png')
}
//
const v = Vec3.zero()
......
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
export function debugTexture(imageData: ImageData, scale = 1) {
const canvas = document.createElement('canvas')
canvas.width = imageData.width
canvas.height = imageData.height
const ctx = canvas.getContext('2d')
if (!ctx) throw new Error('Could not create canvas 2d context')
ctx.putImageData(imageData, 0, 0)
canvas.toBlob(imgBlob => {
const objectURL = window.URL.createObjectURL(imgBlob)
const img = document.createElement('img')
img.src = objectURL
img.style.width = imageData.width * scale + 'px'
img.style.height = imageData.height * scale + 'px'
img.style.position = 'absolute'
img.style.top = '0px'
img.style.left = '0px'
img.style.border = 'solid grey'
document.body.appendChild(img)
}, 'image/png')
}
\ No newline at end of file
......@@ -125,7 +125,7 @@ namespace Representation {
if (update.transform !== undefined) Mat4.copy(state.transform, update.transform)
}
export type Any = Representation<any>
export type Any = Representation<any, any>
export const Empty: Any = {
label: '', groupCount: 0, renderObjects: [], props: {}, params: {}, updated: new Subject(), state: createState(), theme: createEmptyTheme(),
createOrUpdate: () => Task.constant('', undefined),
......@@ -197,7 +197,7 @@ namespace Representation {
Object.assign(currentProps, props, qualityProps)
const { visuals } = currentProps
return Task.create(`Creating '${label}' representation`, async runtime => {
return Task.create(`Creating or updating '${label}' representation`, async runtime => {
for (let i = 0, il = reprList.length; i < il; ++i) {
if (!visuals || visuals.includes(reprMap[i])) {
await reprList[i].createOrUpdate(currentProps, currentData).runInContext(runtime)
......
......@@ -203,6 +203,7 @@ export function VolumeRepresentation<P extends VolumeParams>(label: string, ctx:
function setState(state: Partial<Representation.State>) {
if (state.visible !== undefined && visual) visual.setVisibility(state.visible)
if (state.pickable !== undefined && visual) visual.setPickable(state.pickable)
if (state.transform !== undefined && visual) visual.setTransform(state.transform)
Representation.updateState(_state, state)
}
......
This diff is collapsed.
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