Selaa lähdekoodia

光other直接使用了同一个数据bug

xzw 4 vuotta sitten
vanhempi
commit
cb17fe42ab
4 muutettua tiedostoa jossa 135 lisäystä ja 91 poistoa
  1. 6 6
      edit.html
  2. 82 72
      js/edit.js
  3. 22 10
      js/main_2020_edit.js
  4. 25 3
      js/main_2020_show.js

+ 6 - 6
edit.html

@@ -943,18 +943,18 @@
                         <div class="content">
                             <ul>
                                 <li class="info">
-                                    <div class="itemTitle" data-size="15" id="project-name1">
+                                    <div class="itemTitle" data-size="50" id="project-name1">
                                         <span>标题</span>
                                     </div>
                                     <!-- <span class="redPoint" id="project-name2" data-size="15">标题</span> -->
                                     <div class="name">
                                         <input spellcheck="false" placeholder="热点的标题" class="right" type="text"
-                                            minlength="1" maxlength="15" placeholder="">
+                                            minlength="1" maxlength="50" placeholder="">
                                     </div><!-- 必填,限15字 ??-->
-                                    <div class="itemTitle" data-size="200">
+                                    <div class="itemTitle" data-size="500">
                                         <span>简介</span>
                                     </div>
-                                    <textarea placeholder="热点的简介" class="editText" maxlength="200"></textarea>
+                                    <textarea placeholder="热点的简介" class="editText" maxlength="500"></textarea>
 
 
 
@@ -1419,8 +1419,8 @@
          
         //本地:
         /*var token ="eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsInJvbGUiOm51bGwsIm1hbmFnZXIiOm51bGwsImlkIjoxLCJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNTk3MTA5MDk0LCJpYXQiOjE1OTcwMjI2OTQsImp0aSI6ImY4YzI1MTcyLWM0NmUtNGNmYi04MjRhLWJkMmU2YWRmOWVjZSJ9.kUEmWOCJ0WONTkUI1vTToLePfzgbLiWwhU5nEWIsvlg"
-        var ceshi = 'http://47.107.252.54:8105';*/
-         
+        var ceshi = 'http://47.107.252.54:8105';
+         */
         //大场景: 
         var ceshi = 'http://47.107.252.54:8105';
         var token = window.localStorage.dcj_token 

+ 82 - 72
js/edit.js

@@ -12,7 +12,7 @@ var token = window.localStorage.dcj_token
 var _musicMaxWeight = 8//M
 var cmp = getQueryVariable('cmp') || ''
 
