导出场景。

This commit is contained in:
tengge1 2019-03-16 19:52:10 +08:00
parent fb2536611a
commit ff4ac985ee
6 changed files with 110 additions and 1 deletions

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Http.Results;
using System.IO;
using MongoDB.Bson;
using MongoDB.Driver;
using Newtonsoft.Json.Linq;
using ShadowEditor.Server.Base;
using ShadowEditor.Server.Helpers;
namespace ShadowEditor.Server.Controllers.Export
{
/// <summary>
/// 导出场景控制器
/// </summary>
public class ExportSceneController : ApiBase
{
/// <summary>
/// 执行
/// </summary>
/// <param name="ID"></param>
/// <param name="version"></param>
/// <returns></returns>
[HttpPost]
public JsonResult Run(string ID, int version = -1)
{
var mongo = new MongoHelper();
var filter = Builders<BsonDocument>.Filter.Eq("ID", BsonObjectId.Create(ID));
var doc = mongo.FindOne(Constant.SceneCollectionName, filter);
if (doc == null)
{
return Json(new
{
Code = 300,
Msg = "该场景不存在!"
});
}
//var collectionName = doc["CollectionName"].AsString;
//List<BsonDocument> docs;
//if (version == -1) // 最新版本
//{
// docs = mongo.FindAll(collectionName).ToList();
//}
//else // 特定版本
//{
// filter = Builders<BsonDocument>.Filter.Eq(Constant.VersionField, BsonInt32.Create(version));
// docs = mongo.FindMany($"{collectionName}{Constant.HistorySuffix}", filter).ToList();
//}
//var data = new JArray();
//foreach (var i in docs)
//{
// i["_id"] = i["_id"].ToString(); // ObjectId
// data.Add(JsonHelper.ToObject<JObject>(i.ToJson()));
//}
return Json(new
{
Code = 200,
Msg = "导出成功!"
});
}
}
}

View File

@ -101,6 +101,7 @@
<Compile Include="Base\XmlResult.cs" />
<Compile Include="Constant.cs" />
<Compile Include="Controllers\CharacterController.cs" />
<Compile Include="Controllers\Export\ExportSceneController.cs" />
<Compile Include="Controllers\PrefabController.cs" />
<Compile Include="Controllers\ParticleController.cs" />
<Compile Include="Controllers\MeshController.cs" />

View File

@ -540,7 +540,6 @@
<Content Include="assets\textures\VolumetricFire\nzw.png" />
<Content Include="assets\textures\VolumetricFire\smoke.png" />
<Content Include="assets\textures\wood.jpg" />
<Content Include="dist\ShadowEditor.js" />
<Content Include="favicon.ico" />
<Content Include="Global.asax" />
<Content Include="index.html" />

View File

@ -580,3 +580,5 @@ L_TOOL = '工具';
L_ARRANGE_MAP = '整理贴图';
L_ARRANGE_MESH = '整理模型';
L_ARRANGE_THUMBNAIL = '整理缩略图';
L_EXPORT_SCENE = '导出场景';

View File

@ -44,6 +44,11 @@ SceneMenu.prototype.render = function () {
onClick: this.saveAsScene.bind(this)
}, {
xtype: 'hr'
}, {
xtype: 'div',
html: L_EXPORT_SCENE,
cls: 'option',
onClick: this.exportScene.bind(this)
}, {
xtype: 'div',
html: L_EXPORT_STATIC_WEBSITE,
@ -183,6 +188,31 @@ SceneMenu.prototype.commitSaveAs = function (sceneName) {
});
};
// -------------------------- 导出场景 --------------------------------
SceneMenu.prototype.exportScene = function () {
var sceneID = this.app.editor.sceneID;
if (!sceneID) {
UI.msg('请先打开场景!');
return;
}
UI.confirm('询问', '是否导出当前场景?', (event, btn) => {
if (btn === 'ok') {
fetch(`${this.app.options.server}/api/ExportScene/Run?ID=${sceneID}`, {
method: 'POST'
}).then(response => {
if (response.ok) {
response.json().then(json => {
UI.msg(json.Msg);
});
}
});
}
});
};
// ------------------------- 发布静态网站 ------------------------------
SceneMenu.prototype.publish = function () {

View File

@ -579,4 +579,6 @@ Object.assign(window, {
L_ARRANGE_MAP: 'Arrange Map',
L_ARRANGE_MESH: 'Arrange Mesh',
L_ARRANGE_THUMBNAIL: 'Arrange Thumbnail',
L_EXPORT_SCENE: 'Export Scene',
});