let BaseNode=require("../Utils/BaseNode").BaseNode,RayHitInfo=require("../Utils/GraphHelper").RayHitInfo,APJS=require("../../../amazingpro"),Amaz=effect.Amaz;class CGRayCast extends BaseNode{constructor(){super(),this.collisionMask=16777215,this.hasHit=!1,this.hitInfoArray=[]}convertRayHitInfo(t){if(!t)return null;var i=t.colliderId,e=APJS.transferToAPJSObj(t.hitNormal),t=APJS.transferToAPJSObj(t.hitPoint),s=t.clone().subtract(this.origin).magnitude(),i=i<0?null:APJS.Physics3D.getInstance().colliderMap.get(i);let n=null,r=null,a=null;if(i){n=i.getSceneObject(),r=n?n.getComponent("RigidBody"):null;var o=n.getComponents();for(let t=0;t<o.length;t++){var h=o[t];if(h instanceof APJS.Collider&&h.enabled){a=h;break}}}return new RayHitInfo(n,a,t,e,s,r)}execute(t){if(this.type=this.inputs[1](),this.origin=this.inputs[2](),this.direction=this.inputs[3](),this.length=this.inputs[4](),null!==this.type&&null!==this.origin&&null!==this.direction&&null!==this.length){var i,e=this.origin.getNative(),s=this.direction.getNative();if(this.hitInfoArray=[],APJS.Physics3D.getCollisionFinder().updateTransforms(),"All"===this.type){APJS.Physics3D.getCollisionFinder().getNative().rayTestAllHits(e,s,this.length,this.collisionMask);var n=new Amaz.Vector,r=APJS.Physics3D.getCollisionFinder().rayHitCount();for(let t=0;t<r;++t)n.pushBack(new Amaz.AMGRayHitInfo);APJS.Physics3D.getCollisionFinder().getNative().getRayHitInfoList(n),this.hasHit=0<r;for(let t=0;t<r;++t){var a=n.get(t),a=this.convertRayHitInfo(a);this.hitInfoArray.push(a)}}else"Nearest"===this.type&&(i=new Amaz.AMGRayHitInfo,this.hasHit=APJS.Physics3D.getCollisionFinder().getNative().rayTestClosestHit(e,s,this.length,this.collisionMask,i),this.hasHit)&&(e=this.convertRayHitInfo(i),this.hitInfoArray.push(e))}this.nexts[0]&&this.nexts[0]()}getOutput(t){switch(t){case 1:return this.hasHit;case 2:return this.hitInfoArray;default:return null}}resetOnRecord(t){this.hitInfoArray=[],this.hasHit=!1}}exports.CGRayCast=CGRayCast;