Пример #1
0
 int lookupSubdivMesh(Ref<SceneGraph::SubdivMeshNode> mesh)
 {
   Ref<SceneGraph::Node> node = mesh.dynamicCast<SceneGraph::Node>();
   if (geometry2id.find(node) == geometry2id.end())
     geometry2id[node] = convertSubdivMesh(mesh,one,one);
   return geometry2id[node];
 }
Пример #2
0
  void set_scene (OBJScene* in) 
  {
    ISPCScene* out = new ISPCScene;

    out->meshes = new ISPCMesh*[in->meshes.size()];
    for (size_t i=0; i<in->meshes.size(); i++) out->meshes[i] = convertMesh(in->meshes[i]);
    out->numMeshes = in->meshes.size();

    out->materials = (ISPCMaterial*) (in->materials.size() ? &in->materials[0] : NULL);
    out->numMaterials = in->materials.size();

    out->hairs = new ISPCHairSet*[in->hairsets.size()];
    for (size_t i=0; i<in->hairsets.size(); i++) out->hairs[i] = convertHair(in->hairsets[i]);
    out->numHairSets = in->hairsets.size();

    out->ambientLights = (ISPCAmbientLight*) (in->ambientLights.size() ? &in->ambientLights[0] : NULL);
    out->numAmbientLights = in->ambientLights.size();

    out->pointLights = (ISPCPointLight*) (in->pointLights.size() ? &in->pointLights[0] : NULL);
    out->numPointLights = in->pointLights.size();

    out->dirLights = (ISPCDirectionalLight*) (in->directionalLights.size() ? &in->directionalLights[0] : NULL);
    out->numDirectionalLights = in->directionalLights.size();

    out->distantLights = (ISPCDistantLight*) (in->distantLights.size() ? &in->distantLights[0] : NULL);
    out->numDistantLights = in->distantLights.size();

    out->subdiv = new ISPCSubdivMesh*[in->subdiv.size()];
    for (size_t i=0; i<in->subdiv.size(); i++) out->subdiv[i] = convertSubdivMesh(in->subdiv[i]);
    out->numSubdivMeshes = in->subdiv.size();

    g_ispc_scene = out;
  }
Пример #3
0
 void convert(Ref<SceneGraph::Node> node, const AffineSpace3fa& space0, const AffineSpace3fa& space1)
 {
   if (Ref<SceneGraph::TransformNode> xfmNode = node.dynamicCast<SceneGraph::TransformNode>()) {
     convert(xfmNode->child, space0*xfmNode->xfm0, space1*xfmNode->xfm1);
   } 
   else if (Ref<SceneGraph::GroupNode> groupNode = node.dynamicCast<SceneGraph::GroupNode>()) {
     for (auto child : groupNode->children) convert(child,space0,space1);
   }
   else if (Ref<SceneGraph::LightNode<AmbientLight> > ambientLight = node.dynamicCast<SceneGraph::LightNode<AmbientLight> >()) {
     scene->ambientLights.push_back(ambientLight->light.transform(space0));
   }
   else if (Ref<SceneGraph::LightNode<PointLight> > pointLight = node.dynamicCast<SceneGraph::LightNode<PointLight> >()) {
     scene->pointLights.push_back(pointLight->light.transform(space0));
   }
   else if (Ref<SceneGraph::LightNode<DirectionalLight> > directionalLight = node.dynamicCast<SceneGraph::LightNode<DirectionalLight> >()) {
     scene->directionalLights.push_back(directionalLight->light.transform(space0));
   }
   else if (Ref<SceneGraph::LightNode<SpotLight> > spotLight = node.dynamicCast<SceneGraph::LightNode<SpotLight> >()) {
     //scene->spotLights.push_back(spotLight->light.transform(space0));
   }
   else if (Ref<SceneGraph::LightNode<DistantLight> > distantLight = node.dynamicCast<SceneGraph::LightNode<DistantLight> >()) {
     scene->distantLights.push_back(distantLight->light.transform(space0));
   }
   else if (Ref<SceneGraph::TriangleMeshNode> mesh = node.dynamicCast<SceneGraph::TriangleMeshNode>()) 
   {
     if (instancing) scene->geometries.push_back(new TutorialScene::Instance(space0,lookupTriangleMesh(mesh)));
     //if (instancing) scene->geometries.push_back(new TutorialScene::Instance(space0,convertTriangleMesh(mesh,one,one)));
     else            convertTriangleMesh(mesh,space0,space1);
   }
   else if (Ref<SceneGraph::SubdivMeshNode> mesh = node.dynamicCast<SceneGraph::SubdivMeshNode>()) 
   {
     if (instancing) scene->geometries.push_back(new TutorialScene::Instance(space0,lookupSubdivMesh(mesh)));
     else            convertSubdivMesh(mesh,space0,space1);
   }
   else if (Ref<SceneGraph::HairSetNode> mesh = node.dynamicCast<SceneGraph::HairSetNode>()) 
   {
     if (instancing) scene->geometries.push_back(new TutorialScene::Instance(space0,lookupHairSet(mesh)));
     else            convertHairSet(mesh,space0,space1);
   }
 }
