From d491e9cab014f4c71e2b9706928083187d485749 Mon Sep 17 00:00:00 2001 From: tengge1 <930372551@qq.com> Date: Thu, 19 Dec 2019 20:54:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=BC=E5=87=BA=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E5=88=B0PLY=E6=96=87=E4=BB=B6=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + ShadowEditor.Web/locales/zh-CN.json | 3 +- .../src/editor/menu/SceneMenu.jsx | 134 +++++++----------- 3 files changed, 58 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 67cb3188..71723bc0 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Supported Languages: 中文 / [繁體中文](README-tw.md) / [English](README-en 2. 新增导出场景到JSON文件功能。 3. 新增导出场景到Collada文件功能。 4. 新增导出场景到OBJ文件功能。 +5. 新增导出场景到PLY文件功能。 ## v0.3.9更新【[更新日志](docs-dev/update/UpdateLog.md)】 diff --git a/ShadowEditor.Web/locales/zh-CN.json b/ShadowEditor.Web/locales/zh-CN.json index ff317f5f..337115b1 100644 --- a/ShadowEditor.Web/locales/zh-CN.json +++ b/ShadowEditor.Web/locales/zh-CN.json @@ -954,5 +954,6 @@ "{{dist}}m": "{{dist}}米", "To JSON File": "到JSON文件", "To Collada File": "到Collada文件", - "To OBJ File": "到OBJ文件" + "To OBJ File": "到OBJ文件", + "To PLY File": "到PLY文件" } \ No newline at end of file diff --git a/ShadowEditor.Web/src/editor/menu/SceneMenu.jsx b/ShadowEditor.Web/src/editor/menu/SceneMenu.jsx index ffe3ac68..1bf6bced 100644 --- a/ShadowEditor.Web/src/editor/menu/SceneMenu.jsx +++ b/ShadowEditor.Web/src/editor/menu/SceneMenu.jsx @@ -22,6 +22,7 @@ class SceneMenu extends React.Component { this.handleExportSceneToCollada = this.handleExportSceneToCollada.bind(this); this.handleExportSceneToGltf = this.handleExportSceneToGltf.bind(this); this.handleExportSceneToOBJ = this.handleExportSceneToOBJ.bind(this); + this.handleExportSceneToPLY = this.handleExportSceneToPLY.bind(this); this.handlePublishScene = this.handlePublishScene.bind(this); } @@ -58,6 +59,9 @@ class SceneMenu extends React.Component { + : null} {!enableAuthority || isAdmin ? { - this.commitExportSceneToJson(name); - } + return new Promise(resolve => { + app.prompt({ + title: _t('Input File Name'), + content: _t('Name'), + value: sceneName, + onOK: name => { + resolve(name); + } + }); }); } - commitExportSceneToJson(name) { - var output = app.editor.scene.toJSON(); + handleExportSceneToJson() { + this.querySceneName().then(name => { + var output = app.editor.scene.toJSON(); - try { - output = JSON.stringify(output, StringUtils.parseNumber, '\t'); - // eslint-disable-next-line - output = output.replace(/[\n\t]+([\d\.e\-\[\]]+)/g, '$1'); - } catch (e) { - output = JSON.stringify(output); - } - - StringUtils.saveString(output, `${name}.json`); + try { + output = JSON.stringify(output, StringUtils.parseNumber, '\t'); + // eslint-disable-next-line + output = output.replace(/[\n\t]+([\d\.e\-\[\]]+)/g, '$1'); + } catch (e) { + output = JSON.stringify(output); + } + + StringUtils.saveString(output, `${name}.json`); + }); } // ----------------------- 导出场景为Collada文件 ---------------------- handleExportSceneToCollada() { - var sceneName = app.editor.sceneName; + this.querySceneName().then(name => { + app.require('ColladaExporter').then(() => { + var exporter = new THREE.ColladaExporter(); - if (!sceneName) { - sceneName = _t(`Scene{{Time}}`, { Time: TimeUtils.getDateTime() }); - } - - app.prompt({ - title: _t('Input File Name'), - content: _t('Name'), - value: sceneName, - onOK: name => { - this.commitExportSceneToCollada(name); - } - }); - } - - commitExportSceneToCollada(name) { - app.require('ColladaExporter').then(() => { - var exporter = new THREE.ColladaExporter(); - - exporter.parse(app.editor.scene, function (result) { - StringUtils.saveString(result.data, `${name}.dae`); + exporter.parse(app.editor.scene, function (result) { + StringUtils.saveString(result.data, `${name}.dae`); + }); }); }); } @@ -299,28 +292,13 @@ class SceneMenu extends React.Component { // ----------------------- 导出场景为gltf文件 ------------------------- handleExportSceneToGltf() { - var sceneName = app.editor.sceneName; - - if (!sceneName) { - sceneName = _t(`Scene{{Time}}`, { Time: TimeUtils.getDateTime() }); - } - - app.prompt({ - title: _t('Input File Name'), - content: _t('Name'), - value: sceneName, - onOK: name => { - this.commitExportSceneToGltf(name); - } - }); - } - - commitExportSceneToGltf(name) { - app.require('GLTFExporter').then(() => { - var exporter = new THREE.GLTFExporter(); - - exporter.parse(app.editor.scene, result => { - StringUtils.saveString(JSON.stringify(result), `${name}.gltf`); + this.querySceneName().then(name => { + app.require('GLTFExporter').then(() => { + var exporter = new THREE.GLTFExporter(); + + exporter.parse(app.editor.scene, result => { + StringUtils.saveString(JSON.stringify(result), `${name}.gltf`); + }); }); }); } @@ -328,26 +306,24 @@ class SceneMenu extends React.Component { // ---------------------- 导出场景为OBJ文件 ------------------------------- handleExportSceneToOBJ() { - var sceneName = app.editor.sceneName; - - if (!sceneName) { - sceneName = _t(`Scene{{Time}}`, { Time: TimeUtils.getDateTime() }); - } - - app.prompt({ - title: _t('Input File Name'), - content: _t('Name'), - value: sceneName, - onOK: name => { - this.commitExportSceneToOBJ(name); - } + this.querySceneName().then(name => { + app.require('OBJExporter').then(() => { + var exporter = new THREE.OBJExporter(); + StringUtils.saveString(exporter.parse(app.editor.scene), `${name}.obj`); + }); }); } - commitExportSceneToOBJ(name) { - app.require('OBJExporter').then(() => { - var exporter = new THREE.OBJExporter(); - StringUtils.saveString(exporter.parse(app.editor.scene), `${name}.obj`); + // ----------------------- 导出场景为PLY文件 --------------------------------- + + handleExportSceneToPLY() { + this.querySceneName().then(name => { + app.require('PLYExporter').then(() => { + var exporter = new THREE.PLYExporter(); + StringUtils.saveString(exporter.parse(app.editor.scene, { + excludeAttributes: ['normal', 'uv', 'color', 'index'] + }), `${name}.ply`); + }); }); }