add delete model items function

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

@ -46,6 +46,7 @@ function selectComponent(index) {
componentIndex = index;
$('#componentTitle').text(data.components[componentIndex].name);
$('#delComponent').show();
$('#textureManagerment').show();
$('#upload').removeClass("disabled");
//加载模型列表
freshmodelList();
@ -62,15 +63,20 @@ function freshmodelList() {
for (var index in data.components[componentIndex].models) {
if (index == data.components[componentIndex].modelIndex) {
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 {
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) {
data.components[componentIndex].modelIndex = index;
@ -226,6 +232,7 @@ function initEvent() {
freshComponentItem();
componentIndex = -1;
$('#componentTitle').text('请先选择部件');
$('#textureManagerment').hide();
$('#delComponent').hide();
$('#upload').addClass("disabled");
$('.list-group-item').remove();
@ -251,7 +258,7 @@ function addModel(url, callBack) {
loader.load(url, function (object) {
object.traverse(function (child) {
if (child instanceof THREE.Mesh) {
//child.material.map = map;
child.material.map = map;
child.material.castShadow = true;
child.material.receiveShadow = true;
child.material.needsUpdate = true;
@ -259,8 +266,11 @@ function addModel(url, callBack) {
});
scene.add(object);
callBack(object);
});
}, function (xhr) {
//console.log((xhr.loaded / xhr.total * 100) + '% loaded');
}, function (err) {
console.error('An error happened');
}
);
}

@ -63,7 +63,7 @@
<div class="dropdown">
<button class="btn btn-block" data-toggle="dropdown">组件选择 <span class="caret"></span></button>
<ul class="dropdown-menu" id="componentList">
<li><a data-toggle="modal" data-target="#addComponentModal"><i class="icon icon-plus"></i> 添加新组件</a></li>
<li><a data-toggle="modal" data-target="#addComponentModal"><i class="icon icon-plus"></i>添加新组件</a></li>
</ul>
</div>
<div style="margin-top:20px">
@ -71,11 +71,10 @@
<h3 id="componentTitle">请先选择部件</h3>
</div>
<div class="list-group" id="modelList">
</div>
<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 class="panel-footer">
<form id="uploadForm" enctype="multipart/form-data">
@ -104,6 +103,25 @@
</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>
</body>

Loading…
Cancel
Save