-
+var _hotNum = 0
 
 function reData(data,type) {
   return JSON.stringify(data) == type ? null : data
@@ -40,7 +40,7 @@ var EditTools = function (n) {
 EditTools.prototype.init = function () {
   this.hotpoint.init(this.n);
   var that = this;
-  this.saveAll();
+  this.initSaveAll();
   this.active();
   //请求数据someData.js
   $.ajax(g_Prefix + "data/" + window.number + "/someData.json" + "?" + Date.now(), { dataType: "json" })
@@ -132,7 +132,7 @@ EditTools.prototype.active = function () {
 
 }
 //保存按钮
-EditTools.prototype.saveAll = function () {
+EditTools.prototype.initSaveAll = function () {
   var that = this;
 
   $('#save').on('click', function () {
@@ -143,35 +143,38 @@ EditTools.prototype.saveAll = function () {
     })
     var hots = {}
     // 热点数据
-    Array.from($('.spotList ul li')).forEach(function (dom) {
-        var sid = dom.hotMesh.belongHot.sid;    
-        var hot = player.model.hots[sid];
-        hots[sid] = {
+    var hotLength = 0;
+     
+ 
+    for(let i in player.model.hots){
+        let hot = player.model.hots[i];
+        hots[i] = {
             position: {
-              x: dom.hotMesh.position.x,
-              y: dom.hotMesh.position.y,
-              z: dom.hotMesh.position.z
+              x: hot.mesh.position.x,
+              y: hot.mesh.position.y,
+              z: hot.mesh.position.z
             },
             //有的定制场景代码是旧的,只能使用rotation,所以不输出quaternion : 
-            rotation : hot.isSprite ?  new THREE.Euler().setFromQuaternion(hot.quaternion).toObject() : dom.hotMesh.rotation.toObject() 
+            rotation : hot.isSprite ?  new THREE.Euler().setFromQuaternion(hot.quaternion).toObject() : hot.mesh.rotation.toObject() 
             , 
             isSprite :  hot.isSprite ? 1 : 0,
             noAction : hot.noAction ? 1 : 0,
-            infoAttribute: dom.infoAttribute 
-             
+            infoAttribute: hot.infoAttribute ,
+            order : hotLength++   //因为热点保存后在hots里的顺序会被修改,所以使用order来记录顺序 
         }
         if(hot.visiblePanos) hots[sid].visiblePanos = hot.visiblePanos
 
 
-       
-        delete dom.infoAttribute.position;
-        delete dom.infoAttribute.quaternion;
-        delete dom.infoAttribute.rotation; 
-         
-    })
-
-    
-
+        if(hot.infoAttribute){
+            delete hot.infoAttribute.position;
+            delete hot.infoAttribute.quaternion;
+            delete hot.infoAttribute.rotation; 
+        }
+        
+    }
+ 
+ 
+ 
     var info = {
       name: $('#pjtName').val(),
       summary: $('#info-summary').val(),
@@ -216,7 +219,7 @@ EditTools.prototype.saveAll = function () {
       url: ceshi + url, 
       data: JSON.stringify({
         sceneCode:number,
-        hots: reData(hots,'{}') ,
+        hots: reData(hots,'{}') , 
         name: number,
         guides: reData(guides,'[]'),
         info: info,
@@ -437,7 +440,7 @@ Hotpoint.prototype.init = function (n) {
   this.addMusic();  // 添加音乐
   this.addModel();  // 添加模型
   this.addwebPack();  // 添加外链
-  this.saveHot();  // 保存热点
+  this.initSaveHot();  // 保存热点
   var that = this;
   let hotIconScale = $('#hotIconScale');
 
@@ -457,7 +460,7 @@ Hotpoint.prototype.init = function (n) {
     } else {
       if (target.hasClass("DelConfirm")) {
         e.stopPropagation();
-        that.remHot(target, n);
+        that.removeHot(target, n);
       } else {
         //点击热点列表弹出编辑热点窗口
         if (target.hasClass("title") || target.hasClass("icon")) {
@@ -470,10 +473,10 @@ Hotpoint.prototype.init = function (n) {
   //点击热点编辑窗口右上角的关闭按钮
   this.hotpointDetail.find("a.close, button.cancel").on("click", function () {
     var spot_id = that.hotpointDetail.attr("data-id"); 
+    var hot = player.model.hots[spot_id];
     
-    var info = that.hotpointDetail[0].targetDOM.infoAttribute; 
-    if(info){
-        var hot = player.model.hots[spot_id];
+    var info = hot.infoAttribute; //that.hotpointDetail[0].targetDOM.infoAttribute; 
+    if(info){ 
         info.position && hot.mesh.position.copy(info.position)
         info.quaternion && hot.mesh.quaternion.copy(info.quaternion)
         hot.isSprite = info.isSprite
@@ -483,13 +486,15 @@ Hotpoint.prototype.init = function (n) {
     transformControls.detach() 
   });
  
-  //遍历热点 初始话加载热点数据
-  for (var i = 0; i < g_HotMeshes.length; i++) {
-    this.spotList.children("ul").append(this.addHotList(g_HotMeshes[i], i));
+   
+  //创建列表
+  for(let i in player.model.hots){
+      this.addHotList(player.model.hots[i]); 
   }
-  this.spotList.find("i").text(g_HotMeshes.length);
-  // 初始话的时候把热点信息添加到对应的热点中
-  $.ajax(g_Prefix + "data/" + window.number + "/hot/js/data.js" + "?" + Date.now(), { dataType: "json" })
+   
+  
+  // 初始话的时候把热点信息添加到对应的热点中  直接使用data2.json的会怎样?
+ /*  $.ajax(g_Prefix + "data/" + window.number + "/hot/js/data.js" + "?" + Date.now(), { dataType: "json" })
     .then(function (infos) {
       that.infos = infos ;
       Object.keys(infos).forEach(function (key) {
@@ -498,7 +503,7 @@ Hotpoint.prototype.init = function (n) {
         that.spotList.find("ul li[data-spid=" + key + "]")[0] && (that.spotList.find("ul li[data-spid=" + key + "]")[0].infoAttribute = infos[key])&& (that.spotList.find("ul li[data-spid=" + key + "] .title").html(infos[key].title));
         
       })
-    })
+    }) */
 }
 
 /**
@@ -513,13 +518,13 @@ Hotpoint.prototype.editHot = function (target) {
   $layout.targetDOM = target.closest("li")[0];//closest匹配选择器的第一个祖先元素
   //编辑时将热点列表唯一标识带入,以便后期保存使用识别
   var li_id = $($layout.targetDOM).attr("data-spid");
-  
+  this.editSpot = player.model.hots[li_id]; 
   
   this.hotpointDetail.attr("data-id",li_id);
-  var info = $layout.targetDOM.infoAttribute || {}
+  var info = this.editSpot.infoAttribute || {} //$layout.targetDOM.infoAttribute || {}
   transformControls.transCtlChangeMode("translate")
     
- this.editSpot = player.model.hots[li_id]; 
+ 
     
     
   // 参数初始化
@@ -584,7 +589,8 @@ Hotpoint.prototype.editHot = function (target) {
     this.hotpointDetail.find("#upload-hotBgm").removeAttr('data-hotBgm')   // 没有背景音乐,则移除该属性, 避免其他热点的干扰
   }
 
-    $layout.targetDOM.infoAttribute = info
+   // $layout.targetDOM.infoAttribute = info
+   this.editSpot.infoAttribute = info
 
 }
 //添加图片和视频
@@ -785,26 +791,26 @@ Hotpoint.prototype.active = function () {
 Hotpoint.prototype.state = function (that, Hot) {
   if (g_HotStatus === "add") {
     //console.log(Hot)
-    this.addHot(that, Hot, function () {
-      this.addHotList(g_HotMeshes, g_HotMeshes.length - 1);
-      this.spotList.find("i").text(this.spotList.find("ul li").length);
+    this.addHot(that, Hot, (hot)=> {
+      this.addHotList(hot); 
     });
   }
 }
+Hotpoint.prototype.updateNumDisplay = function(){
+   this.spotList.find("i").text(this.spotList.find("ul li").length);  
+}
+
+
+
 //删除热点
-Hotpoint.prototype.remHot = function (that, thisScene) {
+Hotpoint.prototype.removeHot = function (that, thisScene) {
   var hotId = that.closest("li").attr("data-spid");
-  for (var i = 0; i < g_HotMeshes.length; i++) {
-    if (g_HotMeshes[i].belongHot.sid === hotId) {
-      //在场景中删除这个热点模型
-      thisScene.scene.remove(g_HotMeshes[i]);
-      g_HotMeshes[i].visible = false;
-      //如果热点数据中有这个热点数据就删除
-      //g_HotMeshes.splice(i, 1);
-    }
-  }
+    
+  player.model.hots[hotId].dispose();
+  delete player.model.hots[hotId]
+  
   that.closest("li").remove();
-  this.spotList.find(".hotNum").text(this.spotList.find("ul li").length);
+  this.updateNumDisplay()
   console.log("删除成功:" + hotId);
 }
 //添加热点模型
@@ -824,6 +830,8 @@ Hotpoint.prototype.addHot = function (that, Hot, fn) {
         hot.mesh.lookAt(window.hotIntersect.face.normal.clone().add(hotIntersect.point));
         hot.mesh.position.add(window.hotIntersect.face.normal.clone().multiplyScalar(0.01))
     }  
+    hot.quaternion.copy(hot.mesh.quaternion)
+    hot.position.copy(hot.mesh.position)
 
   g_HotStatus = false;
   that.mouseCouldBeClickToMove = false;
@@ -831,29 +839,30 @@ Hotpoint.prototype.addHot = function (that, Hot, fn) {
   //添加完热点之后的回调函数
   if (g_HotMeshes && g_newHot.length === g_newHot.length++) {
     var thisScene = that;
-    fn && fn.call(this, thisScene);
+    //fn && fn.call(this, thisScene);
+    fn && fn(hot)
   }
 }
-//创建热点列表的dom
-Hotpoint.prototype.createDom = function (data, index) {
-  var _index = +index + 1;
-   return "<li data-spid=" + data.name + " id=ggg_s" + index + ">" +
+ 
+//添加热点列表
+Hotpoint.prototype.addHotList = function (hot ) {
+   
+  var li = $("<li data-spid=" + hot.sid + ">" +
     "<div class=icon></div>" +
-    "<div class=number title=热点>" + _index + "</div>" +
-    "<div class=title title=热点></div>" +
+    "<div class=number title=热点>" + (++_hotNum)  + "</div>" +
+    "<div class=title title=热点>" + (hot.infoAttribute && hot.infoAttribute.title ||  "") + "</div>" +
     "<div class=DelConfirm>确定删除</div>" +
     "<div class=del></div>" +
-    "</li>";
-}
-//添加热点列表
-Hotpoint.prototype.addHotList = function (data, index) {
-  if (!data) return;
-  this.spotList.children("ul").append(this.createDom(data, index));
-  //保存热点信息到热点dom元素中
-  var spotList = $(".spotList ul").children("#ggg_s" + index);
-  spotList[0].hotMesh = g_HotMeshes[index];
-  spotList.attr('data-spid', g_HotMeshes[index].belongHot.sid);
+    "</li>") ; 
+  
+  li.hot = hot 
+  $(".spotList ul").append(li);
+  this.updateNumDisplay()
 }
+
+ 
+
+
 //添加热点音乐
 Hotpoint.prototype.addMusic = function () {
   var mediaUpload = $("#hotpointDetail .audio.mediaUpload");
@@ -901,7 +910,7 @@ Hotpoint.prototype.addwebPack = function () {
   });
 }
 // 保存热点信息
-Hotpoint.prototype.saveHot = function () {
+Hotpoint.prototype.initSaveHot = function () {
   var $layout = $(".edit-loading");
   var hotpointDetail = this.hotpointDetail;
   var spotList = this.spotList ;
@@ -1055,7 +1064,8 @@ Hotpoint.prototype.saveHot = function () {
         }).then(function (args) {
           console.log(args);
           //把获取的所有信息都保存在对应热点的dom元素里面
-          hotpointDetail[0].targetDOM.infoAttribute = args;
+          //hotpointDetail[0].targetDOM.infoAttribute = args;
+          hot.infoAttribute = args;
           $layout.addClass('hide');
           hotpointDetail.addClass("atRight");
           spot.find(".title").html(args.title);

+ 22 - 10
js/main_2020_edit.js

@@ -14833,7 +14833,7 @@ function o(a, s, l) {
             this.changeTex()
             
             this.setVisiblePanos(t.visiblePanos); 
-		
+            this.infoAttribute = t.infoAttribute;
             
         }
         var g = e("three")
@@ -15036,6 +15036,12 @@ function o(a, s, l) {
         }
         
         ,
+        n.prototype.dispose = function(){
+            this.mesh.parent.remove(this.mesh);
+            var index = g_HotMeshes.indexOf(this.mesh);
+            g_HotMeshes.splice(index,1)
+        }
+        
        /*  n.prototype.conversionArray = function(e) {
             if ("[object Array]" == Object.prototype.toString.call(e))
                 return e;
@@ -16802,16 +16808,22 @@ function o(a, s, l) {
                         console.error("data2 is null") 
                     }else{ 
                         g_data2 = hotMatcher(e)
-                        this.hotsCount = 0
-                        for (var t in e.hots){
-                            this.hotsCount++,
-                            this.hots[t] = new M(t,e.hots[t],this);
-                            e.hots[t].infoAttribute || (e.hots[t].infoAttribute = {})
-                            this.hots[t].initStyleImg(e.hots[t].infoAttribute);
-                        }
-                        window.hotData = e.hots
-                        e.hots && this.createHotItem(e.hots, this.hots);
+                        this.hotsCount = 0;
+                        //因为热点保存后在hots里的顺序会被修改,所以使用order来记录顺序,这里要重排序:
+                        window.hotData = {}
                         
+                        if(e.hots){
+                            var sids = Object.keys(e.hots).sort((a,b)=>{return e.hots[a].order - e.hots[b].order});
+                            
+                            sids.forEach((sid)=>{
+                                this.hotsCount++,
+                                this.hots[sid] = new M(sid,e.hots[sid] ,this);
+                                e.hots[sid].infoAttribute || (e.hots[sid].infoAttribute = {})
+                                this.hots[sid].initStyleImg(e.hots[sid].infoAttribute);
+                                window.hotData[sid] = e.hots[sid];
+                            })  
+                        }
+                        this.createHotItem(window.hotData, this.hots);
                         
                         g_index = I.valueFromHash("m"),
                         e.tourAudio && (g_tourAudio = new Audio,

+ 25 - 3
js/main_2020_show.js

@@ -6544,7 +6544,7 @@ window.Modernizr = function(n, e, t) {
                 $(".model-title").text(e.name);
                 var i = Q.pageTitle;
                 // 2 !== K.valueFromHash("mls", 0) && (i = e.name + " - " + i),
-                2 !== K.valueFromHash("mls", 0) && i.name && (i = e.name),
+                2 !== K.valueFromHash("mls", 0) && e.name && (i = e.name),
                 document.title = i ,
                 K.isMobile() ? $("#gui-fullscreen").css("display", "none") : ($("[rel=tooltip]").tooltip({
                     delay: {
@@ -17540,14 +17540,36 @@ window.Modernizr = function(n, e, t) {
                     }else{  
                         g_data2 = hotMatcher(t);
                         this.hotsCount = 0;
-                        for(var i in t.hots){
+                        /* for(var i in t.hots){
                             this.hotsCount ++;
                             this.hots[i] = new Hot(i, t.hots[i], this);  
                             t.hots[i].infoAttribute || (t.hots[i].infoAttribute = {})
                             this.hots[i].initStyleImg(t.hots[i].infoAttribute);
                         };
                         window.hotData = t.hots 
-                        t.hots && this.createHotItem(t.hots, this.hots);
+                        t.hots && this.createHotItem(t.hots, this.hots); */
+                        
+                        
+                        
+                        //因为热点保存后在hots里的顺序会被修改,所以使用order来记录顺序,这里要重排序:
+                        window.hotData = {}
+                        if(t.hots){
+                            var sids = Object.keys(t.hots).sort((a,b)=>{return t.hots[a].order - t.hots[b].order});
+                            
+                            sids.forEach((sid)=>{
+                                this.hotsCount++,
+                                this.hots[sid] = new Hot(sid,t.hots[sid] ,this);
+                                t.hots[sid].infoAttribute || (t.hots[sid].infoAttribute = {})
+                                this.hots[sid].initStyleImg(t.hots[sid].infoAttribute);
+                                window.hotData[sid] = t.hots[sid];
+                            }) 
+                        } 
+                        this.createHotItem(window.hotData, this.hots);
+                        
+                        
+                        
+                        
+                        
                         
                         g_index = w.valueFromHash("m");
                         if(t.tourAudio){