Пример #4
0
RTCScene convertScene(ISPCScene* scene_in)
{
  size_t numGeometries = scene_in->numGeometries;
  int scene_flags = RTC_SCENE_STATIC | RTC_SCENE_INCOHERENT;
  int scene_aflags = RTC_INTERSECT1 | RTC_INTERSECT_STREAM | RTC_INTERPOLATE;
  RTCScene scene_out = rtcDeviceNewScene(g_device, (RTCSceneFlags)scene_flags,(RTCAlgorithmFlags) scene_aflags);

  for (size_t i=0; i<scene_in->numGeometries; i++)
  {
    ISPCGeometry* geometry = scene_in->geometries[i];
    if (geometry->type == SUBDIV_MESH) {
      unsigned int geomID = convertSubdivMesh((ISPCSubdivMesh*) geometry, scene_out);
      assert(geomID == i);
    }
    else if (geometry->type == TRIANGLE_MESH) {
      unsigned int geomID = convertTriangleMesh((ISPCTriangleMesh*) geometry, scene_out);
      assert(geomID == i);
    }
    else if (geometry->type == QUAD_MESH) {
      unsigned int geomID = convertQuadMesh((ISPCQuadMesh*) geometry, scene_out);
      assert(geomID == i);
    }
    else if (geometry->type == LINE_SEGMENTS) {
      unsigned int geomID = convertLineSegments((ISPCLineSegments*) geometry, scene_out);
      assert(geomID == i);
    }
    else if (geometry->type == HAIR_SET) {
      unsigned int geomID = convertHairSet((ISPCHairSet*) geometry, scene_out);
      assert(geomID == i);
    }
    else if (geometry->type == CURVES) {
      unsigned int geomID = convertCurveGeometry((ISPCHairSet*) geometry, scene_out);
      assert(geomID == i);
    }
    else
      assert(false);
  }
  return scene_out;
}
Пример #5
0
  void createObject(const size_t i, ISPCScene* scene_in, RTCScene scene_out)
  {
    ISPCGeometry* geometry = scene_in->geometries[i];
    unsigned int geomID = 0;

    if (geometry->type == SUBDIV_MESH) {
      geomID = convertSubdivMesh((ISPCSubdivMesh*) geometry, scene_out);
      ((ISPCSubdivMesh*)geometry)->geom.geomID = geomID;
      assert(geomID == i);
    }
    else if (geometry->type == TRIANGLE_MESH) {
      geomID = convertTriangleMesh((ISPCTriangleMesh*) geometry, scene_out);
      ((ISPCTriangleMesh*)geometry)->geom.geomID = geomID;
      assert(geomID == i);
    }
    else if (geometry->type == QUAD_MESH) {
      geomID = convertQuadMesh((ISPCQuadMesh*) geometry, scene_out);
      ((ISPCQuadMesh*)geometry)->geom.geomID = geomID;
      assert(geomID == i);
    }
    else if (geometry->type == LINE_SEGMENTS) {
      geomID = convertLineSegments((ISPCLineSegments*) geometry, scene_out);
      ((ISPCLineSegments*)geometry)->geom.geomID = geomID;
      assert(geomID == i);
    }
    else if (geometry->type == HAIR_SET) {
      geomID = convertHairSet((ISPCHairSet*) geometry, scene_out);
      ((ISPCHairSet*)geometry)->geom.geomID = geomID;
      assert(geomID == i);
    }
    else if (geometry->type == CURVES) {
      geomID = convertCurveGeometry((ISPCHairSet*) geometry, scene_out);
      ((ISPCHairSet*)geometry)->geom.geomID = geomID;
      assert(geomID == i);
    }
    else
      assert(false);
  }
Пример #6
0
 void convertGeometries(std::vector<Ref<TutorialScene::Geometry>>& group, Ref<SceneGraph::Node> node, const SceneGraph::Transformations& spaces)
 {
   if (Ref<SceneGraph::TransformNode> xfmNode = node.dynamicCast<SceneGraph::TransformNode>()) {
     convertGeometries(group,xfmNode->child, spaces*xfmNode->spaces);
   } 
   else if (Ref<SceneGraph::GroupNode> groupNode = node.dynamicCast<SceneGraph::GroupNode>()) {
     for (auto child : groupNode->children) convertGeometries(group,child,spaces);
   }
   else if (Ref<SceneGraph::TriangleMeshNode> mesh = node.dynamicCast<SceneGraph::TriangleMeshNode>()) {
     group.push_back(convertTriangleMesh(mesh,spaces));
   }
   else if (Ref<SceneGraph::QuadMeshNode> mesh = node.dynamicCast<SceneGraph::QuadMeshNode>()) {
     group.push_back(convertQuadMesh(mesh,spaces));
   }
   else if (Ref<SceneGraph::SubdivMeshNode> mesh = node.dynamicCast<SceneGraph::SubdivMeshNode>()) {
     group.push_back(convertSubdivMesh(mesh,spaces));
   }
   else if (Ref<SceneGraph::LineSegmentsNode> mesh = node.dynamicCast<SceneGraph::LineSegmentsNode>()) {
     group.push_back(convertLineSegments(mesh,spaces));
   }
   else if (Ref<SceneGraph::HairSetNode> mesh = node.dynamicCast<SceneGraph::HairSetNode>()) {
     group.push_back(convertHairSet(mesh,spaces));
   }
 }