shape.ts 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { PluginContext } from 'mol-plugin/context';
  7. import { State, StateBuilder } from 'mol-state';
  8. import { Task } from 'mol-task';
  9. import { FileInfo } from 'mol-util/file-info';
  10. import { PluginStateObject } from '../objects';
  11. import { StateTransforms } from '../transforms';
  12. import { DataFormatProvider } from './data-format';
  13. export const PlyProvider: DataFormatProvider<any> = {
  14. label: 'PLY',
  15. description: 'PLY',
  16. stringExtensions: ['ply'],
  17. binaryExtensions: [],
  18. isApplicable: (info: FileInfo, data: string) => {
  19. return info.ext === 'ply'
  20. },
  21. getDefaultBuilder: (ctx: PluginContext, data: StateBuilder.To<PluginStateObject.Data.String>, state: State) => {
  22. return Task.create('PLY default builder', async taskCtx => {
  23. const tree = data.apply(StateTransforms.Data.ParsePly)
  24. .apply(StateTransforms.Model.ShapeFromPly)
  25. .apply(StateTransforms.Representation.ShapeRepresentation3D)
  26. await state.updateTree(tree).runInContext(taskCtx)
  27. })
  28. }
  29. }