scene_geometry_instance.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #include "scene_geometry_instance.h"
  17. #include "scene.h"
  18. namespace embree
  19. {
  20. GeometryInstance::GeometryInstance (Scene* parent, Geometry* geom)
  21. : Geometry(parent,Type(geom->type | INSTANCE), 1, geom->numTimeSteps, geom->flags), local2world(one), world2local(one), geom(geom)
  22. {
  23. enabling();
  24. }
  25. void GeometryInstance::count(ssize_t f)
  26. {
  27. if (geom->numTimeSteps == 1)
  28. {
  29. switch (geom->type) {
  30. case TRIANGLE_MESH: parent->instanced.numTriangles += f*ssize_t(geom->size()); break;
  31. case USER_GEOMETRY: parent->instanced.numUserGeometries += f*ssize_t(geom->size()); break;
  32. case BEZIER_CURVES: parent->instanced.numBezierCurves += f*ssize_t(geom->size()); break;
  33. case SUBDIV_MESH : parent->instanced.numSubdivPatches += f*ssize_t(geom->size()); break;
  34. default : throw_RTCError(RTC_INVALID_OPERATION,"cannot instantiate this geometry ");
  35. };
  36. }
  37. else
  38. {
  39. switch (geom->type) {
  40. case TRIANGLE_MESH: parent->instancedMB.numTriangles += f*ssize_t(geom->size()); break;
  41. case USER_GEOMETRY: parent->instancedMB.numUserGeometries += f*ssize_t(geom->size()); break;
  42. case BEZIER_CURVES: parent->instancedMB.numBezierCurves += f*ssize_t(geom->size()); break;
  43. case SUBDIV_MESH : parent->instancedMB.numSubdivPatches += f*ssize_t(geom->size()); break;
  44. default : throw_RTCError(RTC_INVALID_OPERATION,"cannot instantiate this geometry");
  45. };
  46. }
  47. }
  48. void GeometryInstance::enabling ()
  49. {
  50. geom->used++;
  51. count(+1);
  52. }
  53. void GeometryInstance::disabling()
  54. {
  55. geom->used--;
  56. count(-1);
  57. }
  58. void GeometryInstance::setMask (unsigned mask)
  59. {
  60. if (parent->isStatic() && parent->isBuild())
  61. throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified");
  62. this->mask = mask;
  63. Geometry::update();
  64. }
  65. void GeometryInstance::setTransform(const AffineSpace3fa& xfm, size_t timeStep)
  66. {
  67. if (parent->isStatic() && parent->isBuild())
  68. throw_RTCError(RTC_INVALID_OPERATION,"static scenes cannot get modified");
  69. if (timeStep != 0)
  70. throw_RTCError(RTC_INVALID_OPERATION,"geometry instances only support a single timestep");
  71. local2world = xfm;
  72. world2local = rcp(xfm);
  73. }
  74. }