master
tonkia 6 years ago
parent c538299186
commit 0f8fbcdec2
  1. 20
      app.js
  2. 263
      package-lock.json
  3. 1
      package.json
  4. 55
      static/js/createScheme.js
  5. 10
      views/createScheme.html

@ -2,6 +2,10 @@ var express = require('express');
var multer = require('multer');
var upload = multer({ dest: 'uploads/' });
var bodyParser = require('body-parser');
var fs = require('fs');
var gm = require('gm');
var app = express();
app.use(bodyParser.json({ limit: '50mb' }));
@ -28,6 +32,22 @@ app.get('/files/:filename', function (req, res) {
var filename = req.params['filename'];
res.sendFile(__dirname + "/uploads/" + filename);
});
//返回缩略图
app.get('/files/thumbnail/:filename', function (req, res) {
var filename = req.params['filename'];
fs.exists(__dirname + "/uploads/thumbnail/" + filename, function (exist) {
if (exist) {
res.sendFile(__dirname + "/uploads/thumbnail/" + filename);
} else {
gm('./uploads/' + filename).resize(40, 40).write("./uploads/thumbnail/" + filename, function (err) {
if (!err)
console.info(err);
res.sendFile(__dirname + "/uploads/thumbnail/" + filename);
})
}
});
});
//保存方案
app.post('/saveScheme', function (req, res) {

263
package-lock.json generated

@ -1,3 +1,264 @@
{
"lockfileVersion": 1
"name": "3dmodelos",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"array-parallel": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/array-parallel/-/array-parallel-0.1.3.tgz",
"integrity": "sha1-j3hTCJJu1apHjEfmTRszS2wMlH0="
},
"array-series": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/array-series/-/array-series-0.1.5.tgz",
"integrity": "sha1-3103v8XC7wdV4qpPkv6ufUtaly8="
},
"cross-spawn": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-4.0.2.tgz",
"integrity": "sha1-e5JHYhwjrf3ThWAEqCPL45dCTUE=",
"requires": {
"lru-cache": "^4.0.1",
"which": "^1.2.9"
}
},
"express": {
"version": "4.16.4",
"resolved": "http://registry.npm.taobao.org/express/download/express-4.16.4.tgz",
"dependencies": {
"accepts": {
"version": "http://registry.npm.taobao.org/accepts/download/accepts-1.3.5.tgz",
"dependencies": {
"mime-types": {
"version": "http://registry.npm.taobao.org/mime-types/download/mime-types-2.1.21.tgz"
},
"negotiator": {
"version": "http://registry.npm.taobao.org/negotiator/download/negotiator-0.6.1.tgz"
}
}
},
"array-flatten": {
"version": "http://registry.npm.taobao.org/array-flatten/download/array-flatten-1.1.1.tgz"
},
"body-parser": {
"version": "http://registry.npm.taobao.org/body-parser/download/body-parser-1.18.3.tgz"
},
"content-disposition": {
"version": "http://registry.npm.taobao.org/content-disposition/download/content-disposition-0.5.2.tgz"
},
"content-type": {
"version": "http://registry.npm.taobao.org/content-type/download/content-type-1.0.4.tgz"
},
"cookie": {
"version": "http://registry.npm.taobao.org/cookie/download/cookie-0.3.1.tgz"
},
"cookie-signature": {
"version": "http://registry.npm.taobao.org/cookie-signature/download/cookie-signature-1.0.6.tgz"
},
"debug": {
"version": "http://registry.npm.taobao.org/debug/download/debug-2.6.9.tgz",
"dependencies": {
"ms": {
"version": "http://registry.npm.taobao.org/ms/download/ms-2.0.0.tgz",
"bundled": true
}
}
},
"depd": {
"version": "http://registry.npm.taobao.org/depd/download/depd-1.1.2.tgz"
},
"encodeurl": {
"version": "http://registry.npm.taobao.org/encodeurl/download/encodeurl-1.0.2.tgz"
},
"escape-html": {
"version": "http://registry.npm.taobao.org/escape-html/download/escape-html-1.0.3.tgz"
},
"etag": {
"version": "http://registry.npm.taobao.org/etag/download/etag-1.8.1.tgz"
},
"finalhandler": {
"version": "http://registry.npm.taobao.org/finalhandler/download/finalhandler-1.1.1.tgz"
},
"fresh": {
"version": "http://registry.npm.taobao.org/fresh/download/fresh-0.5.2.tgz"
},
"merge-descriptors": {
"version": "http://registry.npm.taobao.org/merge-descriptors/download/merge-descriptors-1.0.1.tgz"
},
"methods": {
"version": "http://registry.npm.taobao.org/methods/download/methods-1.1.2.tgz"
},
"on-finished": {
"version": "http://registry.npm.taobao.org/on-finished/download/on-finished-2.3.0.tgz",
"dependencies": {
"ee-first": {
"version": "http://registry.npm.taobao.org/ee-first/download/ee-first-1.1.1.tgz",
"bundled": true
}
}
},
"parseurl": {
"version": "http://registry.npm.taobao.org/parseurl/download/parseurl-1.3.2.tgz"
},
"path-to-regexp": {
"version": "http://registry.npm.taobao.org/path-to-regexp/download/path-to-regexp-0.1.7.tgz"
},
"proxy-addr": {
"version": "http://registry.npm.taobao.org/proxy-addr/download/proxy-addr-2.0.4.tgz"
},
"qs": {
"version": "http://registry.npm.taobao.org/qs/download/qs-6.5.2.tgz"
},
"range-parser": {
"version": "http://registry.npm.taobao.org/range-parser/download/range-parser-1.2.0.tgz"
},
"safe-buffer": {
"version": "http://registry.npm.taobao.org/safe-buffer/download/safe-buffer-5.1.2.tgz"
},
"send": {
"version": "http://registry.npm.taobao.org/send/download/send-0.16.2.tgz"
},
"serve-static": {
"version": "http://registry.npm.taobao.org/serve-static/download/serve-static-1.13.2.tgz"
},
"setprototypeof": {
"version": "http://registry.npm.taobao.org/setprototypeof/download/setprototypeof-1.1.0.tgz"
},
"statuses": {
"version": "http://registry.npm.taobao.org/statuses/download/statuses-1.4.0.tgz"
},
"type-is": {
"version": "http://registry.npm.taobao.org/type-is/download/type-is-1.6.16.tgz",
"dependencies": {
"media-typer": {
"version": "http://registry.npm.taobao.org/media-typer/download/media-typer-0.3.0.tgz",
"bundled": true
},
"mime-types": {
"version": "http://registry.npm.taobao.org/mime-types/download/mime-types-2.1.21.tgz",
"bundled": true,
"dependencies": {
"mime-db": {
"version": "http://registry.npm.taobao.org/mime-db/download/mime-db-1.37.0.tgz",
"bundled": true
}
}
}
}
},
"utils-merge": {
"version": "http://registry.npm.taobao.org/utils-merge/download/utils-merge-1.0.1.tgz"
},
"vary": {
"version": "http://registry.npm.taobao.org/vary/download/vary-1.1.2.tgz"
}
}
},
"gm": {
"version": "1.23.1",
"resolved": "https://registry.npmjs.org/gm/-/gm-1.23.1.tgz",
"integrity": "sha1-Lt7rlYCE0PjqeYjl2ZWxx9/BR3c=",
"requires": {
"array-parallel": "~0.1.3",
"array-series": "~0.1.5",
"cross-spawn": "^4.0.0",
"debug": "^3.1.0"
},
"dependencies": {
"debug": {
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
"requires": {
"ms": "^2.1.1"
}
},
"ms": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
}
}
},
"isexe": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA="
},
"lru-cache": {
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz",
"integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==",
"requires": {
"pseudomap": "^1.0.2",
"yallist": "^2.1.2"
}
},
"multer": {
"version": "1.4.1",
"resolved": "http://registry.npm.taobao.org/multer/download/multer-1.4.1.tgz",
"dependencies": {
"append-field": {
"version": "http://registry.npm.taobao.org/append-field/download/append-field-1.0.0.tgz"
},
"busboy": {
"version": "http://registry.npm.taobao.org/busboy/download/busboy-0.2.14.tgz"
},
"concat-stream": {
"version": "http://registry.npm.taobao.org/concat-stream/download/concat-stream-1.6.2.tgz"
},
"mkdirp": {
"version": "http://registry.npm.taobao.org/mkdirp/download/mkdirp-0.5.1.tgz"
},
"object-assign": {
"version": "http://registry.npm.taobao.org/object-assign/download/object-assign-4.1.1.tgz"
},
"on-finished": {
"version": "http://registry.npm.taobao.org/on-finished/download/on-finished-2.3.0.tgz",
"dependencies": {
"ee-first": {
"version": "http://registry.npm.taobao.org/ee-first/download/ee-first-1.1.1.tgz",
"bundled": true
}
}
},
"type-is": {
"version": "http://registry.npm.taobao.org/type-is/download/type-is-1.6.16.tgz",
"dependencies": {
"media-typer": {
"version": "http://registry.npm.taobao.org/media-typer/download/media-typer-0.3.0.tgz",
"bundled": true
},
"mime-types": {
"version": "http://registry.npm.taobao.org/mime-types/download/mime-types-2.1.21.tgz",
"bundled": true,
"dependencies": {}
}
}
},
"xtend": {
"version": "http://registry.npm.taobao.org/xtend/download/xtend-4.0.1.tgz"
}
}
},
"pseudomap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
"integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM="
},
"which": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
"integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==",
"requires": {
"isexe": "^2.0.0"
}
},
"yallist": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz",
"integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI="
}
}
}

