-
Notifications
You must be signed in to change notification settings - Fork 1
/
MotionSpheres.cpp
96 lines (74 loc) · 3.33 KB
/
MotionSpheres.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// ======================================================================== //
// Copyright 2018-2020 The Contributors //
// //
// Licensed under the Apache License, Version 2.0 (the "License"); //
// you may not use this file except in compliance with the License. //
// You may obtain a copy of the License at //
// //
// http://www.apache.org/licenses/LICENSE-2.0 //
// //
// Unless required by applicable law or agreed to in writing, software //
// distributed under the License is distributed on an "AS IS" BASIS, //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and //
// limitations under the License. //
// ======================================================================== //
#include "glyphs/MotionSpheres.h"
namespace glyphs {
using device::GlyphsGeom;
extern "C" const char embedded_MotionSpheres_programs[];
MotionSpheres::MotionSpheres()
{
module = owlModuleCreate(context, embedded_MotionSpheres_programs);
OWLVarDecl glyphsVars[] = {
{ "links", OWL_BUFPTR, OWL_OFFSETOF(GlyphsGeom,links)},
{ "radius", OWL_FLOAT , OWL_OFFSETOF(GlyphsGeom,radius)},
{ /* sentinel to mark end of list */ }
};
glyphsType
= owlGeomTypeCreate(context,
OWL_GEOMETRY_USER,
sizeof(GlyphsGeom),
glyphsVars, -1);
owlGeomTypeSetBoundsProg(glyphsType, module,
"MotionSpheres");
owlGeomTypeSetIntersectProg(glyphsType, 0, module,
"MotionSpheres");
owlGeomTypeSetClosestHit(glyphsType, 0, module,
"MotionSpheres");
buildModules();
}
OWLGroup MotionSpheres::buildGlyphs(Glyphs::SP glyphs)
{
linkBuffer
= owlDeviceBufferCreate(context,
OWL_USER_TYPE(glyphs->links[0]),
glyphs->links.size(),
glyphs->links.data());
OWLGeom geom = owlGeomCreate(context, glyphsType);
owlGeomSetPrimCount(geom, glyphs->links.size());
owlGeomSetBuffer(geom, "links", linkBuffer);
owlGeomSet1f(geom, "radius", glyphs->radius);
owlBuildPrograms(context);
OWLGroup glyphsGroup = owlUserGeomGroupCreate(context, 1, &geom);
owlGroupBuildAccel(glyphsGroup);
return glyphsGroup;
}
void MotionSpheres::build(Glyphs::SP glyphs,
Triangles::SP triangles)
{
assert(glyphs != nullptr);
std::vector<OWLGroup> rootGroups;
OWLGroup glyphsGroup = buildGlyphs(glyphs);
if (glyphsGroup)
rootGroups.push_back(glyphsGroup);
if (triangles)
triangleGroup = buildTriangles(triangles);
if (triangleGroup)
rootGroups.push_back(triangleGroup);
this->world = owlInstanceGroupCreate(context, rootGroups.size());
for (int i=0;i<rootGroups.size();i++)
owlInstanceGroupSetChild(this->world, i, rootGroups[i]);
owlGroupBuildAccel(this->world);
}
}