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

use PlyData directly

parent 8e296fd0
No related branches found
No related tags found
No related merge requests found
......@@ -14,36 +14,6 @@ import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder';
import { Mesh } from 'mol-geo/geometry/mesh/mesh';
import { Shape } from 'mol-model/shape';
interface PlyShapeData {
centers: number[],
normals: number[],
faces: number[],
colors: Color[],
labels: string[],
}
function collectData_for_Shape(parsedData: PlyData): PlyShapeData {
// parsedData.data.PLY_File. to access So.format.Ply
console.log('parsedData', parsedData)
const { vertices, colors, faces, normals } = parsedData
const data: PlyShapeData = {
centers: vertices,
normals: normals,
faces: faces,
colors: [],
labels: [],
}
for (let i = 0; i<parsedData.faceCount; i++) {
data.colors[i] = Color.fromRgb(colors[faces[4*i+1]*3+0], colors[faces[4*i+1]*3+1], colors[faces[4*i+1]*3+2]);
data.labels[i] = parsedData.properties[parsedData.propertyCount * faces[4*i+1] + 10].toString();
// i.toString();
// data.transforms[i] = 0;
}
console.log('data', data);
return data;
}
async function getPlyMesh(ctx: RuntimeContext, centers: number[], normals: number[], faces: number[], mesh?: Mesh) {
const builderState = MeshBuilder.createState(faces.length, faces.length, mesh)
builderState.currentGroup = 0
......@@ -64,22 +34,26 @@ async function getPlyMesh(ctx: RuntimeContext, centers: number[], normals: numbe
// console.log(triangle_vertices)
addTriangle(builderState, triangle_vertices, triangle_normals, triangle_indices)
}
let a = MeshBuilder.getMesh(builderState);
console.log(a);
return a
return MeshBuilder.getMesh(builderState);
}
async function getShape(ctx: RuntimeContext, parsedData: PlyData, props: {}, shape?: Shape<Mesh>) {
const data = collectData_for_Shape(parsedData)
await ctx.update('async creation of shape from myData')
const { centers, normals, faces, colors, labels } = data
const mesh = await getPlyMesh(ctx, centers, normals, faces, shape && shape.geometry)
const groupCount = centers.length / 3
const { vertices, normals, faces, colors, properties } = parsedData
const mesh = await getPlyMesh(ctx, vertices, normals, faces, shape && shape.geometry)
return shape || Shape.create(
'test', mesh,
(groupId: number) => colors[groupId], // color: per group, same for instances
(groupId: number) => {
return Color.fromRgb(
colors[faces[4 * groupId + 1] * 3 + 0],
colors[faces[4 * groupId + 1] * 3 + 1],
colors[faces[4 * groupId + 1] * 3 + 2]
)
},
() => 1, // size: constant
(groupId: number, instanceId: number) => labels[instanceId * groupCount + groupId] // label: per group and instance
(groupId: number) => {
return properties[parsedData.propertyCount * faces[4 * groupId + 1] + 10].toString()
}
)
}
......
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