add delete model items function

master
tonkia 6 years ago
parent 98d4e27e9b
commit 3348e616cf
  1. 24
      static/js/createScheme.js
  2. 22
      views/createScheme.html

@ -46,6 +46,7 @@ function selectComponent(index) {
componentIndex = index; componentIndex = index;
$('#componentTitle').text(data.components[componentIndex].name); $('#componentTitle').text(data.components[componentIndex].name);
$('#delComponent').show(); $('#delComponent').show();
$('#textureManagerment').show();
$('#upload').removeClass("disabled"); $('#upload').removeClass("disabled");
//加载模型列表 //加载模型列表
freshmodelList(); freshmodelList();
@ -62,15 +63,20 @@ function freshmodelList() {
for (var index in data.components[componentIndex].models) { for (var index in data.components[componentIndex].models) {
if (index == data.components[componentIndex].modelIndex) { if (index == data.components[componentIndex].modelIndex) {
data.components[componentIndex].models[index].modelObj.visible = true; data.components[componentIndex].models[index].modelObj.visible = true;
$('#modelList').append("<a class='list-group-item active' onclick='selectModel(" + index + ")'>" + data.components[componentIndex].models[index].name + "</a>") $('#modelList').append("<a class='list-group-item active' onclick='selectModel(" + index + ")'><span>" + data.components[componentIndex].models[index].name + "</span><button type='button' class='close' onclick='delModelItem(" + index + ")'><span aria-hidden='true'>×</span><span class='sr-only'>Close</span></button></a>");
} else { } else {
data.components[componentIndex].models[index].modelObj.visible = false; data.components[componentIndex].models[index].modelObj.visible = false;
$('#modelList').append("<a class='list-group-item' onclick='selectModel(" + index + ")'>" + data.components[componentIndex].models[index].name + "</a>") $('#modelList').append("<a class='list-group-item' onclick='selectModel(" + index + ")'><span>" + data.components[componentIndex].models[index].name + "</span><button type='button' class='close' onclick='delModelItem(" + index + ")'><span aria-hidden='true'>×</span><span class='sr-only'>Close</span></button></a>");
} }
} }
} }
} }
//删除模型
function delModelItem(index) {
scene.remove(data.components[componentIndex].models[index].modelObj);
data.components[componentIndex].models.splice(index, 1);
selectModel(0);
}
//选择模型 //选择模型
function selectModel(index) { function selectModel(index) {
data.components[componentIndex].modelIndex = index; data.components[componentIndex].modelIndex = index;
@ -226,6 +232,7 @@ function initEvent() {
freshComponentItem(); freshComponentItem();
componentIndex = -1; componentIndex = -1;
$('#componentTitle').text('请先选择部件'); $('#componentTitle').text('请先选择部件');
$('#textureManagerment').hide();
$('#delComponent').hide(); $('#delComponent').hide();
$('#upload').addClass("disabled"); $('#upload').addClass("disabled");
$('.list-group-item').remove(); $('.list-group-item').remove();
@ -251,7 +258,7 @@ function addModel(url, callBack) {
loader.load(url, function (object) { loader.load(url, function (object) {
object.traverse(function (child) { object.traverse(function (child) {
if (child instanceof THREE.Mesh) { if (child instanceof THREE.Mesh) {
//child.material.map = map; child.material.map = map;
child.material.castShadow = true; child.material.castShadow = true;
child.material.receiveShadow = true; child.material.receiveShadow = true;
child.material.needsUpdate = true; child.material.needsUpdate = true;
@ -259,8 +266,11 @@ function addModel(url, callBack) {
}); });
scene.add(object); scene.add(object);
callBack(object); callBack(object);
}); }, function (xhr) {
//console.log((xhr.loaded / xhr.total * 100) + '% loaded');
}, function (err) {
console.error('An error happened');
}
);
} }

@ -71,11 +71,10 @@
<h3 id="componentTitle">请先选择部件</h3> <h3 id="componentTitle">请先选择部件</h3>
</div> </div>
<div class="list-group" id="modelList"> <div class="list-group" id="modelList">
</div> </div>
<button id="delComponent" class="btn btn-danger pull-right" style="display: none">删除该组件</button> <button id="delComponent" class="btn btn-danger pull-right" style="display: none">删除该组件</button>
<button id="textureManagerment" class="btn pull-right" style="display: none;margin-right:10px;">贴图管理</button>
</div> </div>
</div> </div>
<div class="panel-footer"> <div class="panel-footer">
<form id="uploadForm" enctype="multipart/form-data"> <form id="uploadForm" enctype="multipart/form-data">
@ -104,6 +103,25 @@
</div> </div>
</div> </div>
</div> </div>
<!-- 模态框:材质管理 -->
<div class="modal fade" id="textureManagermentModal">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
class="sr-only">关闭</span></button>
<h4 class="modal-title">材质管理</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="addComponent">确定</button>
</div>
</div>
</div>
</div>
<script src="/js/createScheme.js"></script> <script src="/js/createScheme.js"></script>
</body> </body>

Loading…
Cancel
Save