新增导出场景到PLY文件功能。

This commit is contained in:
tengge1 2019-12-19 20:54:20 +08:00
parent 6f0899980c
commit d491e9cab0
3 changed files with 58 additions and 80 deletions

View File

@ -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)】

View File

@ -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文件"
}

View File

@ -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 {
<MenuItem title={_t('To OBJ File')}
onClick={this.handleExportSceneToOBJ}
/>
<MenuItem title={_t('To PLY File')}
onClick={this.handleExportSceneToPLY}
/>
</MenuItem> : null}
{!enableAuthority || isAdmin ? <MenuItem title={_t('Publish Scene')}
onClick={this.handlePublishScene}
@ -236,62 +240,51 @@ class SceneMenu extends React.Component {
// ---------------------- json --------------------------
handleExportSceneToJson() {
querySceneName() {
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.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`);
});
});
}