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

use PlyData directly

parent 8e296fd0
Branches
Tags
No related merge requests found
...@@ -14,36 +14,6 @@ import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder'; ...@@ -14,36 +14,6 @@ import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder';
import { Mesh } from 'mol-geo/geometry/mesh/mesh'; import { Mesh } from 'mol-geo/geometry/mesh/mesh';
import { Shape } from 'mol-model/shape'; 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) { async function getPlyMesh(ctx: RuntimeContext, centers: number[], normals: number[], faces: number[], mesh?: Mesh) {
const builderState = MeshBuilder.createState(faces.length, faces.length, mesh) const builderState = MeshBuilder.createState(faces.length, faces.length, mesh)
builderState.currentGroup = 0 builderState.currentGroup = 0
...@@ -64,22 +34,26 @@ async function getPlyMesh(ctx: RuntimeContext, centers: number[], normals: numbe ...@@ -64,22 +34,26 @@ async function getPlyMesh(ctx: RuntimeContext, centers: number[], normals: numbe
// console.log(triangle_vertices) // console.log(triangle_vertices)
addTriangle(builderState, triangle_vertices, triangle_normals, triangle_indices) addTriangle(builderState, triangle_vertices, triangle_normals, triangle_indices)
} }
let a = MeshBuilder.getMesh(builderState); return MeshBuilder.getMesh(builderState);
console.log(a);
return a
} }
async function getShape(ctx: RuntimeContext, parsedData: PlyData, props: {}, shape?: Shape<Mesh>) { 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') await ctx.update('async creation of shape from myData')
const { centers, normals, faces, colors, labels } = data const { vertices, normals, faces, colors, properties } = parsedData
const mesh = await getPlyMesh(ctx, centers, normals, faces, shape && shape.geometry) const mesh = await getPlyMesh(ctx, vertices, normals, faces, shape && shape.geometry)
const groupCount = centers.length / 3
return shape || Shape.create( return shape || Shape.create(
'test', mesh, '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 () => 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.
Please register or to comment