@ -10,6 +10,7 @@
"license": "ISC",
"dependencies": {
"express": "^4.16.4",
"gm": "^1.23.1",
"multer": "^1.4.1"
}
}

@ -100,6 +100,17 @@ function delModelItem(index) {
selectModel(0);
}
//刷新贴图列表
function freshTextureList() {
$('#textureList').empty();
for (var index in data.components[componentIndex].textures) {
var fileName = data.components[componentIndex].textures[index].name;
var fileId = data.components[componentIndex].textures[index].fileId;
$('#textureList').append("<img src='/files/thumbnail/" + fileId + "' width='40px' height='40px' class='img-thumbnail' alt = '" + fileName + "' > ");
}
}
//初始化模型
function loadmodel() {
var manager = new THREE.LoadingManager();
@ -183,7 +194,7 @@ function initCamera() {
function initRenderer() {
//初始化渲染器
renderer = new THREE.WebGLRenderer();
renderer = new THREE.WebGLRenderer({ antialias: true });
//设置像素值
renderer.setPixelRatio(window.devicePixelRatio);
//设置渲染范围为屏幕的大小
@ -219,6 +230,10 @@ function initEvent() {
$("#file").click();
});
$("#textureUpload").click(function () {
$("#textureFile").click();
});
//只要file发生改变就上传文件
$("#file").change(function () {
if ($(this).val().length > 0) {
@ -250,6 +265,38 @@ function initEvent() {
}
});
//贴图文件上传
$("#textureFile").change(function () {
if ($(this).val().length > 0) {
var formData = new FormData($('#uploadTextureForm')[0]);
$.ajax({
type: 'post',
url: "/upload",
data: formData,
cache: false,
processData: false,
contentType: false,
success: function (fileData) {
//上传成功后加载模型
//加载是异步的
var addTextureItem = function (textureObj) {
data.components[componentIndex].textures.push({
name: fileData.originalname,
fileId: fileData.filename,
textureObj: textureObj
});
//selectModel(data.components[componentIndex].models.length - 1);
freshTextureList();
}
addTexture('/files/' + fileData.filename, addTextureItem);
},
error: function () {
alert("上传失败")
}
});
}
});
//当浏览器大小变化时
$(window).resize(function () {
camera.aspect = $('#viewField').innerWidth() / $('#viewField').innerHeight();
@ -345,3 +392,9 @@ function addModel(url, callBack) {
);
}
function addTexture(url, callBack) {
var textureLoader = new THREE.TextureLoader();
textureLoader.load(url, function (object) {
callBack(object);
});
}

@ -114,10 +114,16 @@
<h4 class="modal-title">贴图管理</h4>
</div>
<div class="modal-body">
<div id="textureList">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">确定</button>
<form id="uploadTextureForm" enctype="multipart/form-data">
<input type="file" name="file" id="textureFile" style="display: none" />
</form>
<button class="btn btn-primary" id="textureUpload">上传贴图</button>
<button type="button" class="btn btn-default" data-dismiss="modal" style="margin-left: 10px">确定</button>
</div>
</div>
</div>

Loading…
Cancel
Save