|
@@ -1,143 +1,82 @@
|
|
-import {ply_form} from '../../../../mol-io/reader/ply/parse_data/data-model';
|
|
|
|
-import {MyData} from '../../../../../build/src/mol-model/shape/formarts/ply/plyData_to_shape';
|
|
|
|
-import {Progress, RuntimeContext} from 'mol-task';
|
|
|
|
|
|
+import {ply_form, PlyFile} from '../../../../mol-io/reader/ply/parse_data/data-model';
|
|
|
|
+import {RuntimeContext, Task} from 'mol-task';
|
|
import {Mesh} from '../../../../mol-geo/geometry/mesh/mesh';
|
|
import {Mesh} from '../../../../mol-geo/geometry/mesh/mesh';
|
|
import {MeshBuilder} from '../../../../mol-geo/geometry/mesh/mesh-builder';
|
|
import {MeshBuilder} from '../../../../mol-geo/geometry/mesh/mesh-builder';
|
|
-import {Mat4, Vec3} from '../../../../mol-math/linear-algebra/3d';
|
|
|
|
-import {Sphere} from '../../../../mol-geo/primitive/sphere';
|
|
|
|
|
|
+import { addSphere } from 'mol-geo/geometry/mesh/builder/sphere';
|
|
|
|
+import {Vec3} from '../../../../mol-math/linear-algebra/3d';
|
|
import {Shape} from '../../shape';
|
|
import {Shape} from '../../shape';
|
|
import {Color} from '../../../../mol-util/color';
|
|
import {Color} from '../../../../mol-util/color';
|
|
-import {Canvas3D} from '../../../../mol-canvas3d/canvas3d';
|
|
|
|
-import {labelFirst} from '../../../../mol-theme/label';
|
|
|
|
-import {ColorNames} from '../../../../mol-util/color/tables';
|
|
|
|
-import {ShapeRepresentation} from '../../../../mol-repr/shape/representation';
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-const parent = document.getElementById('app')!
|
|
|
|
-parent.style.width = '100%'
|
|
|
|
-parent.style.height = '100%'
|
|
|
|
-
|
|
|
|
-const canvas = document.createElement('canvas')
|
|
|
|
-canvas.style.width = '100%'
|
|
|
|
-canvas.style.height = '100%'
|
|
|
|
-parent.appendChild(canvas)
|
|
|
|
-
|
|
|
|
-const info = document.createElement('div')
|
|
|
|
-info.style.position = 'absolute'
|
|
|
|
-info.style.fontFamily = 'sans-serif'
|
|
|
|
-info.style.fontSize = '24pt'
|
|
|
|
-info.style.bottom = '20px'
|
|
|
|
-info.style.right = '20px'
|
|
|
|
-info.style.color = 'white'
|
|
|
|
-parent.appendChild(info)
|
|
|
|
-
|
|
|
|
-const canvas3d = Canvas3D.create(canvas, parent)
|
|
|
|
-canvas3d.animate()
|
|
|
|
-canvas3d.input.move.subscribe(async ({x, y}) => {
|
|
|
|
- const pickingId = await canvas3d.identify(x, y)
|
|
|
|
- let label = ''
|
|
|
|
- if (pickingId) {
|
|
|
|
- const { loci } = canvas3d.getLoci(pickingId)
|
|
|
|
- label = labelFirst(loci)
|
|
|
|
- }
|
|
|
|
- info.innerText = label
|
|
|
|
-})
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+import { ShapeProvider } from 'mol-model/shape/provider';
|
|
|
|
|
|
export interface MyData {
|
|
export interface MyData {
|
|
centers: number[],
|
|
centers: number[],
|
|
- colors: string[],
|
|
|
|
|
|
+ colors: Color[],
|
|
labels: string[],
|
|
labels: string[],
|
|
transforms: number[]
|
|
transforms: number[]
|
|
}
|
|
}
|
|
|
|
|
|
-let data:MyData = {
|
|
|
|
- centers: [],
|
|
|
|
- colors: [],
|
|
|
|
- labels: [],
|
|
|
|
- transforms:[]
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-function componentToHex(c) {
|
|
|
|
- let hex = c.toString(16);
|
|
|
|
- return hex.length == 1 ? "0" + hex : hex;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-function rgbToHex(r, g, b) {
|
|
|
|
- return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
- function collectData_for_Shape(parsedData: ply_form):{centers: number[], colors: string[], labels: string[], transforms: number[]}{
|
|
|
|
|
|
+function collectData_for_Shape(parsedData: ply_form): MyData {
|
|
// parsedData.data.PLY_File. to access So.format.Ply
|
|
// parsedData.data.PLY_File. to access So.format.Ply
|
|
|
|
+ console.log('parsedData', parsedData)
|
|
|
|
+ const { vertices, colors } = parsedData
|
|
|
|
+ const data: MyData = {
|
|
|
|
+ centers: vertices,
|
|
|
|
+ colors: [],
|
|
|
|
+ labels: [],
|
|
|
|
+ transforms: []
|
|
|
|
+ }
|
|
|
|
|
|
- data.centers = parsedData.vertices;
|
|
|
|
- let hexColor;
|
|
|
|
-
|
|
|
|
- for(let i=0; i<parsedData.vertexCount; i++){
|
|
|
|
- hexColor = rgbToHex(parsedData.colors[i*3+0],parsedData.colors[i*3+1],parsedData.colors[i*3+2]);
|
|
|
|
- data.colors[i] = hexColor;
|
|
|
|
|
|
+ for (let i = 0; i<parsedData.vertexCount; i++) {
|
|
|
|
+ data.colors[i] = Color.fromRgb(colors[i*3+0], colors[i*3+1], colors[i*3+2]);
|
|
data.labels[i] = '';
|
|
data.labels[i] = '';
|
|
data.transforms[i] = 0;
|
|
data.transforms[i] = 0;
|
|
}
|
|
}
|
|
- console.log(data);
|
|
|
|
|
|
+ console.log('data', data);
|
|
return data;
|
|
return data;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- async function getSphereMesh(ctx: RuntimeContext, centers: number[], mesh?: Mesh) {
|
|
|
|
|
|
+async function getSphereMesh(ctx: RuntimeContext, centers: number[], mesh?: Mesh) {
|
|
const builderState = MeshBuilder.createState(centers.length * 128, centers.length * 128 / 2, mesh)
|
|
const builderState = MeshBuilder.createState(centers.length * 128, centers.length * 128 / 2, mesh)
|
|
- const t = Mat4.identity()
|
|
|
|
const v = Vec3.zero()
|
|
const v = Vec3.zero()
|
|
- const sphere = Sphere(4)
|
|
|
|
builderState.currentGroup = 0
|
|
builderState.currentGroup = 0
|
|
for (let i = 0, il = centers.length / 3; i < il; ++i) {
|
|
for (let i = 0, il = centers.length / 3; i < il; ++i) {
|
|
- // for production, calls to update should be guarded by `if (ctx.shouldUpdate)`
|
|
|
|
- await ctx.update({ current: i, max: il, message: `adding sphere ${i}` })
|
|
|
|
|
|
+ if (i % 10000 === 0 && ctx.shouldUpdate) await ctx.update({ current: i, max: il, message: `adding sphere ${i}` })
|
|
builderState.currentGroup = i
|
|
builderState.currentGroup = i
|
|
- Mat4.setTranslation(t, Vec3.fromArray(v, centers, i * 3))
|
|
|
|
- MeshBuilder.addPrimitive(builderState, t, sphere)
|
|
|
|
|
|
+ addSphere(builderState, Vec3.fromArray(v, centers, i * 3), 0.2, 1)
|
|
}
|
|
}
|
|
let a = MeshBuilder.getMesh(builderState);
|
|
let a = MeshBuilder.getMesh(builderState);
|
|
- //console.log(a);
|
|
|
|
|
|
+ // console.log(a);
|
|
return a
|
|
return a
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getShape(ctx: RuntimeContext, parsedData: ply_form, props: {}, shape?: Shape<Mesh>) {
|
|
export async function getShape(ctx: RuntimeContext, parsedData: ply_form, props: {}, shape?: Shape<Mesh>) {
|
|
- let data:MyData;
|
|
|
|
- data = collectData_for_Shape(parsedData)
|
|
|
|
|
|
+ const data = collectData_for_Shape(parsedData)
|
|
await ctx.update('async creation of shape from myData')
|
|
await ctx.update('async creation of shape from myData')
|
|
- const { centers , colors, labels} = data
|
|
|
|
|
|
+ const { centers , colors, labels } = data
|
|
const mesh = await getSphereMesh(ctx, centers, shape && shape.geometry)
|
|
const mesh = await getSphereMesh(ctx, centers, shape && shape.geometry)
|
|
const groupCount = centers.length / 3
|
|
const groupCount = centers.length / 3
|
|
return shape || Shape.create(
|
|
return shape || Shape.create(
|
|
'test', mesh,
|
|
'test', mesh,
|
|
- (groupId: number) => Color(Number(colors[groupId])), // color: per group, same for instances
|
|
|
|
|
|
+ (groupId: number) => colors[groupId], // color: per group, same for instances
|
|
() => 1, // size: constant
|
|
() => 1, // size: constant
|
|
(groupId: number, instanceId: number) => labels[instanceId * groupCount + groupId] // label: per group and instance
|
|
(groupId: number, instanceId: number) => labels[instanceId * groupCount + groupId] // label: per group and instance
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
-const repr = ShapeRepresentation(getShape, Mesh.Utils)
|
|
|
|
-
|
|
|
|
-export async function init_ren(myData : ply_form) {
|
|
|
|
- // Create shape from myData and add to canvas3d
|
|
|
|
- await repr.createOrUpdate({}, myData).run((p: Progress) => console.log(Progress.format(p)))
|
|
|
|
- canvas3d.add(repr)
|
|
|
|
- canvas3d.resetCamera()
|
|
|
|
-
|
|
|
|
- // Change color after 1s
|
|
|
|
- setTimeout(async () => {
|
|
|
|
- myData.colors[0] = ColorNames.darkmagenta
|
|
|
|
- // Calling `createOrUpdate` with `data` will trigger color and transform update
|
|
|
|
- await repr.createOrUpdate({}, myData).run()
|
|
|
|
- }, 1000)
|
|
|
|
|
|
+export const PlyShapeParams = {
|
|
|
|
+ ...Mesh.Params
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+export type PlyShapeParams = typeof PlyShapeParams
|
|
|
|
+
|
|
|
|
+export function shapeFromPly(source: PlyFile, params?: {}) {
|
|
|
|
+ return Task.create<ShapeProvider<ply_form, Mesh, PlyShapeParams>>('Parse Shape Data', async ctx => {
|
|
|
|
+ console.log('source', source)
|
|
|
|
+ return {
|
|
|
|
+ label: 'Mesh',
|
|
|
|
+ data: source.PLY_File,
|
|
|
|
+ getShape,
|
|
|
|
+ geometryUtils: Mesh.Utils
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+}
|