diff --git a/src/gltf-object.js b/src/gltf-object.js deleted file mode 100644 index 2148503..0000000 --- a/src/gltf-object.js +++ /dev/null @@ -1,12 +0,0 @@ -import { NetworkObject } from "./network-object"; - -export class glTFObject extends NetworkObject { - constructor(app) { - super(app); - this.register(); - } - - async handleModelData(response) { - const raw = await response.json(); - } -} diff --git a/src/network-object.js b/src/network-object.js deleted file mode 100644 index 1281a62..0000000 --- a/src/network-object.js +++ /dev/null @@ -1,23 +0,0 @@ -import { Object } from "./object"; - -export class NetworkObject extends Object { - constructor(app) { - super(app); - - this.loaded = false; - } - - register() { - app.onUpdate(() => { - if (this.loaded) { - this.draw3D(); - } - }); - } - - async load(url) { - const response = await fetch(url); - await this.handleModelData(response); - this.loaded = true; - } -} diff --git a/src/ply-object.js b/src/ply-object.js deleted file mode 100644 index 46c8ae4..0000000 --- a/src/ply-object.js +++ /dev/null @@ -1,116 +0,0 @@ -import { NetworkObject } from "./network-object"; - -export class PlyObject extends NetworkObject { - constructor(app) { - super(app); - this.register(); - } - - async handleModelData(response) { - const raw = await response.text(); - - const config = { - vertex: { - count: 0, - properties: [], - }, - face: { - count: 0, - properties: [], - }, - }; - - const data = { - vertexes: [], - faces: [], - }; - - let phase = "header"; // "vertex", "face", ... - let currentField = null; - - const headerHandlers = { - ply: () => {}, - format: (ascii, version) => { - if (ascii !== "ascii") { - throw new Error("Only ascii ply files are supported"); - } - - if (version !== "1.0") { - throw new Error("Only version 1.0 ply files are supported"); - } - }, - comment: () => {}, - element: (which, value) => { - currentField = which; - if (which === "vertex") { - config.vertex.count = Number(value); - } else if (which === "face") { - config.face.count = Number(value); - } - }, - property: (what, ...data) => { - if (what === "float") { - config[currentField].properties.push({ - name: data[1], - type: "float", - }); - } else if (what === "list") { - config[currentField].properties.push({ - name: data[2], - type: "list", - indexType: data[0], - valueType: data[1], - }); - } - }, - end_header: () => { - phase = "vertex"; - }, - }; - - const lines = raw.split("\n"); - for (const line of lines) { - const parts = line.split(" "); - - if (phase === "header") { - const handler = headerHandlers[parts[0]]; - if (handler) { - handler(...parts.slice(1)); - } - - continue; - } - - if (phase === "vertex") { - const vertex = {}; - for (let i = 0; i < config.vertex.properties.length; i++) { - const property = config.vertex.properties[i]; - if (property.type === "float") { - vertex[property.name] = Number(parts[i]); - } - } - data.vertexes.push(vertex); - - if (data.vertexes.length === config.vertex.count) { - phase = "face"; - } - - continue; - } - - if (phase === "face") { - const face = []; - for (let i = 1; i < parts.length; i++) { - face.push(Number(parts[i])); - } - data.faces.push(face); - - if (data.faces.length === config.face.count) { - break; - } - - continue; - } - } - } -}