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

moved ply to shape converter to mol-model-formats

parent 67b3aac2
No related branches found
No related tags found
No related merge requests found
...@@ -5,16 +5,16 @@ ...@@ -5,16 +5,16 @@
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
import {ply_form, PlyFile} from '../../../../mol-io/reader/ply/parse_data/data-model'; import { RuntimeContext, Task } from 'mol-task';
import {RuntimeContext, Task} from 'mol-task';
import {Mesh} from '../../../../mol-geo/geometry/mesh/mesh';
import {MeshBuilder} from '../../../../mol-geo/geometry/mesh/mesh-builder';
import { addTriangle } from 'mol-geo/geometry/mesh/builder/triangle'; import { addTriangle } from 'mol-geo/geometry/mesh/builder/triangle';
import {Shape} from '../../shape';
import {Color} from '../../../../mol-util/color';
import { ShapeProvider } from 'mol-model/shape/provider'; import { ShapeProvider } from 'mol-model/shape/provider';
import { Color } from 'mol-util/color';
import { ply_form, PlyFile } from 'mol-io/reader/ply/parse_data/data-model';
import { MeshBuilder } from 'mol-geo/geometry/mesh/mesh-builder';
import { Mesh } from 'mol-geo/geometry/mesh/mesh';
import { Shape } from 'mol-model/shape';
export interface MyData { interface PlyShapeData {
centers: number[], centers: number[],
normals: number[], normals: number[],
faces: number[], faces: number[],
...@@ -22,11 +22,11 @@ export interface MyData { ...@@ -22,11 +22,11 @@ export interface MyData {
labels: string[], labels: string[],
} }
function collectData_for_Shape(parsedData: ply_form): MyData { function collectData_for_Shape(parsedData: ply_form): PlyShapeData {
// parsedData.data.PLY_File. to access So.format.Ply // parsedData.data.PLY_File. to access So.format.Ply
console.log('parsedData', parsedData) console.log('parsedData', parsedData)
const { vertices, colors, faces, normals } = parsedData const { vertices, colors, faces, normals } = parsedData
const data: MyData = { const data: PlyShapeData = {
centers: vertices, centers: vertices,
normals: normals, normals: normals,
faces: faces, faces: faces,
...@@ -44,7 +44,7 @@ function collectData_for_Shape(parsedData: ply_form): MyData { ...@@ -44,7 +44,7 @@ function collectData_for_Shape(parsedData: ply_form): MyData {
return data; return data;
} }
async function getSphereMesh(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
for (let i = 0, il = faces.length/4; i < il; ++i) { for (let i = 0, il = faces.length/4; i < il; ++i) {
...@@ -65,19 +65,15 @@ async function getSphereMesh(ctx: RuntimeContext, centers: number[], normals: nu ...@@ -65,19 +65,15 @@ async function getSphereMesh(ctx: RuntimeContext, centers: number[], normals: nu
addTriangle(builderState, triangle_vertices, triangle_normals, triangle_indices) addTriangle(builderState, triangle_vertices, triangle_normals, triangle_indices)
} }
let a = MeshBuilder.getMesh(builderState); let a = MeshBuilder.getMesh(builderState);
// a.normalsComputed = false
// Mesh.computeNormalsImmediate(a)
console.log(a); console.log(a);
return a return a
} }
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>) {
const 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, normals, faces, colors, labels } = data const { centers, normals, faces, colors, labels } = data
const mesh = await getSphereMesh(ctx, centers, normals, faces, shape && shape.geometry) const mesh = await getPlyMesh(ctx, centers, normals, faces, 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,
......
...@@ -19,12 +19,12 @@ import { StateObject, StateTransformer } from 'mol-state'; ...@@ -19,12 +19,12 @@ import { StateObject, StateTransformer } from 'mol-state';
import { RuntimeContext, Task } from 'mol-task'; import { RuntimeContext, Task } from 'mol-task';
import { ParamDefinition as PD } from 'mol-util/param-definition'; import { ParamDefinition as PD } from 'mol-util/param-definition';
import { stringToWords } from 'mol-util/string'; import { stringToWords } from 'mol-util/string';
import { shapeFromPly } from 'mol-model/shape/formarts/ply/plyData_to_shape';
import { PluginStateObject as SO, PluginStateTransform } from '../objects'; import { PluginStateObject as SO, PluginStateTransform } from '../objects';
import { trajectoryFromGRO } from 'mol-model-formats/structure/gro'; import { trajectoryFromGRO } from 'mol-model-formats/structure/gro';
import { parseGRO } from 'mol-io/reader/gro/parser'; import { parseGRO } from 'mol-io/reader/gro/parser';
import { parseMolScript } from 'mol-script/language/parser'; import { parseMolScript } from 'mol-script/language/parser';
import { transpileMolScript } from 'mol-script/script/mol-script/symbols'; import { transpileMolScript } from 'mol-script/script/mol-script/symbols';
import { shapeFromPly } from 'mol-model-formats/shape/ply';
export { TrajectoryFromBlob }; export { TrajectoryFromBlob };
export { TrajectoryFromMmCif }; export { TrajectoryFromMmCif };
......
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