tencentcloud-webar 2.0.3-dev.3 → 2.0.3-dev.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var self = wx;(self.webpackChunktencentcloud_webar=self.webpackChunktencentcloud_webar||[]).push([[790],{2790:(t,n,o)=>{o.r(n),o.d(n,{PhysicsController:()=>c,PhysicsModelParser:()=>i});var i=function(){function t(t){this.CANNON=t}return t.prototype.parse=function(t){var n,o,i=this,s=[],e=new Map;return t.traverse((function(t){if(t.name){var n=t.name.toLowerCase();if(console.log('解析节点: "'.concat(t.name,'", 类型: ').concat(t.type,", 位置:"),t.position),/_\d+$/.test(n))console.log(" -> 跳过拆分子节点: ".concat(t.name));else if(i.isAnchor(n))e.has("anchor")||e.set("anchor",[]),e.get("anchor").push(t);else if(i.isChain(n)){var o=i.extractChainIndex(n),s="chain-".concat(o);e.has(s)||e.set(s,[]),e.get(s).push(t)}else i.isPendant(n)&&(e.has("pendant")||e.set("pendant",[]),e.get("pendant").push(t))}})),n=this.selectBestCandidate(e.get("anchor")),o=this.selectBestCandidate(e.get("pendant")),Array.from(e.keys()).filter((function(t){return t.startsWith("chain-")})).sort((function(t,n){return parseInt(t.split("-")[1])-parseInt(n.split("-")[1])})).forEach((function(t){var n=i.selectBestCandidate(e.get(t));n&&s.push(n)})),o&&!s.includes(o)&&s.push(o),console.log("解析结果:",{anchor:null==n?void 0:n.name,chains:s.map((function(t){return t.name})),pendant:null==o?void 0:o.name}),{anchorMesh:n,chainMeshes:s,pendantMesh:o}},t.prototype.selectBestCandidate=function(t){if(!t||0===t.length)return null;var n=t.filter((function(t){return"Group"===t.type}));if(n.length>0)return console.log(" -> 选择 Group: ".concat(n[0].name)),n[0];var o=t.filter((function(t){return"Mesh"===t.type}));return o.length>0?(console.log(" -> 选择 Mesh: ".concat(o[0].name)),o[0]):(console.log(" -> 选择默认: ".concat(t[0].name)),t[0])},t.prototype.isAnchor=function(t){return t.startsWith("anchor")},t.prototype.isChain=function(t){return t.startsWith("chain")},t.prototype.isPendant=function(t){return t.startsWith("pendant")},t.prototype.extractChainIndex=function(t){var n=t.match(/chain-(\d+)/);return n?parseInt(n[1])-1:0},t}(),s=function(){return s=Object.assign||function(t){for(var n,o=1,i=arguments.length;o<i;o++)for(var s in n=arguments[o])Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s]);return t},s.apply(this,arguments)},e=function(t,n,o,i){return new(o||(o=Promise))((function(s,e){function r(t){try{a(i.next(t))}catch(t){e(t)}}function h(t){try{a(i.throw(t))}catch(t){e(t)}}function a(t){var n;t.done?s(t.value):(n=t.value,n instanceof o?n:new o((function(t){t(n)}))).then(r,h)}a((i=i.apply(t,n||[])).next())}))},r=function(t,n){var o,i,s,e,r={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return e={next:h(0),throw:h(1),return:h(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function h(e){return function(h){return function(e){if(o)throw new TypeError("Generator is already executing.");for(;r;)try{if(o=1,i&&(s=2&e[0]?i.return:e[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,e[1])).done)return s;switch(i=0,s&&(e=[2&e[0],s.value]),e[0]){case 0:case 1:s=e;break;case 4:return r.label++,{value:e[1],done:!1};case 5:r.label++,i=e[1],e=[0];continue;case 7:e=r.ops.pop(),r.trys.pop();continue;default:if(!(s=r.trys,(s=s.length>0&&s[s.length-1])||6!==e[0]&&2!==e[0])){r=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]<s[3])){r.label=e[1];break}if(6===e[0]&&r.label<s[1]){r.label=s[1],s=e;break}if(s&&r.label<s[2]){r.label=s[2],r.ops.push(e);break}s[2]&&r.ops.pop(),r.trys.pop();continue}e=n.call(t,r)}catch(t){e=[6,t],i=0}finally{o=s=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,h])}}},h=function(t,n){var o="function"==typeof Symbol&&t[Symbol.iterator];if(!o)return t;var i,s,e=o.call(t),r=[];try{for(;(void 0===n||n-- >0)&&!(i=e.next()).done;)r.push(i.value)}catch(t){s={error:t}}finally{try{i&&!i.done&&(o=e.return)&&o.call(e)}finally{if(s)throw s.error}}return r},a=function(t,n,o){if(o||2===arguments.length)for(var i,s=0,e=n.length;s<e;s++)!i&&s in n||(i||(i=Array.prototype.slice.call(n,0,s)),i[s]=n[s]);return t.concat(i||Array.prototype.slice.call(n))},c=function(){function t(t,n){void 0===t&&(t={}),this.chainBodies=[],this.meshes=[],this.constraints=[],this.originalTransforms=[],this.spacing=1.2,this.ANCHOR_SWING_ANGLE=15,this.initialized=!1,this.groupScale=1,this.lastAnchorPosition={x:0,y:0,z:0},this.smoothedAnchorPosition={x:0,y:0,z:0},this.GRAVITY_SCALE=14.3,this.config=s({gravity:-9.8,damping:.8,mass:.05,swingAngle:5},t),this.anchorPoint=n||""}return t.prototype.init=function(t){var n;return e(this,void 0,Promise,(function(){var s,e,c,l,d,p,u,y,f,g,N,A,v,w,m;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),s=this,[4,o.e(541).then(o.bind(o,2415))];case 1:return s.CANNON=r.sent(),e=(null!==(n=this.config.gravity)&&void 0!==n?n:-9.8)*this.GRAVITY_SCALE,this.world=new this.CANNON.World({gravity:new this.CANNON.Vec3(0,e,0)}),this.world.solver.iterations=20,console.log("PhysicsController: cannon-es 加载成功"),c=new i(this.CANNON),l=c.parse(t),d=l.anchorMesh,p=l.chainMeshes,u=l.pendantMesh,d&&0!==p.length?(p.length>=1&&(y=d.position,f=p[0].position,console.log("=== 间距计算详情 ==="),console.log('锚点 "'.concat(d.name||"anchor",'" 位置:'),{x:y.x.toFixed(6),y:y.y.toFixed(6),z:y.z.toFixed(6)}),console.log('第一个链节 "'.concat(p[0].name||"chain_1",'" 位置:'),{x:f.x.toFixed(6),y:f.y.toFixed(6),z:f.z.toFixed(6)}),g=f.x-y.x,N=f.y-y.y,A=f.z-y.z,console.log("位置差值:",{deltaX:g.toFixed(6),deltaY:N.toFixed(6),deltaZ:A.toFixed(6)}),this.spacing=Math.sqrt(g*g+N*N+A*A),console.log("计算过程:"),console.log(" √(".concat(g.toFixed(6),"² + ").concat(N.toFixed(6),"² + ").concat(A.toFixed(6),"²)")),console.log(" = √(".concat((g*g).toFixed(6)," + ").concat((N*N).toFixed(6)," + ").concat((A*A).toFixed(6),")")),console.log(" = √".concat((g*g+N*N+A*A).toFixed(6))),console.log(" = ".concat(this.spacing.toFixed(6))),console.log("=== 所有链节间距离 ==="),v=y,w=d.name||"anchor",p.forEach((function(t,n){var o=t.position,i=t.name||"chain_".concat(n+1),s=Math.sqrt(Math.pow(o.x-v.x,2)+Math.pow(o.y-v.y,2)+Math.pow(o.z-v.z,2));console.log("".concat(w," → ").concat(i,": ").concat(s.toFixed(6))),v=o,w=i}))),console.log("PhysicsController: 模型间距 =",this.spacing,"m"),this.meshes=a([d],h(p),!1),u&&!p.includes(u)&&this.meshes.push(u),this.originalTransforms=this.meshes.map((function(t){return{position:{x:t.position.x,y:t.position.y,z:t.position.z},quaternion:{x:t.quaternion.x,y:t.quaternion.y,z:t.quaternion.z,w:t.quaternion.w}}})),this.createPhysicsBodies(),this.initialized=!0,console.log("PhysicsController: 初始化完成,".concat(this.chainBodies.length," 个链节")),[3,3]):(console.warn("PhysicsController: 未找到锚点或链节"),[2]);case 2:throw m=r.sent(),console.error("PhysicsController: 初始化失败",m),m;case 3:return[2]}}))}))},t.prototype.createPhysicsBodies=function(){var t,n,o,i,s,e,r=.3*this.spacing;this.hiddenAnchor=new this.CANNON.Body({mass:0,type:this.CANNON.Body.KINEMATIC,position:new this.CANNON.Vec3(0,0,0),shape:new this.CANNON.Sphere(.5*r)}),this.world.addBody(this.hiddenAnchor);var h=this.meshes[0];this.anchorBody=new this.CANNON.Body({mass:.5*(null!==(t=this.config.mass)&&void 0!==t?t:.05),position:new this.CANNON.Vec3((null==h?void 0:h.position.x)||0,(null==h?void 0:h.position.y)||0,(null==h?void 0:h.position.z)||0),shape:new this.CANNON.Sphere(r),linearDamping:.8,angularDamping:.8}),this.world.addBody(this.anchorBody);var a=new this.CANNON.DistanceConstraint(this.hiddenAnchor,this.anchorBody,0);this.world.addConstraint(a),this.constraints.push(a);var c=this.ANCHOR_SWING_ANGLE*Math.PI/180,l=new this.CANNON.ConeTwistConstraint(this.hiddenAnchor,this.anchorBody,{pivotA:new this.CANNON.Vec3(0,0,0),pivotB:new this.CANNON.Vec3(0,0,0),axisA:new this.CANNON.Vec3(0,1,0),axisB:new this.CANNON.Vec3(0,1,0),angle:c,twistAngle:.5*c});this.world.addConstraint(l),this.constraints.push(l);for(var d=this.meshes.slice(1),p=this.anchorBody,u=0;u<d.length;u++){var y=d[u],f=u===d.length-1,g=f?3*(null!==(n=this.config.mass)&&void 0!==n?n:.05):(null!==(o=this.config.mass)&&void 0!==o?o:.05)*(1+.1*u),N=new this.CANNON.Body({mass:g,position:new this.CANNON.Vec3(y.position.x,y.position.y,y.position.z),shape:new this.CANNON.Sphere(f?1.5*r:r),linearDamping:null!==(i=this.config.damping)&&void 0!==i?i:.5,angularDamping:.5*(null!==(s=this.config.damping)&&void 0!==s?s:.5)});this.world.addBody(N),this.chainBodies.push(N);var A=0===u?this.meshes[0]:d[u-1],v=y,w=A.position,m=v.position,x=Math.sqrt(Math.pow(m.x-w.x,2)+Math.pow(m.y-w.y,2)+Math.pow(m.z-w.z,2));console.log("约束距离 ".concat(A.name||"prev"," → ").concat(v.name||"current",": ").concat(x.toFixed(6)));var C=new this.CANNON.DistanceConstraint(p,N,x);this.world.addConstraint(C),this.constraints.push(C);var z=(null!==(e=this.config.swingAngle)&&void 0!==e?e:45)*Math.PI/180,B=new this.CANNON.ConeTwistConstraint(p,N,{pivotA:new this.CANNON.Vec3(0,-x/2,0),pivotB:new this.CANNON.Vec3(0,x/2,0),axisA:new this.CANNON.Vec3(0,1,0),axisB:new this.CANNON.Vec3(0,1,0),angle:z,twistAngle:0});this.world.addConstraint(B),this.constraints.push(B),p=N}},t.prototype.setGroupScale=function(t){t>0&&(this.groupScale=t)},t.prototype.update=function(t,n){var o=this;if(this.world&&this.initialized&&n){var i=this.groupScale||1,s=n.x/i,e=n.y/i,r=n.z/i;this.smoothedAnchorPosition.x+=.3*(s-this.smoothedAnchorPosition.x),this.smoothedAnchorPosition.y+=.3*(e-this.smoothedAnchorPosition.y),this.smoothedAnchorPosition.z+=.3*(r-this.smoothedAnchorPosition.z);var h=this.smoothedAnchorPosition.x-this.lastAnchorPosition.x,a=this.smoothedAnchorPosition.y-this.lastAnchorPosition.y,c=this.smoothedAnchorPosition.z-this.lastAnchorPosition.z;this.hiddenAnchor.position.x+=h,this.hiddenAnchor.position.y+=a,this.hiddenAnchor.position.z+=c,this.lastAnchorPosition.x=this.smoothedAnchorPosition.x,this.lastAnchorPosition.y=this.smoothedAnchorPosition.y,this.lastAnchorPosition.z=this.smoothedAnchorPosition.z,this.world.step(1/60,t,3);var l=this.meshes[0];l&&(l.position.x=this.anchorBody.position.x-this.hiddenAnchor.position.x,l.position.y=this.anchorBody.position.y-this.hiddenAnchor.position.y,l.position.z=this.anchorBody.position.z-this.hiddenAnchor.position.z),this.chainBodies.forEach((function(t,n){var i=o.meshes[n+1];i&&(i.position.x=t.position.x-o.hiddenAnchor.position.x,i.position.y=t.position.y-o.hiddenAnchor.position.y,i.position.z=t.position.z-o.hiddenAnchor.position.z,i.quaternion.set(t.quaternion.x,t.quaternion.y,t.quaternion.z,t.quaternion.w))}))}},t.prototype.setConfig=function(t){if(this.config=s(s({},this.config),t),void 0!==t.gravity&&this.world){var n=t.gravity*this.GRAVITY_SCALE;this.world.gravity.set(0,n,0)}void 0!==t.damping&&this.chainBodies.forEach((function(n){var o;n.linearDamping=t.damping,n.angularDamping=.5*(null!==(o=t.damping)&&void 0!==o?o:.5)}))},t.prototype.destroy=function(){var t,n,o=this;this.meshes.forEach((function(t,n){var i=o.originalTransforms[n];t&&i&&(t.position.x=i.position.x,t.position.y=i.position.y,t.position.z=i.position.z,t.quaternion.x=i.quaternion.x,t.quaternion.y=i.quaternion.y,t.quaternion.z=i.quaternion.z,t.quaternion.w=i.quaternion.w)})),this.originalTransforms=[],this.constraints.forEach((function(t){var n;return null===(n=o.world)||void 0===n?void 0:n.removeConstraint(t)})),this.constraints=[],this.hiddenAnchor&&(null===(t=this.world)||void 0===t||t.removeBody(this.hiddenAnchor),this.hiddenAnchor=null),this.anchorBody&&(null===(n=this.world)||void 0===n||n.removeBody(this.anchorBody),this.anchorBody=null),this.chainBodies.forEach((function(t){var n;return null===(n=o.world)||void 0===n?void 0:n.removeBody(t)})),this.chainBodies=[],this.meshes=[],this.world=null,this.CANNON=null,this.initialized=!1},t}()}}]);
1
+ var self = wx;(self.webpackChunktencentcloud_webar=self.webpackChunktencentcloud_webar||[]).push([[790],{2790:(t,i,n)=>{n.r(i),n.d(i,{PhysicsController:()=>c,PhysicsModelParser:()=>o});var o=function(){function t(t){this.CANNON=t}return t.prototype.parse=function(t){var i,n,o=this,s=[],e=new Map;return t.traverse((function(t){if(t.name){var i=t.name.toLowerCase();if(!/_\d+$/.test(i))if(o.isAnchor(i))e.has("anchor")||e.set("anchor",[]),e.get("anchor").push(t);else if(o.isChain(i)){var n=o.extractChainIndex(i),s="chain-".concat(n);e.has(s)||e.set(s,[]),e.get(s).push(t)}else o.isPendant(i)&&(e.has("pendant")||e.set("pendant",[]),e.get("pendant").push(t))}})),i=this.selectBestCandidate(e.get("anchor")),n=this.selectBestCandidate(e.get("pendant")),Array.from(e.keys()).filter((function(t){return t.startsWith("chain-")})).sort((function(t,i){return parseInt(t.split("-")[1])-parseInt(i.split("-")[1])})).forEach((function(t){var i=o.selectBestCandidate(e.get(t));i&&s.push(i)})),n&&!s.includes(n)&&s.push(n),{anchorMesh:i,chainMeshes:s,pendantMesh:n}},t.prototype.selectBestCandidate=function(t){if(!t||0===t.length)return null;var i=t.filter((function(t){return"Group"===t.type}));if(i.length>0)return i[0];var n=t.filter((function(t){return"Mesh"===t.type}));return n.length>0?n[0]:t[0]},t.prototype.isAnchor=function(t){return t.startsWith("anchor")},t.prototype.isChain=function(t){return t.startsWith("chain")},t.prototype.isPendant=function(t){return t.startsWith("pendant")},t.prototype.extractChainIndex=function(t){var i=t.match(/chain-(\d+)/);return i?parseInt(i[1])-1:0},t}(),s=function(){return s=Object.assign||function(t){for(var i,n=1,o=arguments.length;n<o;n++)for(var s in i=arguments[n])Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s]);return t},s.apply(this,arguments)},e=function(t,i,n,o){return new(n||(n=Promise))((function(s,e){function r(t){try{a(o.next(t))}catch(t){e(t)}}function h(t){try{a(o.throw(t))}catch(t){e(t)}}function a(t){var i;t.done?s(t.value):(i=t.value,i instanceof n?i:new n((function(t){t(i)}))).then(r,h)}a((o=o.apply(t,i||[])).next())}))},r=function(t,i){var n,o,s,e,r={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return e={next:h(0),throw:h(1),return:h(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function h(e){return function(h){return function(e){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,o&&(s=2&e[0]?o.return:e[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,e[1])).done)return s;switch(o=0,s&&(e=[2&e[0],s.value]),e[0]){case 0:case 1:s=e;break;case 4:return r.label++,{value:e[1],done:!1};case 5:r.label++,o=e[1],e=[0];continue;case 7:e=r.ops.pop(),r.trys.pop();continue;default:if(!(s=r.trys,(s=s.length>0&&s[s.length-1])||6!==e[0]&&2!==e[0])){r=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]<s[3])){r.label=e[1];break}if(6===e[0]&&r.label<s[1]){r.label=s[1],s=e;break}if(s&&r.label<s[2]){r.label=s[2],r.ops.push(e);break}s[2]&&r.ops.pop(),r.trys.pop();continue}e=i.call(t,r)}catch(t){e=[6,t],o=0}finally{n=s=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,h])}}},h=function(t,i){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,s,e=n.call(t),r=[];try{for(;(void 0===i||i-- >0)&&!(o=e.next()).done;)r.push(o.value)}catch(t){s={error:t}}finally{try{o&&!o.done&&(n=e.return)&&n.call(e)}finally{if(s)throw s.error}}return r},a=function(t,i,n){if(n||2===arguments.length)for(var o,s=0,e=i.length;s<e;s++)!o&&s in i||(o||(o=Array.prototype.slice.call(i,0,s)),o[s]=i[s]);return t.concat(o||Array.prototype.slice.call(i))},c=function(){function t(t,i){void 0===t&&(t={}),this.chainBodies=[],this.meshes=[],this.constraints=[],this.originalTransforms=[],this.spacing=1.2,this.ANCHOR_SWING_ANGLE=15,this.initialized=!1,this.groupScale=1,this.lastAnchorPosition={x:0,y:0,z:0},this.smoothedAnchorPosition={x:0,y:0,z:0},this.GRAVITY_SCALE=14.3,this.config=s({gravity:-9.8,damping:.8,mass:.05,swingAngle:5},t),this.anchorPoint=i||""}return t.prototype.init=function(t){var i;return e(this,void 0,Promise,(function(){var s,e,c,l,d,u,p,y,f,N,A,v;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),s=this,[4,n.e(541).then(n.bind(n,2415))];case 1:return s.CANNON=r.sent(),e=(null!==(i=this.config.gravity)&&void 0!==i?i:-9.8)*this.GRAVITY_SCALE,this.world=new this.CANNON.World({gravity:new this.CANNON.Vec3(0,e,0)}),this.world.solver.iterations=20,c=new o(this.CANNON),l=c.parse(t),d=l.anchorMesh,u=l.chainMeshes,p=l.pendantMesh,d&&0!==u.length?(u.length>=1&&(y=d.position,f=u[0].position,N=f.x-y.x,A=f.y-y.y,v=f.z-y.z,this.spacing=Math.sqrt(N*N+A*A+v*v)),this.meshes=a([d],h(u),!1),p&&!u.includes(p)&&this.meshes.push(p),this.originalTransforms=this.meshes.map((function(t){return{position:{x:t.position.x,y:t.position.y,z:t.position.z},quaternion:{x:t.quaternion.x,y:t.quaternion.y,z:t.quaternion.z,w:t.quaternion.w}}})),this.createPhysicsBodies(),this.initialized=!0,[3,3]):[2];case 2:throw r.sent();case 3:return[2]}}))}))},t.prototype.createPhysicsBodies=function(){var t,i,n,o,s,e,r=.3*this.spacing;this.hiddenAnchor=new this.CANNON.Body({mass:0,type:this.CANNON.Body.KINEMATIC,position:new this.CANNON.Vec3(0,0,0),shape:new this.CANNON.Sphere(.5*r)}),this.world.addBody(this.hiddenAnchor);var h=this.meshes[0];this.anchorBody=new this.CANNON.Body({mass:.5*(null!==(t=this.config.mass)&&void 0!==t?t:.05),position:new this.CANNON.Vec3((null==h?void 0:h.position.x)||0,(null==h?void 0:h.position.y)||0,(null==h?void 0:h.position.z)||0),shape:new this.CANNON.Sphere(r),linearDamping:.8,angularDamping:.8}),this.world.addBody(this.anchorBody);var a=new this.CANNON.DistanceConstraint(this.hiddenAnchor,this.anchorBody,0);this.world.addConstraint(a),this.constraints.push(a);var c=this.ANCHOR_SWING_ANGLE*Math.PI/180,l=new this.CANNON.ConeTwistConstraint(this.hiddenAnchor,this.anchorBody,{pivotA:new this.CANNON.Vec3(0,0,0),pivotB:new this.CANNON.Vec3(0,0,0),axisA:new this.CANNON.Vec3(0,1,0),axisB:new this.CANNON.Vec3(0,1,0),angle:c,twistAngle:.5*c});this.world.addConstraint(l),this.constraints.push(l);for(var d=this.meshes.slice(1),u=this.anchorBody,p=0;p<d.length;p++){var y=d[p],f=p===d.length-1,N=f?3*(null!==(i=this.config.mass)&&void 0!==i?i:.05):(null!==(n=this.config.mass)&&void 0!==n?n:.05)*(1+.1*p),A=new this.CANNON.Body({mass:N,position:new this.CANNON.Vec3(y.position.x,y.position.y,y.position.z),shape:new this.CANNON.Sphere(f?1.5*r:r),linearDamping:null!==(o=this.config.damping)&&void 0!==o?o:.5,angularDamping:.5*(null!==(s=this.config.damping)&&void 0!==s?s:.5)});this.world.addBody(A),this.chainBodies.push(A);var v=y,w=(0===p?this.meshes[0]:d[p-1]).position,g=v.position,m=Math.sqrt(Math.pow(g.x-w.x,2)+Math.pow(g.y-w.y,2)+Math.pow(g.z-w.z,2)),C=new this.CANNON.DistanceConstraint(u,A,m);this.world.addConstraint(C),this.constraints.push(C);var x=(null!==(e=this.config.swingAngle)&&void 0!==e?e:45)*Math.PI/180,B=new this.CANNON.ConeTwistConstraint(u,A,{pivotA:new this.CANNON.Vec3(0,-m/2,0),pivotB:new this.CANNON.Vec3(0,m/2,0),axisA:new this.CANNON.Vec3(0,1,0),axisB:new this.CANNON.Vec3(0,1,0),angle:x,twistAngle:0});this.world.addConstraint(B),this.constraints.push(B),u=A}},t.prototype.setGroupScale=function(t){t>0&&(this.groupScale=t)},t.prototype.update=function(t,i){var n=this;if(this.world&&this.initialized&&i){var o=this.groupScale||1,s=i.x/o,e=i.y/o,r=i.z/o;this.smoothedAnchorPosition.x+=.3*(s-this.smoothedAnchorPosition.x),this.smoothedAnchorPosition.y+=.3*(e-this.smoothedAnchorPosition.y),this.smoothedAnchorPosition.z+=.3*(r-this.smoothedAnchorPosition.z);var h=this.smoothedAnchorPosition.x-this.lastAnchorPosition.x,a=this.smoothedAnchorPosition.y-this.lastAnchorPosition.y,c=this.smoothedAnchorPosition.z-this.lastAnchorPosition.z;this.hiddenAnchor.position.x+=h,this.hiddenAnchor.position.y+=a,this.hiddenAnchor.position.z+=c,this.lastAnchorPosition.x=this.smoothedAnchorPosition.x,this.lastAnchorPosition.y=this.smoothedAnchorPosition.y,this.lastAnchorPosition.z=this.smoothedAnchorPosition.z,this.world.step(1/60,t,3);var l=this.meshes[0];l&&(l.position.x=this.anchorBody.position.x-this.hiddenAnchor.position.x,l.position.y=this.anchorBody.position.y-this.hiddenAnchor.position.y,l.position.z=this.anchorBody.position.z-this.hiddenAnchor.position.z),this.chainBodies.forEach((function(t,i){var o=n.meshes[i+1];o&&(o.position.x=t.position.x-n.hiddenAnchor.position.x,o.position.y=t.position.y-n.hiddenAnchor.position.y,o.position.z=t.position.z-n.hiddenAnchor.position.z,o.quaternion.set(t.quaternion.x,t.quaternion.y,t.quaternion.z,t.quaternion.w))}))}},t.prototype.setConfig=function(t){if(this.config=s(s({},this.config),t),void 0!==t.gravity&&this.world){var i=t.gravity*this.GRAVITY_SCALE;this.world.gravity.set(0,i,0)}void 0!==t.damping&&this.chainBodies.forEach((function(i){var n;i.linearDamping=t.damping,i.angularDamping=.5*(null!==(n=t.damping)&&void 0!==n?n:.5)}))},t.prototype.destroy=function(){var t,i,n=this;this.meshes.forEach((function(t,i){var o=n.originalTransforms[i];t&&o&&(t.position.x=o.position.x,t.position.y=o.position.y,t.position.z=o.position.z,t.quaternion.x=o.quaternion.x,t.quaternion.y=o.quaternion.y,t.quaternion.z=o.quaternion.z,t.quaternion.w=o.quaternion.w)})),this.originalTransforms=[],this.constraints.forEach((function(t){var i;return null===(i=n.world)||void 0===i?void 0:i.removeConstraint(t)})),this.constraints=[],this.hiddenAnchor&&(null===(t=this.world)||void 0===t||t.removeBody(this.hiddenAnchor),this.hiddenAnchor=null),this.anchorBody&&(null===(i=this.world)||void 0===i||i.removeBody(this.anchorBody),this.anchorBody=null),this.chainBodies.forEach((function(t){var i;return null===(i=n.world)||void 0===i?void 0:i.removeBody(t)})),this.chainBodies=[],this.meshes=[],this.world=null,this.CANNON=null,this.initialized=!1},t}()}}]);