Beispiel #1
0
void Sphere::Register(RTCScene scene, unsigned int geomID) {
    unsigned int obtainedGeomID = rtcNewUserGeometry(scene, 1);
    if(obtainedGeomID != geomID)
        throw std::runtime_error("Wrong geomID provided when registering a Sphere");
    m_GeomID = geomID;
    rtcSetUserData(scene, geomID, this);
    rtcSetBoundsFunction(scene, geomID, (RTCBoundsFunc)&BoundsFunc);
    rtcSetIntersectFunction(scene, geomID, (RTCIntersectFunc)&IntersectFunc);
    rtcSetOccludedFunction (scene, geomID, (RTCOccludedFunc )&OccludedFunc);
}
Sphere* createAnalyticalSpheres (RTCScene scene, size_t N)
{
  unsigned int geomID = rtcNewUserGeometry(scene,N);
  Sphere* spheres = new Sphere[N];
  for (int i=0; i<N; i++) spheres[i].geomID = geomID;
  rtcSetUserData(scene,geomID,spheres);
  rtcSetBoundsFunction(scene,geomID,(RTCBoundsFunc)&sphereBoundsFunc);
  rtcSetIntersectFunction(scene,geomID,(RTCIntersectFunc)&sphereIntersectFunc);
  rtcSetOccludedFunction (scene,geomID,(RTCOccludedFunc )&sphereOccludedFunc);
  return spheres;
}
Sphere* createAnalyticalSphere (RTCScene scene, Vec3f p, float r)
{
  unsigned int geomID = rtcNewUserGeometry(scene,1);
  Sphere* sphere = new Sphere;
  sphere->p = p;
  sphere->r = r;
  sphere->geomID = geomID;
  rtcSetUserData(scene,geomID,sphere);
  rtcSetBoundsFunction(scene,geomID,(RTCBoundsFunc)&sphereBoundsFunc);
  rtcSetIntersectFunction(scene,geomID,(RTCIntersectFunc)&sphereIntersectFunc);
  rtcSetOccludedFunction (scene,geomID,(RTCOccludedFunc )&sphereOccludedFunc);
  return sphere;
}
LazyGeometry* createLazyObject (RTCScene scene, int userID, const Vec3fa& center, const float radius)
{
    LazyGeometry* instance = new LazyGeometry;
    instance->state = LAZY_INVALID;
    instance->object = nullptr;
    instance->userID = userID;
    instance->center = center;
    instance->radius = radius;
    instance->geometry = rtcNewUserGeometry(scene,1);
    rtcSetUserData(scene,instance->geometry,instance);
    rtcSetBoundsFunction(scene,instance->geometry,(RTCBoundsFunc)&instanceBoundsFunc);
    rtcSetIntersectFunction(scene,instance->geometry,(RTCIntersectFunc)&instanceIntersectFunc);
    rtcSetOccludedFunction (scene,instance->geometry,(RTCOccludedFunc )&instanceOccludedFunc);
    return instance;
}
Instance* createInstance (RTCScene scene, RTCScene object, int userID, Vec3f lower, Vec3f upper)
{
  Instance* instance = new Instance;
  instance->object = object;
  instance->userID = userID;
  instance->lower = lower;
  instance->upper = upper;
  instance->local2world.l.vx = Vec3f(1,0,0);
  instance->local2world.l.vy = Vec3f(0,1,0);
  instance->local2world.l.vz = Vec3f(0,0,1);
  instance->local2world.p    = Vec3f(0,0,0);
  instance->geometry = rtcNewUserGeometry(scene,1);
  rtcSetUserData(scene,instance->geometry,instance);
  rtcSetBoundsFunction(scene,instance->geometry,(RTCBoundsFunc)&instanceBoundsFunc);
  rtcSetIntersectFunction(scene,instance->geometry,(RTCIntersectFunc)&instanceIntersectFunc);
  rtcSetOccludedFunction (scene,instance->geometry,(RTCOccludedFunc )&instanceOccludedFunc);
  return instance;
}
void Object::embreeInit(RTCDevice device) {

	Embree.scene = rtcDeviceNewScene(device, EMBREE_SFLAGS_OBJECT, EMBREE_AFLAGS_OBJECT);

	// Init embree for meshes
	for (uint i = 0; i < geometries.size(); i++) { // If it crashes here, then it can't find the .mtl or the last line is not empty

		uint geomID = geometries[i]->embreeInit(Embree.scene);
		Embree.geomIDmap[geomID] = geometries[i];

		// Set filter functions
		rtcSetOcclusionFilterFunction(Embree.scene, geomID, (RTCFilterFunc)&RayEngine::embreeOcclusionFilter);
		rtcSetOcclusionFilterFunction8(Embree.scene, geomID, (RTCFilterFunc8)&RayEngine::embreeOcclusionFilter8);
		rtcSetUserData(Embree.scene, geomID, userData);

	}

	rtcCommit(Embree.scene);

}