From 29de100661a425b9b0f5d0e19a1c270f6acd791a Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Mon, 20 Aug 2018 16:39:35 -0700 Subject: [PATCH] obj parser placeholder --- src/apps/canvas/index.ts | 12 ++++++++++++ src/mol-io/reader/obj/parser.ts | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/mol-io/reader/obj/parser.ts diff --git a/src/apps/canvas/index.ts b/src/apps/canvas/index.ts index ed3103de5..8eccc6e3c 100644 --- a/src/apps/canvas/index.ts +++ b/src/apps/canvas/index.ts @@ -8,6 +8,7 @@ import './index.html' import Viewer from 'mol-view/viewer'; import CIF, { CifBlock } from 'mol-io/reader/cif' +import { parse as parseObj } from 'mol-io/reader/obj/parser' import { readUrlAs } from 'mol-util/read' import { Model, Format, Structure, StructureSymmetry } from 'mol-model/structure'; import { CartoonRepresentation } from 'mol-geo/representation/structure/representation/cartoon'; @@ -48,6 +49,15 @@ viewer.input.move.subscribe(({x, y, inside, buttons}) => { info.innerText = `${label}` }) + +async function getObjFromUrl(url: string) { + const data = await readUrlAs(url, false) as string + const comp = parseObj(data) + const parsed = await comp.run() + if (parsed.isError) throw parsed + return parsed.result +} + async function getCifFromUrl(url: string) { const data = await readUrlAs(url, false) const comp = CIF.parse(data) @@ -108,6 +118,8 @@ async function init() { const mesh = meshBuilder.getMesh() // Mesh.computeNormalsImmediate(mesh) + // mesh = getObjFromUrl('mesh.obj') + // add representation from custom mesh const customRepr = CustomRepresentation() await customRepr.create(mesh, { diff --git a/src/mol-io/reader/obj/parser.ts b/src/mol-io/reader/obj/parser.ts new file mode 100644 index 000000000..10dafa091 --- /dev/null +++ b/src/mol-io/reader/obj/parser.ts @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author Alexander Rose <alexander.rose@weirdbyte.de> + */ + +import Result from '../result' +import { Task, RuntimeContext } from 'mol-task' +import { Mesh } from 'mol-geo/shape/mesh'; + +async function parseInternal(data: string, ctx: RuntimeContext): Promise<Result<Mesh>> { + // TODO + const result: Mesh = Mesh.createEmpty(); + return Result.success(result); +} + +export function parse(data: string) { + return Task.create<Result<Mesh>>('Parse OBJ', async ctx => { + return await parseInternal(data, ctx); + }); +} + +export default parse; \ No newline at end of file -- GitLab