From 9fb7bd7eadf8b39b8f194ca4357ca0eed49a074d Mon Sep 17 00:00:00 2001 From: ChenX Date: Tue, 14 Nov 2017 15:13:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E6=B5=8B=E8=AF=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=20=E5=8A=A0=E8=BD=BDfbx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Add-on/CreateBoardFromData.ts | 11 +++++++--- src/Add-on/loadfbx.ts | 34 +++++++++++++++++++++++++++++++ src/Editor/CommandRegister.ts | 2 ++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 src/Add-on/loadfbx.ts diff --git a/src/Add-on/CreateBoardFromData.ts b/src/Add-on/CreateBoardFromData.ts index a67efb37d..c28ffdd44 100644 --- a/src/Add-on/CreateBoardFromData.ts +++ b/src/Add-on/CreateBoardFromData.ts @@ -42,11 +42,16 @@ export async function CreateBoardFromData(data: Object) { let mat = new THREE.Matrix4(); mat.scale(new THREE.Vector3(0.01, 0.01, 0.01)); + fbxState.object.applyMatrix(mat); + + // app.m_Viewer.m_Scene.add(fbxState.object); + + fbxState.object.updateMatrix(); for (let mesh of fbxState.object.children) { - mesh.applyMatrix(fbxState.object.matrix); - mesh.applyMatrix(mat); - app.m_Viewer.m_Scene.add(mesh); + let meshC = mesh.clone(); + meshC.applyMatrix(fbxState.object.matrix); + app.m_Viewer.m_Scene.add(meshC); } } } diff --git a/src/Add-on/loadfbx.ts b/src/Add-on/loadfbx.ts new file mode 100644 index 000000000..c8b8c0d42 --- /dev/null +++ b/src/Add-on/loadfbx.ts @@ -0,0 +1,34 @@ +import { Command } from "../Editor/CommandMachine"; +import { FileSystem } from "../Common/FileSystem"; +import * as THREE from "three"; +import { app } from '../ApplicationServices/Application'; + +//FileSystem + + +export class Fbx implements Command +{ + async exec() + { + FileSystem.chooseFile((f: FileList) => + { + var reader = new FileReader(); + + // Closure to capture the file information. + reader.onload = (ev) => + { + console.log(ev); + let manager = new THREE.LoadingManager(); + let loader = new THREE.FBXLoader(manager); + let obj = loader.parse(reader.result, ""); + + obj.scale.set(0.01, 0.01, 0.01); + obj.matrixWorldNeedsUpdate = true; + + app.m_Viewer.m_Scene.add(obj); + } + // Read in the image file as a data URL. + reader.readAsArrayBuffer(f.item(0)); + }, null, null); + } +} diff --git a/src/Editor/CommandRegister.ts b/src/Editor/CommandRegister.ts index 25c2b2151..5e75951a2 100644 --- a/src/Editor/CommandRegister.ts +++ b/src/Editor/CommandRegister.ts @@ -16,6 +16,7 @@ import { Stretch } from '../Add-on/Stretch'; import { ViewToTop } from '../Add-on/ViewChange'; import { Test } from '../Add-on/test'; import { DrawGripStretch } from '../Add-on/DrawGripStretch'; +import { Fbx } from '../Add-on/loadfbx'; export function registerCommand() @@ -53,4 +54,5 @@ export function registerCommand() commandMachine.m_CommandList.set("grip", new DrawGripStretch()) + commandMachine.m_CommandList.set("fbx", new Fbx()) }