diff --git a/123456 b/123456 new file mode 100644 index 0000000..e69de29 diff --git a/static/js/createScheme.js b/static/js/createScheme.js index 439eaac..0bb0ce9 100644 --- a/static/js/createScheme.js +++ b/static/js/createScheme.js @@ -171,15 +171,16 @@ function delTexture(index) { //点击事件:切换贴图 function changeTexture(index) { - if (index < 0) - return; - var modelIndex = data.components[componentIndex].modelIndex; - if (modelIndex < 0) - return; - data.components[componentIndex].textureIndex = index; - replaceTexture(data.components[componentIndex].models[modelIndex].modelObj, data.components[componentIndex].textures[index].textureObj); + if (componentIndex >= 0) { + if (index < 0) + return; + var modelIndex = data.components[componentIndex].modelIndex; + if (modelIndex < 0) + return; + data.components[componentIndex].textureIndex = index; + replaceTexture(data.components[componentIndex].models[modelIndex].modelObj, data.components[componentIndex].textures[index].textureObj); + } } - //--------------------------------------------------------------------------------------------------------------------- //ui初始化结束后 //初始化Threejs diff --git a/static/js/share.js b/static/js/share.js index e3fdf6b..6ec2a74 100644 --- a/static/js/share.js +++ b/static/js/share.js @@ -1,4 +1,5 @@ var data; +var componentIndex; $().ready(function () { init(); @@ -78,9 +79,96 @@ function init() { //------------------------------------------------------------------------------ //界面初始化 + + +var swiperComponent; +var swiperModel; +var swiperTexture; + function initUi() { + $('#ui').show(); + initComponentList(); + initSwiper(); +} +function initComponentList() { + for (var index in data.components) { + $('#componentList').prepend("
"); + } +} + +function initSwiper() { + swiperModel = new Swiper('#swiperModel', { + grabCursor: true, + spaceBetween: 20, + slidesPerView: 3, + }) + + swiperTexture = new Swiper('#swiperTexture', { + grabCursor: true, + slidesPerView: 6, + spaceBetween: 20, + }) + + swiperComponent = new Swiper('#swiperComponent', { + grabCursor: true, + direction: 'vertical', + on: { + slideChange: function () { + componentIndex = this.activeIndex; + freshModelList(this.activeIndex); + freshTextureList(this.activeIndex); + }, + }, + }) +} + +function freshModelList(componentIndex) { + swiperModel.removeAllSlides(); + for (var index in data.components[componentIndex].models) { + swiperModel.appendSlide(''); + } } + +function freshTextureList(componentIndex) { + swiperTexture.removeAllSlides(); + for (var index in data.components[componentIndex].textures) { + var fileName = data.components[componentIndex].textures[index].name; + var fileId = data.components[componentIndex].textures[index].fileId; + swiperTexture.appendSlide(' '); + } +} +//点击事件:切换模型 +function changeModel(index) { + //先换贴图 + data.components[componentIndex].modelIndex = index; + var textureIndex = data.components[componentIndex].textureIndex; + changeTexture(textureIndex); + //显示模型 + for (var i in data.components[componentIndex].models) { + if (i == index) { + data.components[componentIndex].models[i].modelObj.visible = true; + } else { + data.components[componentIndex].models[i].modelObj.visible = false; + } + } +} + + +//点击事件:切换贴图 +function changeTexture(index) { + if (componentIndex >= 0) { + if (index < 0) + return; + var modelIndex = data.components[componentIndex].modelIndex; + if (modelIndex < 0) + return; + data.components[componentIndex].textureIndex = index; + replaceTexture(data.components[componentIndex].models[modelIndex].modelObj, data.components[componentIndex].textures[index].textureObj); + } +} + + //------------------------------------------------------------------------------ //threejs配置 function initThree() { diff --git a/views/share.html b/views/share.html index d0ea675..66c79fb 100644 --- a/views/share.html +++ b/views/share.html @@ -19,6 +19,9 @@ + + + + + + + + +