123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821 |
- var g_ProjectName = window.location.pathname.substring(window.location.pathname.indexOf("/") + 1, window.location.pathname.lastIndexOf("/"));
- // var g_Prefix = "//super.4dage.com/";
- // http://wangzhan.cctv.com/wlwm2022/test/data/1248
- var g_Prefix = "//wangzhan.cctv.com/wlwm2022/";
- // var g_Prefix=window.location.href.substring(0,window.location.href.indexOf("/index.html")+1);
- var s = window.location.href.split("/");
- s.pop();
- //var g_Prefix = s.join('/');
- var g_index = null;
- var g_modeldata = null;
- var g_weixinTitle = null;
- var g_Hots = null;
- var g_HotMeshes = [];
- var g_HotMeshSize = {
- g_HotMeshWidth: 0.3,
- g_HotMeshHeight: 0.3,
- };
- //add表示添加,delete表示删除
- var g_HotStatus = null;
- var g_newHot = []; //存储新加热点
- var g_HotImage = {
- point: "https://super.4dage.com/images/4dagePoint2.png",
- point2: "https://super.4dage.com/images/4dagePoint.png",
- };
- var g_saveHot = false;
- var g_TextColor = 0x7777ff;
- var g_Text = null;
- var g_TextPlaneMesh = [];
- var g_TextIconMesh = [];
- var g_TextIcon = "./images/text.png";
- var g_SelectTextIndex = null;
- var g_TextShow = null;
- var g_audioPlay = false;
- var g_background = null;
- var g_roof = null;
- var g_data2 = null; //加载的data2.js的内容
- var g_bgAudio = null; //背景音乐
- var g_tourAudio = null; //导览音乐
- var g_play = 1; //表示播放图标状态
- var g_playAudio = null; //当前在播放或当继续播放时应该播放的,是g_bgAudio或g_tourAudio
- var g_currentHot = null; //当前打开的热点
- //var g_Texture=null;
- //var g_ChunknameTexture={}; //chunkname和贴图名称对应
- var g_NormalTexture = false;
- var g_SpecularTexture = false;
- var g_DirectionalLight = null;
- var g_snapShotWidth = 200; //截图下载图片的大小
- var g_snapShotHeight = 140;
- //微信分享
- var g_weixinObj = {
- title: document.querySelector("head title").innerHTML,
- lineLink: window.location.href,
- imgUrl: "https://www.4dmodel.com/SuperPanoramic/images/weixintitle.jpg",
- desc: "四维时代提供技术支持",
- };
- var settings = {
- hotClickEvent: {
- video: {
- playAndPause: true,
- examine: false,
- openHot: false,
- },
- photo: {
- examine: false,
- openHot: false,
- },
- shine: {
- examine: true,
- openHot: true,
- },
- },
- hotClickActions: ["playAndPause", "examine", "openHot", "fastTran"],
- //默认的:
- teleportTime: 1500, //瞬间过渡的时间
- /* flytimeDistanceMultiplier:150,
- flyTime:750, */
- tourRotTime: 2, //默认停留2秒
- hotFastTran:true,
- dontExamHot:true,
- transparentBg: true,
- bgImg: './static/images/bg.jpg',
- mobileBgImg: './static/images/mobile_bg.png',
- bgColor: '#0f3574',
- };
- if (window.number == "725" || window.number == "724") {
- settings.mobileNavHigh = true;
- }
- //共用函数:
- window.common = null;
- window.MathLight = null;
- window.math = null;
- window.easing = null;
- window.lerp = null;
- window.transitions = null;
- window.browser = null;
- function watch(object, propName, initialValue) {
- //监听某个属性的变化
- let v = initialValue;
- Object.defineProperty(object, propName, {
- get: function() {
- return v;
- },
- set: function(e) {
- console.log("watch:", propName, e);
- v = e;
- },
- });
- }
- var toPrecision = function(e, t) {
- function i(e, t) {
- var i = Math.pow(10, t);
- return Math.round(e * i) / i;
- }
- if (e instanceof Array) {
- for (var n = 0; n < e.length; n++) e[n] = i(e[n], t);
- return e;
- }
- return i(e, t);
- };
- var dealMap = (map) => {
- //使不resize when image is not power of two
- map.wrapS = map.wrapT = THREE.ClampToEdgeWrapping;
- map.minFilter = THREE.LinearFilter;
- map.magFilter = THREE.LinearFilter;
- map.generateMipmaps = true;
- };
- var dom = {
- getOffset: function(type, element, parent) {
- left = type == "left" ? element.offsetLeft : element.offsetTop;
- if (!parent) parent = $("body")[0];
- while ((element = element.offsetParent)) {
- if (element == parent) break;
- left += type == "left" ? element.offsetLeft : element.offsetTop;
- }
- return left;
- },
- };
- var getTransformSid = function() {
- var name;
- if (player.mode == "panorama") {
- name = player.currentPano ? player.currentPano.id : "outside";
- } else {
- name = "outside";
- }
- return name;
- };
- var LineDraw = {
- /* createLine: function(posArr, o) {
- var e = new THREE.BufferGeometry
- , p = new Float32Array(6);
- e.addAttribute("position", new THREE.BufferAttribute(p,3));
- //这句新旧版写法不同 旧版这样:e.addAttribute("position",Float32Array,2,3);
- var p = e.attributes.position.array;
- for (var i = 0; i < 2; i++) {
- p[i * 3] = posArr[i].x;
- p[i * 3 + 1] = posArr[i].y;
- p[i * 3 + 2] = posArr[i].z;
- }
- var mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"]({
- linewidth: o.width || 1,
- //windows无效。 似乎mac/ios上粗细有效 ?
- color: o.color || defaultColor,
- transparent: o.dontAlwaysSeen ? false : true,
- depthTest: o.dontAlwaysSeen ? true : false
- })
- var line = new THREE.Line(e,mat);
- line.renderOrder = o.renderOrder || 4
- //同tagStem; //如果不加高,可能会部分被model遮住
- return line;
- } */
- createLine: function(posArr, o = {}) {
- //多段普通线 (第二个点和第三个点之间是没有线段的, 所以不用在意线段顺序)
- var mat;
- if (o.mat) {
- mat = o.mat;
- } else {
- let prop = {
- lineWidth: o.lineWidth || 1,
- //windows无效。 似乎mac/ios上粗细有效 ?
- color: o.color || defaultColor,
- transparent: o.dontAlwaysSeen ? false : true,
- depthTest: o.dontAlwaysSeen ? true : false,
- opacity: o.opacity != void 0 ? o.opacity : 1,
- };
- if (o.deshed) {
- (prop.dashSize = o.dashSize || 0.1), (prop.gapSize = o.gapSize || 0.1);
- }
- mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"](prop);
- }
- var line = new THREE.LineSegments(new THREE.BufferGeometry(), mat);
- line.renderOrder = o.renderOrder || 4;
- this.moveLine(line, posArr);
- return line;
- },
- moveLine: function(line, posArr) {
- if (posArr.length == 0) return;
- let position = new Float32Array(posArr.length * 3); //[]
- for (var i = 0; i < 2; i++) {
- position[i * 3] = posArr[i].x;
- position[i * 3 + 1] = posArr[i].y;
- position[i * 3 + 2] = posArr[i].z;
- }
- line.geometry.addAttribute("position", new THREE.BufferAttribute(position, 3));
- //line.geometry.setAttribute('position', new THREE.Float32BufferAttribute(new Float32Array(position), 3));
- line.geometry.attributes.position.needsUpdate = true;
- line.geometry.computeBoundingSphere();
- /* if(line.material instanceof THREE.LineDashedMaterial){
- line.computeLineDistances() //只有非buffer的geometry才有
- } */
- },
- };
- var convertTool = {
- getPos2d: function(point, camera, dom) {
- //获取一个三维坐标对应屏幕中的二维坐标
- var camera = camera || player.camera;
- var dom = dom || player.domElement;
- if (!camera) return;
- var pos = point.clone().project(camera); //比之前hotspot的计算方式写得简单 project用于3转2(求法同shader); unproject用于2转3 :new r.Vector3(e.x, e.y, -1).unproject(this.camera);
- var x, y;
- x = ((pos.x + 1) / 2) * dom.clientWidth;
- y = (1 - (pos.y + 1) / 2) * dom.clientHeight;
- var inSight =
- x <= dom.clientWidth &&
- x >= 0 && //是否在屏幕中
- y <= dom.clientHeight &&
- y >= 0;
- return {
- pos: new THREE.Vector2(x, y), // 屏幕像素坐标
- vector: pos, //(范围 -1 ~ 1)
- trueSide: pos.z < 1, //trueSide为false时,即使在屏幕范围内可见,也是反方向的另一个不可以被渲染的点 参见Tag.update
- inSight: inSight, //在屏幕范围内可见
- };
- },
- ifShelter: function( pos3d, pos2d, floorIndex, camera) {
- //检测某点在视线中是否被mesh遮挡
- //if (!pos2d) pos2d = this.getPos2d(pos3d, player)
- camera = camera || player.camera
- var ori = new THREE.Vector3(pos2d.x, pos2d.y, -1).unproject(camera) //找到视线原点 //var ori = player.position;
- var dir = pos3d.clone().sub(ori).normalize()
-
-
- var ray = new THREE.Raycaster(ori, dir); //由外向里 因为模型从内侧是可见的所以从外侧
- /* if(config.isEdit && publicObjectSet.editor.mainDesign.editing){
- var o = ray.intersectObjects(publicObjectSet.editor.mainDesign.wallMeshes);
- }else{ */
- let colliders = player.model.allFloorsVisible
- ? player.model.colliders
- : (floorIndex != void 0 ? player.model.floors.index[floorIndex] : player.model.currentFloor).collider.children;
- //let colliders = (floorIndex == void 0 ) ? player.model.colliders : player.model.floors.index[floorIndex].collider.children
- var o = ray.intersectObjects(colliders);
- //}
- var len = pos3d.distanceTo(ori);
- if (o && o.length) {
- for (var i = 0; i < o.length; i++) {
- if (o[i].distance < len) {
- return true;
- } //有遮挡
- }
- }
- },
- /*
- 拖拽时,获取鼠标在拖拽面上的位置(需要借助另一个intersectPlane面来计算,即和相机方向一样的面,可保证铺满屏幕)
- 但是不一定能获取到,比如鼠标射线不朝向拖拽面时,即使获取也会是一个意外的反方向的交点。
- */
- getPosAtPlane: function(pos, info /* , mouse, camera */) {
- //pos:与intersectPlane的交点 见笔记
- var A = pos;
- var player = player;
- var mouse = player.mouse;
- var O = new THREE.Vector3(mouse.x, mouse.y, -1).unproject(player.camera);
- if (info.y != void 0) {
- //地面线的
- var y = info.y;
- if (player.mode == "floorplan" /* || Math.abs(O.x-pos.x)<0.0001 && Math.abs(O.z-pos.z)<0.0001) */) {
- //intersectPlane和地面平行,无交点
- var x = pos.x,
- z = pos.z;
- } else {
- if (y < player.camera.position.y && O.y <= A.y /* || y>player.camera.position.y && O.y >= A.y */) return null; //鼠标射线向上。因为相机一定位于地面以上(地面不会抬高到相机上吧?),所以无交点。
- if (O.y == A.y) {
- console.log("一样??");
- return;
- }
- if (A.y == y) {
- console.log("一样2??");
- return;
- }
- var r = (O.y - y) / (A.y - y);
- var x = (r * A.x - O.x) / (r - 1);
- var z = (r * A.z - O.z) / (r - 1);
- }
- } else {
- //垂直的也有越过消失点以后反向变化的情况,但使用时影响不大
- var N = info.normalVec;
- var P = info.pullPos;
- if (N.y != 0) {
- console.log("N.y != 0");
- return;
- } //仅仅支持垂直于地面的的墙壁,目前都是
- if (O.z == A.z) {
- console.log("O.z==A.z?");
- return;
- }
- if (N.z != 0 && N.x != 0) {
- //直接用这个通用的也可以,支持斜线的墙
- //console.log('N.z==0 && N.x == 0?');
- var c = N.x * (A.x - O.x) + N.y * (A.y - O.y) + N.z * (A.z - O.z);
- if (c == 0) {
- console.log("分母为0?? return;");
- return;
- }
- var t = -(N.x * O.x + N.y * O.y + N.z * O.z - (P.x * N.x + P.y * N.y + P.z * N.z)) / c;
- var x = t * (A.x - O.x) + O.x;
- var y = t * (A.y - O.y) + O.y;
- var z = t * (A.z - O.z) + O.z;
- /*原理: 已知空间直线L:(x-a)/m=(x-b)/n=(z-c)/p和空间平面π:Ax+By+Cz+D=0;
- 求直线L与平面π的交点的坐标。
- 把直线方程改写成参数形式:设(x-a)/m=(x-b)/n=(z-c)/p=t;
- 则x=mt+a;y=nt+b;z=pt+c;代入平面π的方程得:
- A(mt+a)+B(nt+b)+C(pt+c)+D=0
- 由此解得t=-(Aa+Bb+Cc+D)/(Am+Bn+Cp)
- 再代入参数方程即得交点的坐标(x,y,z). */
- } else if (N.x == 0) {
- //z与pullPos相等
- var z = P.z;
- if (O.y == A.y) {
- console.log("一样??");
- return;
- }
- if (A.y == y) {
- console.log("一样2??");
- return;
- }
- if (A.z == z) {
- console.log("一样3??");
- return;
- }
- var r = (O.z - z) / (A.z - z);
- var x = (r * A.x - O.x) / (r - 1);
- var y = (r * A.y - O.y) / (r - 1);
- } else if (N.z == 0) {
- //x与pullPos相等
- var x = P.x;
- if (O.y == A.y) {
- console.log("一样??");
- return;
- }
- if (A.y == y) {
- console.log("一样2??");
- return;
- }
- if (A.x == x) {
- console.log("一样3??");
- return;
- }
- var r = (O.x - x) / (A.x - x);
- var y = (r * A.y - O.y) / (r - 1);
- var z = (r * A.z - O.z) / (r - 1);
- }
- }
- return new THREE.Vector3(x, y, z);
- },
- getMouseIntersect: function(camera, meshes, mouse) {
- //获取鼠标和meshes交点
- var raycaster = new THREE.Raycaster();
- camera.updateMatrixWorld();
- var origin = new THREE.Vector3(mouse.x, mouse.y, -1).unproject(camera),
- end = new THREE.Vector3(mouse.x, mouse.y, 1).unproject(camera);
- var dir = end.sub(origin).normalize();
- raycaster.set(origin, dir);
- var n = raycaster.intersectObjects(meshes);
- if (0 === n.length) return null;
- return n[0];
- },
- ifIntersectChunks: function(A, B, options = {}) {
- //获取某个线段/射线和meshes的交点
- var dir = B.clone()
- .sub(A)
- .normalize();
- var len = options.InfinityLen ? Infinity : A.distanceTo(B) + (options.extLen || 0);
- var ray = new THREE.Raycaster(A.clone(), dir, 0, len);
- var o = ray.intersectObjects(options.model || player.model.colliders);
- if (o && o.length) return o;
- if (options.throughWidth) {
- //允许最小宽度,防止穿过极小的缝隙导致撞墙感
- var normal = math.getNormal({
- points: [
- { x: A.x, y: A.z },
- { x: B.x, y: B.z },
- ],
- }); //线段法线
- normal.multiplyScalar(options.throughWidth);
- var normalVec3 = new THREE.Vector3(normal.x, 0, normal.y);
- var A2 = A.clone().add(normalVec3);
- ray.set(A2, dir);
- var o2 = ray.intersectObjects(options.model || player.model.colliders);
- ray.set(A.clone().add(normalVec3.negate()), dir);
- if (o2 && o2.length) return o2;
- var o3 = ray.intersectObjects(options.model || player.model.colliders);
- if (o3 && o3.length) return o3;
- }
- return null;
- },
-
- getNormal: function(line2d){//获取二维法向量 方向向内
- var x,y;//要求的向量
- //line2d的向量
- var x1 = line2d.points[1].x - line2d.points[0].x;
- var y1 = line2d.points[1].y - line2d.points[0].y;
- //假设法向量的x或y固定为1或-1
- if(y1 != 0){
- x = 1;
- y = - (x1 * x) / y1;
- }else if(x1 != 0){//y如果为0,正常情况x不会是0
- y = 1;
- x = - (y1 * y) / x1;
- }else{
- console.log("两个点一样");
- return null;
- }
-
- //判断方向里或者外:
- var vNormal = new THREE.Vector3(x, 0, y);
- var vLine = new THREE.Vector3(x1, 0, y1);
- var vDir = vNormal.cross(vLine);
- if(vDir.y>0){
- x *= -1;
- y *= -1;
- }
- return new THREE.Vector2(x, y).normalize();
- },
-
-
-
-
- getPosAtSphere: function(pos3d, toPanoPos) {
- var dir = pos3d.clone().sub(toPanoPos);
- dir.normalize(); //然后计算在球中
- dir.multiplyScalar(Constants.skyRadius);
- dir.add(toPanoPos);
- return dir;
- },
- getScaleForConstantSize: function(op = {}) {
- //获得规定二维大小的mesh的scale值。可以避免因camera的projection造成的mesh视觉大小改变。 来源:tag.updateDisc
- var w;
- var i = new THREE.Vector3(),
- o = new THREE.Vector3(),
- l = new THREE.Vector3(),
- c = new THREE.Vector3(),
- h = new THREE.Vector3();
- if (op.width2d) w = op.width2d;
- //如果恒定二维宽度
- else {
- //否则考虑上距离,加一丢丢近大远小的效果
- var currentDis, nearBound, farBound;
- if (op.camera.type == "OrthographicCamera") {
- currentDis = (op.camera.right - op.camera.left) / op.camera.zoom;
- } else {
- currentDis = op.position.distanceTo(op.camera.position);
- }
- w = op.maxSize - (op.maxSize - op.minSize) * THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound);
- //maxSize : mesh要表现的最大像素宽度; nearBound: 最近距离,若比nearBound近,则使用maxSize
- }
- i.copy(op.position).project(op.camera), //tag中心在屏幕上的二维坐标
- o.set(op.resolution.x / 2, op.resolution.y / 2, 1).multiply(i), //转化成px -w/2 到 w/2的范围
- l.set(w / 2, 0, 0).add(o), //加上tag宽度的一半
- c.set(2 / op.resolution.x, 2 / op.resolution.y, 1).multiply(l), //再转回 -1 到 1的范围
- h.copy(c).unproject(op.camera); //再转成三维坐标,求得tag边缘的位置
- var g = h.distanceTo(op.position); //就能得到tag的三维半径
- return g; //可能NAN 当相机和position重叠时
- },
- updateVisible: function(object, reason, ifShow, level = 0, type) {
- //当所有加入的条件都不为false时才显示. reason='force'一般是强制、临时的
- if (!object.unvisibleReasons) object.unvisibleReasons = []; //如果length>0代表不可见
- if (!object.visibleReasons) object.visibleReasons = []; //在同级时,优先可见
- var update = function() {
- //先按从高到低的level排列
- object.unvisibleReasons = object.unvisibleReasons.sort((a, b) => b.level - a.level);
- object.visibleReasons = object.visibleReasons.sort((a, b) => b.level - a.level);
- var maxVisiLevel = object.visibleReasons[0] ? object.visibleReasons[0].level : -1;
- var maxunVisiLevel = object.unvisibleReasons[0] ? object.unvisibleReasons[0].level : -1;
- var shouldVisi = maxVisiLevel >= maxunVisiLevel;
- var visiBefore = object.visible;
- if (visiBefore != shouldVisi) {
- object.visible = shouldVisi;
- object.dispatchEvent({
- type: "isVisible",
- visible: shouldVisi,
- reason,
- });
- }
- };
- if (ifShow) {
- var index = object.unvisibleReasons.findIndex((e) => e.reason == reason);
- if (index > -1) {
- type = "cancel";
- object.unvisibleReasons.splice(index, 1);
- }
- if (type == "add") {
- if (!object.visibleReasons.some((e) => e.reason == reason)) {
- object.visibleReasons.push({ reason, level });
- }
- }
- } else {
- var index = object.visibleReasons.findIndex((e) => e.reason == reason);
- if (index > -1) {
- type = "cancel";
- object.visibleReasons.splice(index, 1);
- }
- if (type != "cancel") {
- if (!object.unvisibleReasons.some((e) => e.reason == reason)) {
- object.unvisibleReasons.push({ reason, level });
- }
- }
- }
- update();
- },
- getObjVisiByReason: function(object, reason) {
- //获取在某条件下是否可见. 注: 用户在数据集选择可不可见为"datasetSelection"
- if (object.visible) return true;
- else {
- return !object.unvisibleReasons || !object.unvisibleReasons.some((e) => e.reason == reason);
- }
- },
- };
- //--------------------------------------
- //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
- var Manage = function() {
- (this.weixinURL = "https://res.wx.qq.com/open/js/jweixin-1.2.0.js"), (this.time = "?" + new Date().getTime());
- this.loadAudio();
- // this.loadWeixin();
- };
- //动态加载js文件
- Manage.prototype.LoadJs = function(_files, succes) {
- /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
- var classcodes = [];
- var FileArray = [];
- if (typeof _files === "object") {
- FileArray = _files;
- } else {
- /*如果文件列表是字符串,则用,切分成数组*/
- if (typeof _files === "string") {
- FileArray = _files.split(",");
- }
- }
- if (FileArray != null && FileArray.length > 0) {
- var LoadedCount = 0;
- for (var i = 0; i < FileArray.length; i++) {
- loadFile(FileArray[i], function() {
- LoadedCount++;
- if (LoadedCount == FileArray.length) {
- try {
- succes();
- } catch (err) {
- console.log("err: 您未定义回调");
- }
- }
- });
- }
- }
- /*加载JS文件,url:文件路径,success:加载成功回调函数*/
- function loadFile(url, success) {
- if (!FileIsExt(classcodes, url)) {
- var _ThisType = GetFileType(url);
- var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0, _ThisType.indexOf("?"));
- var fileObj = null;
- if (ThisType == ".js") {
- fileObj = document.createElement("script");
- fileObj.src = url;
- } else if (ThisType == ".css") {
- fileObj = document.createElement("link");
- fileObj.href = url;
- fileObj.type = "text/css";
- fileObj.rel = "stylesheet";
- } else if (ThisType == ".less") {
- fileObj = document.createElement("link");
- fileObj.href = url;
- fileObj.type = "text/css";
- fileObj.rel = "stylesheet/less";
- }
- success = success || function() {};
- fileObj.onload = fileObj.onreadystatechange = function() {
- if (!this.readyState || "loaded" === this.readyState || "complete" === this.readyState) {
- success();
- classcodes.push(url);
- }
- };
- document.getElementsByTagName("head")[0].appendChild(fileObj);
- } else {
- success();
- }
- }
- /*获取文件类型,后缀名,小写*/
- function GetFileType(url) {
- if (url != null && url.length > 0) {
- return url.substr(url.lastIndexOf(".")).toLowerCase();
- }
- return "";
- }
- /*文件是否已加载*/
- function FileIsExt(FileArray, _url) {
- if (FileArray != null && FileArray.length > 0) {
- var len = FileArray.length;
- for (var i = 0; i < len; i++) {
- if (FileArray[i] == _url) {
- return true;
- }
- }
- }
- return false;
- }
- };
- //获取页面url后面的参数
- Manage.prototype.number = function(variable) {
- var query = window.location.search.substring(1);
- var vars = query.split("&");
- for (var i = 0; i < vars.length; i++) {
- var pair = vars[i].split("=");
- if (pair[0] == variable) {
- return pair[1];
- }
- }
- return false;
- };
- Manage.prototype.loadWeixin = function() {
- var that = this;
- this.LoadJs(that.weixinURL + that.time, function() {});
- };
- Manage.prototype.weixinShare = function() {
- console.log("weixinShare");
- $.ajax({
- url: "https://www.4dage.com/wechat/jssdk/",
- type: "post",
- data: {
- url: location.href.split("#")[0],
- },
- dataType: "jsonp",
- jsonpCallback: "success_jsonp",
- success: function(data, textStatus) {
- console.log("weixinShare success");
- console.log(data.appId);
- wx.config({
- // debug : true,
- appId: data.appId,
- timestamp: data.timestamp,
- nonceStr: data.nonceStr,
- signature: data.signature,
- jsApiList: [
- "checkJsApi",
- "onMenuShareTimeline",
- "onMenuShareAppMessage",
- "onMenuShareQQ",
- "onMenuShareWeibo",
- "hideMenuItems",
- "showMenuItems",
- "hideAllNonBaseMenuItem",
- "showAllNonBaseMenuItem",
- "translateVoice",
- "startRecord",
- "stopRecord",
- "onRecordEnd",
- "playVoice",
- "pauseVoice",
- "stopVoice",
- "uploadVoice",
- "downloadVoice",
- "chooseImage",
- "previewImage",
- "uploadImage",
- "downloadImage",
- "getNetworkType",
- "openLocation",
- "getLocation",
- "hideOptionMenu",
- "showOptionMenu",
- "closeWindow",
- "scanQRCode",
- "chooseWXPay",
- "openProductSpecificView",
- "addCard",
- "chooseCard",
- "openCard",
- ],
- });
- },
- error: function(XMLHttpRequest, textStatus, errorThrown) {
- console.log("jsonp.error:" + textStatus);
- },
- });
- var success_jsonp = function(json) {
- console.log(json);
- };
- wx.ready(function() {
- // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
- //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
- //分享到朋友圈
- console.log(g_weixinObj);
- wx.onMenuShareTimeline({
- title: g_weixinObj.title, // 分享标题
- link: g_weixinObj.lineLink, // 分享链接
- imgUrl: g_weixinObj.imgUrl, // 分享图标
- desc: g_weixinObj.desc,
- });
- //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
- wx.onMenuShareAppMessage({
- title: g_weixinObj.title, // 分享标题
- desc: g_weixinObj.desc, // 分享描述
- link: g_weixinObj.lineLink, // 分享链接
- imgUrl: g_weixinObj.imgUrl, // 分享图标
- type: "", // 分享类型,music、video或link,不填默认为link
- dataUrl: "", // 如果type是music或video,则要提供数据链接,默认为空
- });
- wx.onMenuShareWeibo({
- title: g_weixinObj.title, // 分享标题
- desc: g_weixinObj.desc, // 分享描述
- link: g_weixinObj.lineLink, // 分享链接
- imgUrl: g_weixinObj.imgUrl, // 分享图标
- success: function() {
- // 用户确认分享后执行的回调函数
- },
- cancel: function() {
- // 用户取消分享后执行的回调函数
- },
- });
- wx.onMenuShareQZone({
- title: g_weixinObj.title, // 分享标题
- desc: g_weixinObj.desc, // 分享描述
- link: g_weixinObj.lineLink, // 分享链接
- imgUrl: g_weixinObj.imgUrl, // 分享图标
- success: function() {
- // 用户确认分享后执行的回调函数
- },
- cancel: function() {
- // 用户取消分享后执行的回调函数
- },
- });
- wx.onMenuShareQQ({
- title: g_weixinObj.title, // 分享标题
- desc: g_weixinObj.desc, // 分享描述
- link: g_weixinObj.lineLink, // 分享链接
- imgUrl: g_weixinObj.imgUrl, // 分享图标
- success: function() {
- // 用户确认分享后执行的回调函数
- },
- cancel: function() {
- // 用户取消分享后执行的回调函数
- },
- });
- wx.error(function(res) {
- // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
- });
- });
- };
- Manage.prototype.dealURL = function(src, type) {
- //music: "///super.4dage.com/data/LYW/edit/20200928_151633415.mp3"
- //"https://super.4dage.com/data/LYW/edit/20200928_165319399.jpg"]
- if (window.isLocal && settings.localPrefix != void 0) {
- //本地将线上的前缀替换
- var oldPrefix = "super.4dage.com/"; //最简单的地址写一个,如果有其他完全不一样的地址就用数组逐个判断
- var index = src.indexOf(oldPrefix);
- if (index > -1) {
- var wholeOldPrefix = src.slice(0, index + oldPrefix.length);
- return src.replace(wholeOldPrefix, settings.localPrefix);
- }
- console.error("没有找到合适的本地链接");
- return src;
- } else {
- //add https://
- var prefix = g_Prefix.replace("https://", "").replace("http://", "");
- if (!src.includes("http:/") && !src.includes("https:/") && src.includes(prefix)) {
- src = "https://" + src;
- }
- return src;
- }
- };
- Manage.prototype.removeSrcPostMark = function(url) {
- //去除texture.load时自动加上的'?'
- var index = url.indexOf("?");
- if (index > -1) {
- return url.slice(0, index);
- } else return url;
- };
- Manage.prototype.showInfo = function(o) {
- // ({result:true, title:"发布成功"});
- var box = $(".resultBox");
- var title = o.title || o || i18n.get("保存成功");
- box
- .children()
- .eq(0)
- .html(title);
- //var time = o.time || THREE.Math.clamp((Config.lang=='en') ? title.length*50 : title.length*130 ,1300,5000);
- var time = o.time || THREE.Math.clamp(title.length * 130, 1300, 5000);
- o.time || console.log("showtime " + time);
- //实际有一半的时间在渐变透明度
- this.showInfoTimer && clearTimeout(this.showInfoTimer);
- box.removeClass("animate"); //如果之后不久又要showinfo一个的话,先停止前面的animate
- setTimeout(
- function() {
- box.css({
- "-webkit-animation-duration": time + "ms",
- "animation-duration": time + "ms",
- });
- if (o.top) {
- box.children().css("top", o.top + "%");
- } else {
- box.children().css("top", "");
- }
- box.removeClass("hide");
- box.addClass("animate");
- if (o.dontInteract) {
- //遮挡对屏幕的操作
- box.css("pointer-events", "auto");
- } else {
- box.css("pointer-events", "none");
- }
- this.showInfoTimer = setTimeout(
- function() {
- box.removeClass("animate");
- box.addClass("hide");
- this.showInfoTimer = null;
- }.bind(this),
- time + 20
- );
- }.bind(this),
- 50
- ); //这个数字太小的话后面触发的没有重新animate的效果 应该要比帧率大吧
- }; //like: manage.showInfo({title:'a', top:20})
- //公用的函数
- function getQueryVariable(variable) {
- var query = window.location.search.substring(1);
- var vars = query.split("&");
- for (var i = 0; i < vars.length; i++) {
- var pair = vars[i].split("=");
- if (pair[0] == variable) {
- return pair[1];
- }
- }
- return false;
- }
- //隐藏公司Logo
- function showLogo() {
- $("#myCompany").hide();
- $("#loaderCoBrandName").hide();
- $("#title-logo").hide();
- $(".title-container").css("justify-content", "center");
- }
- //czj 添加随机的时间
- function randomTime() {
- return new Date();
- }
- function matcher(data) {
- if (!data || !g_version) return data;
- delete data.model.vision_version;
- var _data = {
- files: {
- templates: ["images/images{{number}}/{{filename}}"],
- },
- model: {
- sid: window.number,
- camera_start:
- data.model.images && data.model.images.length != 0
- ? {
- camera: {
- zoom: "-1",
- quaternion: [
- JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
- JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
- JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
- JSON.parse(data.model.images[0].metadata).camera_quaternion.y,
- ],
- },
- pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
- mode: "0",
- }
- : "",
- },
- sid: window.number,
- hoticon: {
- default: "https://super.4dage.com/images/4dagePoint2.png",
- higt: "https://super.4dage.com/images/4dagePoint.png",
- },
- special: "false",
- weixinDesc: "",
- };
- $.extend(true, data, _data);
- return data;
- }
- function hotMatcher(data = {}) {
- //if(!data || !g_version) return data;
- if (g_version) {
- data.tourAudio = data.audio || {};
- } else {
- data.tourAudio = {};
- }
- return data;
- }
- var GifTexDeal = {
- animateObjects: [],
- animateTexs: [],
- addAnimation: function(texture, owner, info, id) {
- /* if(this.animateObjects.find(e=>
- e.texture == texture && !ifSame(info, e.info)
- )) */
- var animation;
- var tex = this.animateTexs.find((e) => e.texture == texture);
- if (tex) {
- animation = tex;
- } else {
- animation = { texture, info };
- this.animateTexs.push(animation);
- this.setRepeart(animation);
- }
- var object = {
- animation, //默认相同的texture对应的info是一样的, 对应一个animation
- owner,
- };
- this.animateObjects.push(object);
- return object;
- },
- remove: function(object) {
- var index = this.animateObjects.indexOf(object);
- if (index > -1) {
- this.animateObjects.splice(index, 1);
- if (!this.animateObjects.find((e) => e.animation == object.animation)) {
- let i = this.animateTexs.indexOf(object.animation);
- this.animateTexs.splice(i, 1);
- object.animation.texture.repeat.set(1, 1);
- }
- this.stop(object);
- }
- },
- setRepeart: function(animation) {
- animation.texture.repeat.set(1 / animation.info.cellXcount, 1 / animation.info.cellYcount);
- },
- start: function(object) {
- if (!object || object.started) return;
- object.started = true;
- if (object.animation.started) return;
- object.animation.started = true;
- var info = object.animation.info;
- var count = info.cellXcount * info.cellYcount - (info.voidCount || 0);
- if (count <= 1) return;
- transitions.start(
- (progress) => {
- var index = Math.floor(count * progress);
- var indexX = index % info.cellXcount;
- var indexY = info.cellYcount - Math.floor(index / info.cellXcount) - 1; //uv.offset.y是从下到上的
- object.animation.texture.offset.x = indexX / info.cellXcount;
- object.animation.texture.offset.y = indexY / info.cellYcount;
- //console.log(object.id + " : "+ object.texture.offset.toArray())
- },
- info.duration * -1,
- null,
- /* ()=>{//done (-1):循环
- object.started = false
- object.texture.offset.x = 0;
- object.texture.offset.y = 0;
- this.start(object)
- }, */ 0,
- null,
- object.id,
- "gif_" + object.animation.texture.id
- );
- },
- stop: function(object) {
- if (!object || !object.started) return;
- object.started = false;
- //只有该object对应的texture对应的所有object都停止了,才能真的停止动画:
- if (this.animateObjects.find((e) => e.animation == object.animation && e.started)) return;
- transitions.cancelById("gif_" + object.animation.texture.id);
- object.animation.texture.offset.set(0, 0);
- object.animation.started = false;
- },
- };
- var CloneObject = function(copyObj, result, isSimpleCopy, extraReplace) {
- //isSimpleCopy只复制最外层
- //复制json result的可能:普通数字或字符串、普通数组、复杂对象
- if (!copyObj) return copyObj; //0 null undefined ''
- result = result || {};
- if (copyObj instanceof Array) {
- /* if (copyObj[0]instanceof Object) {
- //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
- console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
- }
-
- return copyObj.slice(0);*/ //如果是数组,直接复制返回(排除数组内是object
- return copyObj.map((e) => {
- if (e instanceof Object) {
- return CloneObject(e);
- } else return e;
- });
- } else {
- if (copyObj.clone instanceof Function) {
- //解决一部分
- return copyObj.clone();
- }
- }
- for (var key in copyObj) {
- if (copyObj[key] instanceof Object && !isSimpleCopy) result[key] = CloneObject(copyObj[key]);
- else result[key] = copyObj[key];
- //如果是函数类同基本数据,即复制引用
- }
- return result;
- };
- var ifSame = function(object1, object2) {
- if (object1 == object2) return true;
- // 0 != undefined , 0 == ''
- else if (!object1 || !object2) return false;
- else if (object1.constructor != object2.constructor) {
- return false;
- } else if (object1 instanceof Array) {
- if (object1.length != object2.length) return false;
- var _object2 = object2.slice(0);
- for (let i = 0; i < object1.length; i++) {
- var u = _object2.find((e) => ifSame(object1[i], e));
- if (u == void 0 && !_object2.includes(u) && !object1.includes(u)) return false;
- else {
- let index = _object2.indexOf(u);
- _object2.splice(index, 1);
- }
- }
- return true;
- } else if (object1.equals instanceof Function) {
- //复杂数据仅支持这种,其他的可能卡住?
- return object1.equals(object2);
- } else if (typeof object1 == "number" || typeof object1 == "string") {
- if (isNaN(object1) && isNaN(object2)) return true;
- else return object1 == object2;
- } else if (typeof object1 == "object") {
- var keys1 = Object.keys(object1);
- var keys2 = Object.keys(object2);
- if (!ifSame(keys1, keys2)) return false;
- for (let i in object1) {
- var same = ifSame(object1[i], object2[i]);
- if (!same) return false;
- }
- return true;
- } else {
- console.log("isSame出现例外");
- }
- };
- function initByTHREE(THREE) {
- window.bus = new THREE.EventDispatcher(); //因为player一开始总是没创建好,所以加一个事件传递器
- THREE.TransitionPass = function(scene, camera) {
- this.renderScene = scene;
- this.renderCamera = camera;
- this.coverRenderTarget = new THREE.WebGLRenderTarget(100, 100, {
- minFilter: THREE.LinearFilter,
- magFilter: THREE.LinearFilter,
- format: THREE.RGBAFormat,
- });
- this.coverTex = this.coverRenderTarget.texture;
- this.enabled = false;
- this.oldClearColor = new THREE.Color();
- this.oldClearAlpha = 1;
- this.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
- this.scene = new THREE.Scene();
- this.material = this.getMaskMaterial();
- var copyShader = THREE.CopyShader;
- this.materialCopy = new THREE.ShaderMaterial({
- uniforms: this.copyUniforms,
- vertexShader: copyShader.vertexShader,
- fragmentShader: copyShader.fragmentShader,
- blending: THREE.NoBlending,
- depthTest: false,
- depthWrite: false,
- transparent: true,
- });
- this.quad = new THREE.Mesh(new THREE.PlaneBufferGeometry(2, 2), this.material);
- this.quad.frustumCulled = false; // Avoid getting clipped
- this.scene.add(this.quad);
- };
- THREE.TransitionPass.prototype = {
- //波形扩散,出下一个画面
- constructor: THREE.TransitionPass,
- setSize: function(width, height) {
- this.coverRenderTarget.setSize(width, height);
- },
- render: function(renderer, writeBuffer, readBuffer, delta, maskActive) {
- var oldAutoClear = renderer.autoClear;
- renderer.autoClear = false;
- var uniforms = this.quad.material.uniforms;
- uniforms.bgTex.value = readBuffer.texture; //更新
- uniforms.coverTex.value = this.coverTex;
- uniforms.progress.value = player.model.skybox.material.uniforms.progress.value; //
- uniforms.screenRatio.value = player.domElement.clientWidth / player.domElement.clientHeight; // 使波纹为圆形
- uniforms.screenRatio.value *= uniforms.screenRatio.value;
- renderer.render(this.scene, this.camera);
- renderer.autoClear = oldAutoClear;
- },
- start: function(sceneRenderer) {
- this.enabled = true;
- //draw coverTex
- this.quad.material.uniforms.progress.value = 1;
- sceneRenderer.renderer.render(sceneRenderer.scene, sceneRenderer.camera, this.coverRenderTarget, true);
- console.log("start111");
- },
- stop: function() {
- this.enabled = false;
- console.log("stop111");
- },
- getMaskMaterial: function() {
- return new THREE.ShaderMaterial({
- uniforms: {
- coverTex: {
- type: "t",
- value: null,
- },
- bgTex: {
- type: "t",
- value: null,
- },
- progress: {
- type: "f",
- value: 0,
- },
- screenRatio: {
- type: "f",
- value: 1,
- },
- },
- vertexShader: `
- varying vec2 vUv;
-
- void main()
- {
- vUv = uv;
-
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
- }
-
- `,
- fragmentShader: `
- uniform sampler2D coverTex;
- uniform sampler2D bgTex;
- uniform float progress;
- uniform float screenRatio;
- varying vec2 vUv;
-
- void main() {
-
- const float maxRadius = 0.708; // sqrt(0.5^2+0.5^2)
- const float minRadius = 0.0 ;
-
- float radius = screenRatio>1.0 ? sqrt((vUv.x - 0.5)*(vUv.x - 0.5) + (vUv.y - 0.5)*(vUv.y - 0.5)/screenRatio) : sqrt((vUv.x - 0.5)*(vUv.x - 0.5)*screenRatio+ (vUv.y - 0.5)*(vUv.y - 0.5));
- float diff = 0.292; //1.0-maxRadius;
- float radiusIn = maxRadius * progress + minRadius * (1.0-progress);
- float radiusOut = radiusIn + diff;
- if(radius < radiusIn) {
-
- gl_FragColor = texture2D(bgTex, vUv);
- //gl_FragColor = vec4(0.0,0.0,1.0,1.0);//
-
- }else if(radius>radiusOut){
- gl_FragColor = texture2D(coverTex, vUv) ;
- //gl_FragColor = vec4(1.0,1.0,0.0,1.0);//
-
- }else{
-
- vec4 color1 = texture2D(bgTex, vUv);
- vec4 color2 = texture2D(coverTex, vUv);
- float rotio = smoothstep(radiusIn ,radiusOut,radius);
-
- gl_FragColor = mix(color1, color2, rotio);
- }
- }
- `,
- });
- },
- };
- let labels = [];
- class Label2D extends THREE.EventDispatcher {
- constructor(o = {}) {
- super();
- this.position = o.position;
- this.elem = $(o.innerHTML || "<div ><a></a></div>");
- $(o.domElement).append(this.elem);
- this.pos2d = new THREE.Vector3();
- this.elem.css({ position: "absolute", "z-index": 999 });
- this.clickFun = o.clickFun;
- this.clickFun && this.elem.on("click", this.clickFun.bind(this));
- if (o.autoUpdate) {
- let update = (e) => {
- if (e.cameraChanged) this.update();
- };
- player.on("view.changed", update); //确保player存在
- this.addEventListener("dispose", (e) => {
- player.off("view.changed", update);
- });
- }
- this.visible = true;
- this.shelterByModel = o.shelterByModel;
- this.floorIndex = o.floorIndex;
- labels.push(this);
- if (window.player.model) {
- this.init();
- } else {
- window.bus.addEventListener("playerAndModelReady", this.init.bind(this));
- }
- }
- init() {
- if (this.floorIndex != void 0) {
- player.model.on("floor.changed", (currentFloor, mode, oldFloor) => {
- this.update(currentFloor); //注: currentFloor 这时候还没成为 model.currentFloor
- });
- }
- }
- update(currentFloor) {
- if (!this.position || !this.visible) return;
- var p = convertTool.getPos2d(this.position);
- if (!p || !p.trueSide) {
- this.elem.css("display", "none");
- return;
- }
- //判断label是否被模型遮挡,遮挡则消失(如果是漫游模式最好提前计算visiblePanos)
- if (player.mode != "panorama") {
- currentFloor = currentFloor || player.model.currentFloor;
- if (!player.model.allFloorsVisible && this.floorIndex != void 0 && this.floorIndex != currentFloor.floorIndex) {
- this.elem.css("display", "none");
- return;
- }
- if (this.shelterByModel && convertTool.ifShelter(this.position, p.vector, this.floorIndex)) {
- this.elem.css("display", "none");
- return;
- }
- }
-
-
- let s = 1
- if(player.mode == 'floorplan'){
- s = THREE.Math.clamp(0.12/player.cameraControls.activeControl.camera.right * window.innerWidth / window.devicePixelRatio, 0.1, 1)
-
- }
- this.elem.css({
- left: p.pos.x + "px",
- top: p.pos.y + "px",
- transform: 'scale('+s+')',
- });
-
-
- /* if(settings.vrEnabled){
- this.elem.css({transform:'rotate('+window.screenFaceOrient+'deg)'})
- }else{
- this.elem.css({transform:''})
- } */
- this.elem.css("display", "block");
- this.pos2d = p.vector;
- }
- setVisible(visi, reason, level = 0, type) {
- convertTool.updateVisible(this, reason, visi, level, type);
- if (!this.visible) {
- this.elem.css("display", "none");
- } else {
- this.update();
- }
- }
- setPos(pos) {
- this.position = pos;
- this.update();
- }
- dispose() {
- this.elem.remove();
- this._listeners = {};
- this.dispatchEvent({ type: "dispose" });
- let index = labels.indexOf(this);
- index > -1 && labels.splice(index, 1);
- }
- }
- window.Label2D = Label2D;
- class RoomLabel extends Label2D {
- constructor(o) {
- if (o.position instanceof Array) o.position = new THREE.Vector3().fromArray(o.position);
- o.innerHTML = `<div class="room-label" ><a><p><span>${o.title}</span></p></a></div>`;
- o.domElement = $(".widgets-doll-labels")[0];
- (o.shelterByModel = true), (o.autoUpdate = true);
- o.clickFun = () => {
- if (player.roomLebelClickUnabled) return;
- let result = common.sortByScore(
- player.model.floors.index[this.floorIndex].panos,
- [],
- [
- (pano) => {
- return -pano.position.distanceToSquared(this.position);
- },
- ]
- );
- player.flyToPano({
- pano: result && result[0] && result[0].item,
- });
- };
- super(o);
- this.setTitle(o.title);
- }
- init() {
- super.init();
- //飞入后不可见
- player.on("mode.changing", (currentMode, mode, pano, duration) => {
- //准备飞
- this.setStyle(currentMode, mode, duration);
- });
- this.setStyle();
- }
- setStyle(currentMode, mode, duration) {
- if (!mode) mode = player.mode;
- if (mode == "panorama") {
- this.setVisible(false, "isPanorama");
- } else if (currentMode == "panorama") {
- setTimeout(() => {
- this.setVisible(true, "isPanorama");
- }, duration * 0.7);
- }
- }
- setTitle(title) {
- this.title = title || "";
- this.elem.html(`<a><p><span>${this.title}</span></p></a>`);
- }
- setEditSelect(state) {
- //编辑页面用
- this.editing = !!state;
- this.setVisible(state, "editSelected", 1, state ? "add" : "cancel"); //强制可见
- }
- }
- window.RoomLabel = RoomLabel;
- window.bus.addEventListener("playerAndModelReady", () => {
- player.on("mode.changing", (currentMode, mode, pano, duration) => {
- let noLine = mode == "floorplan";
- if (noLine) {
- $(".widgets-doll-labels")
- .addClass("noLine")
- .addClass("noCorner");
- } else {
- $(".widgets-doll-labels")
- .removeClass("noLine")
- .removeClass("noCorner");
- }
- });
- player.on("view.changed", (e) => {
- if (e.cameraChanged) {
- //if(needUpdateZIndex){ //如果某个label显示时需要更新index的话,加个参数
- let label_ = labels.filter((e) => e.elem[0].style.display == "block");
- label_.sort((a, b) => b.pos2d.z - a.pos2d.z);
- label_.forEach((e, index) => e.elem.css("z-index", index + 1000));
- //}
- }
- });
- });
- }
- //最好能知道应该播放到的currentTime
- var SoundManager = {
- //暂不支持同时播放
- currentAudio: null, //当前正在播放list中的哪一个
- enableSound: true, //是否允许有声音
- playHistory: [], //被打断的加入播放历史
- list: [], //同一级别可以互相打断 //暂时不做多级别
- play: function(name, src, currentTime) {
- var object = this.list.find((e) => e.name == name);
- if (object && this.currentAudio == object) {
- if (this.currentAudio) {
- this.pause(this.currentAudio.name, false, true);
- }
- {
- //将当前要播放的播放历史中清除
- let index = this.playHistory.indexOf(object);
- if (index > -1) this.playHistory.splice(index, 1);
- }
- this.currentAudio = object;
- if (src) {
- this.setSrc(name, src);
- }
- if (currentTime != void 0) {
- object.audio.currentTime = currentTime;
- }
- if (object.audio && object.src) {
- object.audio.load(); // iOS 9 还需要额外的 load 一下, 否则直接 play 无效 *///https://www.cnblogs.com/interdrp/p/4211883.html 部分资料
- object.audio.play();
- object.callback && object.callback(true);
- Log(name + " 播放 ");
- }
- }
- },
- pause: function(name, autoReplayLast, isInterrupt) {
- //需要能自动恢复上一个被打算的音频。恢复前判断是否还需要播放
- var object = this.list.find((e) => e.name == name);
- if (object) {
- this.currentAudio = null;
- if (object.audio) {
- object.audio.pause();
- object.callback && object.callback(false);
- object.audio.src && Log(name + " 中断音频 " + "(" + common.getFileNameFromUrl(object.audio.src) + ")");
- }
- if (isInterrupt) {
- //一般主动调用不需要加这个
- this.playHistory.push(object); //如果是被中断的,加入播放历史,等待恢复播放
- }
- if (autoReplayLast) {
- //播放之前的音频。它们是被打断过的。
- while (this.playHistory.length) {
- var last = this.playHistory.pop();
- if (last.src && last.canplay(last.audio)) {
- this.play(last.name);
- }
- }
- }
- }
- },
- setSrc: function(name, src) {
- //不能直接给audio赋src!一定要用这个函数!因为我要拿这里的src来判断有无src,因为貌似audio的src会自动变,''时会变成html的链接
- var object = this.list.find((e) => e.name == name);
- object.src = src;
- object.audio.src = src;
- Log(`${object.name} 设置src: ${src}`);
- },
- createAudio: function(object = {}) {
- //name, level, canplay
- if (!object.fake) {
- object.audio = new Audio();
- object.audio.loop = !!object.loop;
- //object.audio.autoplay = true;
- object.audio.addEventListener("ended", () => {
- if (object.loop) {
- //循环
- Log(`${object.name} 播放完毕,重新播放`);
- object.audio.play();
- } else {
- this.pause(object.name, true); //停止后的后续处理
- }
- });
- object.audio.oncanplaythrough = () => {
- Log(`${object.name} canplaythrough `);
- };
- }
- this.list.push(object);
- },
- initAutoPlay: function() {
- //处理设备自动播放限制
- let play = function() {
- if (this.currentAudio && this.currentAudio.audio && this.currentAudio.src) {
- this.currentAudio.audio.play();
- Log(`${this.currentAudio.name} 自动播放成功`); //即使设置src在这之后好像也能成功播放
- } else {
- }
- document.removeEventListener("touchstart", play);
- document.removeEventListener("click", play);
- $("#player")[0] && $("#player")[0].removeEventListener("touchstart", play);
- }.bind(this);
- document.addEventListener("WeixinJSBridgeReady", play, false);
- document.addEventListener("touchstart", play); //ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件
- document.addEventListener("click", play);
- $("#player")[0] && $("#player")[0].addEventListener("touchstart", play);
- },
- };
- function Log(value, color, fontSize) {
- color = color || "#13f";
- fontSize = fontSize || 14;
- console.warn(`%c${value}`, `color:${color};font-size:${fontSize}px`);
- }
- Manage.prototype.loadAudio = function() {
- //相关:g_tourAudio \ g_playAudio
- //热点页面因为挡住了界面,所以暂时不存在别的音频阻止热点音频的可能
- //box视频都静音,所以暂时不考虑
- SoundManager.createAudio({
- name: "bgm",
- level: 0,
- src: "",
- loop: true,
- canplay: (audio) => {
- return this.bgmShouldPlay;
- },
- callback: (state) => {
- //play或pause时随之触发的函数(即使还没开始播放)
- if (state) {
- $("#volume a img").attr("src", "./images/Volume btn_off.png");
- $("#volume").attr("title", "关闭声音");
- } else {
- $("#volume a img").attr("src", "./images/Volume btn_on.png");
- $("#volume").attr("title", "打开声音");
- }
- },
- });
- SoundManager.createAudio({
- name: "tour",
- level: 0,
- src: "",
- loop: false,
- canplay: (audio) => {
- return player.director && player.director.tourIsPlaying && player.director.getAudio();
- },
- });
- SoundManager.createAudio({
- name: "hot",
- fake: true, //实际上没有audio. 只是为了来停止和续播其他音频
- level: 1,
- src: "",
- loop: false,
- canplay: (audio) => {},
- });
- $("#volume")
- .find("a")
- .on("click", () => {
- if ($("#volume img")[0].src.indexOf("btn_on.png") > -1) {
- this.switchBgmState(true);
- } else if ($("#volume img")[0].src.indexOf("btn_off.png") > -1) {
- this.switchBgmState(false);
- }
- });
- this.switchBgmState(true); //初始设置允许播放bgm
- SoundManager.initAutoPlay();
- };
- Manage.prototype.switchBgmState = function(state) {
- //按钮的状态完全代表是否应该播放bgm,即使还没加载完
- this.bgmShouldPlay = state;
- if (state) {
- SoundManager.play("bgm");
- } else {
- SoundManager.pause("bgm");
- }
- /* if(!g_bgAudio || !g_bgAudio.src) return;
-
-
- var played = function(){
- console.log('begin play bgm');
- g_play = 1;
- g_playAudio = g_bgAudio;
-
- g_tourAudio && g_tourAudio.pause()
- }
- var paused = function(){
- g_play = 0;
- g_playAudio == g_bgAudio && (g_playAudio = null)
-
- }
-
- if(state ){
- g_bgAudio.play();
- if(g_bgAudio.paused){
- paused()
- }else{
- played()
- return true
- }
- }else{
- g_bgAudio.pause();
- paused()
- }
-
-
- g_bgAudio.pauseByHot = false
- g_bgAudio.pauseByTour = false */
- };
- var manage = new Manage();
- //处理cursor优先级
- var CursorDeal = {
- priorityEvent: [
- //在前面的优先级高
- { noIntersect: "not-allowed" },
- { addHot: "cell" },
- { hoverFootIcon: "pointer" },
- { hoverHot: "pointer" },
- { addLabel: "cell" },
- { moveLabel: "grab" },
- ],
- domElements: [$("#player")[0] && $("#player")[0]],
- list: [], //当前存在的cursor状态
- currentCursorIndex: null,
- /* init : function(viewer){
-
- this.priorityEvent.forEach(e=>{//刚开始Potree.resourcePath没值,现在换
- for(let i in e){
- e[i] = Common.replaceAll(e[i],'{Potree.resourcePath}',Potree.resourcePath)
- }
- })
-
- this.domElements = [viewer.renderArea, viewer.mapViewer.renderArea];
-
- viewer.addEventListener("CursorChange",(e)=>{
- if(e.action == 'add'){
- this.add(e.name)
- }else{
- this.remove(e.name)
- }
- })
-
-
- }, */
- add: function(name) {
- var priorityItem = this.priorityEvent.find((e) => e[name]);
- if (!priorityItem) {
- console.error("CursorDeal 未定义优先级 name:" + name);
- return;
- }
- if (!this.list.includes(name)) {
- this.judge({ addItem: priorityItem, name });
- this.list.push(name);
- }
- },
- remove: function(name) {
- var index = this.list.indexOf(name);
- if (index > -1) {
- this.list.splice(index, 1);
- this.judge();
- }
- },
- judge: function(o = {}) {
- //console.log(o,this.list)
- if (o.addItem) {
- var addIndex = this.priorityEvent.indexOf(o.addItem);
- if (addIndex < this.currentCursorIndex || this.currentCursorIndex == void 0) {
- this.domElements.forEach((e) => (e.style.cursor = o.addItem[o.name]));
- this.currentCursorIndex = addIndex;
- }
- } else {
- var levelMax = { index: Infinity, cursor: null };
- this.list.forEach((name) => {
- var priorityItem = this.priorityEvent.find((e) => e[name]);
- var index = this.priorityEvent.indexOf(priorityItem);
- if (index < levelMax.index) {
- levelMax.index = index;
- levelMax.cursor = priorityItem[name];
- }
- });
- this.currentCursorIndex = levelMax.index;
- this.domElements.forEach((e) => (e.style.cursor = levelMax.cursor || ""));
- }
- },
- };
- //兼容一代的場景
- //請求地址統一管理
- var g_onePregix = "https://bigscene.4dage.com/"; //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55
- var g_version = manage.number("version");
- g_version === "one" ? (g_Prefix = g_onePregix) : "";
|