Jump to content

GetIntersection depending normal


photo

Recommended Posts

Hi,

 

Sometimes inside our 3D shop depending of the camera position, the ray intersect with the roof of the shop.

 

Will be interesting if the getIntersection don't intersect with some object depending their normals orientation like :

#include "Sound.h"
#include "Render.h"
#include "Visualizer.h"
#include "Material.h"
#include "Property.h"
#include "MaterialManager.h"
#include "PropertyManager.h"
#include "Game.h"
#include "Physics.h"
#include "PathFind.h"
#include "Editor.h"
#include "Interpreter.h"
#include "EngineConsole.h"
#include "EngineExpression.h"
#include "EngineInterpreter.h"
#include "WorldSpatial.h"
#include "WorldSector.h"
#include "WorldCluster.h"
#include "WorldClutter.h"
#include "WorldTrigger.h"
#include "World.h"

Object *World::getIntersection(const Vec3 &p0,const Vec3 &p1,int mask,Vec3 &ret_point,vec3 &ret_normal,vec4 &ret_texcoord,int &ret_surface, int care_normal) {
	Vector<Node*> exclude;
	return getIntersection(p0,p1,mask,exclude,ret_point,ret_normal,ret_texcoord,ret_surface,care_normal);
}


Object *World::getIntersection(const Vec3 &p0,const Vec3 &p1,int mask,const Vector<Node*> &exclude,Vec3 &ret_point,vec3 &ret_normal,vec4 &ret_texcoord,int &ret_surface,int care_normals) {
	
      ...

      // object intersection
      mul(ip1,itransform,ret_point);
      if(object->getIntersection(ip0,ip1,ipoint,inormal,texcoord,triangle,surface) == 0) continue;
      mul(point,transform,Vec3(ipoint));
			
	
      float norm = 0;                                                 
      if (care_normals) {                                     
          vec3 p = p1 - p0;                                   
          vec3 n;                                                       
          p.normalizeFast();                                          
          mul3(n,transform,inormal);
          norm = dot( p, n.normalizeFast());                        
      }                                                                       

      // find nearest point
      if(length2(p0 - point) < length2(p0 - ret_point) && norm <= 0) {
          ret_point = point;
          mul3(ret_normal,transform,inormal);
          ret_normal.normalize();
          ret_texcoord = texcoord;
          ret_surface = surface;
          ret = object;
      }
   
      ...

      return ret;
}
Link to comment

BTW one extension of getIntersection() we were looking for was accounting for surface texture alpha e.g. in case of tree leaf billboards. This is something especially important for realistic simulation of laser range finders.

 

On a front-to-back basis the alpha values of all intersection points gets aggregated until some user-defined threshhold value is reached and this final intersection will be returned as result. Doing this iteratively in script proved to be a performance bottleneck.

Link to comment
  • 1 month later...

CPU side texture fetching will be a bottleneck on any case. Texture caching algorithm and texture coordinates modification based on material texture transformation expression is required. I will export "int getIntersection(const Vec3 &p0,const Vec3 &p1,Vector<Object*> &objects);" function to the script. After that intersection refinement function can be implemented on script side without performance drop.

 

Anthony, what about specific intersection mask for the roof?

Link to comment

Hi Frustum, i m not sure because i m not in charge of this part of developement but, i know we want have the possibility when we are inside the shop modify the texture of the roof (see by the client inside the shop) and for that we use intersection and work well but if we are outside we can't modify the template shop the outside part of the roof (no sure if i m really understandable ...) for that we use normal for detect if the picking and getIntersection come outside or inside the shop.

 

I can do that with mask ?? Because i need to talk with my developer but it seems that wasn't possible, the mask remove completely the detection of the roof whatever if we are inside or outside
 

Link to comment
  • 3 months later...

I will export "int getIntersection(const Vec3 &p0,const Vec3 &p1,Vector<Object*> &objects);" function to the script. After that intersection refinement function can be implemented on script side without performance drop.

 

Hi frustum, has this been implemented ? Can't find this version of engine.world.getIntersection()

Link to comment

I see, the still undocumented one Thanks :) Having a look into the source this will return all objects based on coarse bounding box/radius testing.

 

Therefore I guess it will be possible that for at least some returned objects a finer follow-on object.getIntersection() surface-level test might return null, right ? If so, it would be a good idea to cleary state this behaviour in the documentation to avoid unexpected results.

Link to comment
×
×
  • Create New...