浏览代码

added Ray.intersectsMesh and Ray.render

Adam Bowman 8 年之前
父节点
当前提交
e8bf070728
共有 1 个文件被更改,包括 31 次插入0 次删除
  1. 31 0
      src/Culling/babylon.ray.ts

+ 31 - 0
src/Culling/babylon.ray.ts

@@ -6,6 +6,9 @@
         private _tvec: Vector3;
         private _qvec: Vector3;
 
+        private _renderPoints: Vector3[];
+        private _renderLine: LinesMesh;
+
         constructor(public origin: Vector3, public direction: Vector3, public length: number = Number.MAX_VALUE) {
         }
 
@@ -193,6 +196,34 @@
             }
         }
 
+        public intersectsMesh(mesh:AbstractMesh, fastCheck?: boolean): PickingInfo {
+
+            var tm = Tmp.Matrix[0];
+
+            mesh.getWorldMatrix().invertToRef(tm);
+
+            var ray = Ray.Transform(this, tm);
+
+            return mesh.intersects(ray, fastCheck);
+
+        }
+
+        public render(scene: Scene, color:Color3): void{
+            
+            if(!this._renderLine){
+                this._renderPoints = [this.origin, this.origin.add(this.direction.scale(this.length))];
+                this._renderLine = Mesh.CreateLines("ray", this._renderPoints, scene, true);
+            }else{
+                this.origin.addToRef(this.direction.scale(this.length), this._renderPoints[1]);
+                Mesh.CreateLines("ray", this._renderPoints, scene, true, this._renderLine);
+            }
+
+            if(color){
+                this._renderLine.color = color;
+            }
+
+        }
+
         private static smallnum = 0.00000001;
         private static rayl = 10e8;