|
|
@@ -0,0 +1,120 @@
|
|
|
+
|
|
|
+import * as THREE from "../../../../libs/three.js/build/three.module.js";
|
|
|
+import math from "../../utils/math.js";
|
|
|
+import browser from "../../utils/browser.js";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class TempImageSampler extends THREE.EventDispatcher{
|
|
|
+
|
|
|
+ constructor(){
|
|
|
+ super()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ getValue({data, width, height}, UVx, UVy, useNeighIfZero) {//根据图片像素获取深度值
|
|
|
+ var x = Math.round(UVx * (width - 1))
|
|
|
+ , y = Math.round(UVy * (height - 1));
|
|
|
+
|
|
|
+ let get = (x,y)=>{
|
|
|
+ let blockIndex = width * y + x
|
|
|
+ let color = data.slice(blockIndex*4, (blockIndex+1)*4)
|
|
|
+ return color[1] + (color[0] << 8) //为什么不是除以255见聊天记录.(验证过比点云的远一点点)
|
|
|
+ }
|
|
|
+
|
|
|
+ let value = get(x,y)
|
|
|
+ if(!value && useNeighIfZero){ //遇到过有的相隔很远且有阻挡的两个漫游点间居然depth为0,没有阻挡?但是周围点有四个非零。所以为了修正会飞到很远的点加个识别周围像素的depth 。 2024.3.19
|
|
|
+
|
|
|
+ let results = []
|
|
|
+ let d = 0, sum = 0, count = 0, maxResDis = 1, padding = 2 //间隔
|
|
|
+ outer2: while(d++<maxResDis){
|
|
|
+ outer: for(let i=-d;i<=d;i++){
|
|
|
+ for(let j=-d;j<=d;j++){
|
|
|
+ if(i==-d || i==d || j==-d || j==d ){//外围
|
|
|
+ let v2 = get(x+i*padding,y+j*padding)
|
|
|
+ if(v2!=0){
|
|
|
+ results.push(v2)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(results.length){
|
|
|
+ value = results.reduce((w,c)=>{return w+c},0) / results.length
|
|
|
+ //console.error('useNeighIfZero', results, depth)
|
|
|
+ }
|
|
|
+ //console.log('useNeighIfZero', results, depth)
|
|
|
+ }
|
|
|
+ value/=10
|
|
|
+ return {value,x,y}
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ sample( intersect, type, currentPano, useNeighIfZero, celsius ) {//通过和skybox的intersect得到真实的intersect的位置
|
|
|
+ if(!intersect)return
|
|
|
+ let uv
|
|
|
+
|
|
|
+
|
|
|
+ if(intersect.uv){
|
|
|
+ uv = intersect.uv
|
|
|
+ }else{
|
|
|
+ let origin = currentPano.position
|
|
|
+ let dir = intersect.dir || new THREE.Vector3().subVectors(intersect.point, origin).normalize()
|
|
|
+ //var uv = intersect.uv
|
|
|
+ //let dirInPano = math.getNormalDir(dir, currentPano)//转化为考虑漫游点旋转的方向
|
|
|
+
|
|
|
+ let dirInPano = dir.clone().applyMatrix4(currentPano.panoMatrix2Inverse).normalize(); //转化为考虑漫游点旋转的方向
|
|
|
+ uv = math.getUVfromDir(dirInPano)//转化为uv
|
|
|
+ }
|
|
|
+
|
|
|
+ let image = currentPano[type+'Tex']?.image
|
|
|
+ if(!image)return console.error( 'no'+ type+'Tex', currentPano)
|
|
|
+ let {value,x,y} = this.getValue(image, uv.x, uv.y, useNeighIfZero);
|
|
|
+
|
|
|
+
|
|
|
+ celsius && (value = math.getCelsiusFromKelvin(value))
|
|
|
+
|
|
|
+ if (!value ){
|
|
|
+ if(this.ignoreTopAndBtmHole){
|
|
|
+ return null
|
|
|
+ }
|
|
|
+ const margin = 0.1
|
|
|
+ /* if(uv.y > 1-Potree.config.depthTexUVyLimit){//漫游点底部识别不到的区域,给一个地板高度
|
|
|
+
|
|
|
+ depth = (currentPano.floorPosition.z - origin.z - margin) / dir.z
|
|
|
+ location.copy(dir).multiplyScalar(depth).add(origin);
|
|
|
+ let normal = new THREE.Vector3(0,0,1)
|
|
|
+
|
|
|
+ return {location, normal, distance:depth, uv}
|
|
|
+ }else if(uv.y < Potree.config.depthTexUVyLimit){
|
|
|
+ let ceilZ = currentPano.getCeilHeight()
|
|
|
+ if(ceilZ == Infinity)return !1
|
|
|
+ else{
|
|
|
+ depth = (ceilZ - origin.z - margin) / dir.z
|
|
|
+ location.copy(dir).multiplyScalar(depth).add(origin);
|
|
|
+ let normal = new THREE.Vector3(0,0,-1)
|
|
|
+ return {location, normal, distance:depth, uv}
|
|
|
+ }
|
|
|
+ } */
|
|
|
+ //console.log('无穷远')
|
|
|
+ return !1; //应该是天空或模型外 , 因为很少有漫游点的地方还拍不到地板
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('value', value )
|
|
|
+ return { value, x,y, uv }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+export default TempImageSampler
|
|
|
+
|
|
|
+
|