-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagx_write_example.cpp
More file actions
70 lines (56 loc) · 1.73 KB
/
agx_write_example.cpp
File metadata and controls
70 lines (56 loc) · 1.73 KB
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
// Copyright 2025 Jefferson Amstutz
// SPDX-License-Identifier: Apache-2.0
// std
#include <cmath>
#include <vector>
// agx
#define AGX_WRITE_IMPL
#include "agx/agx_write.h"
int main()
{
AGXExporter ex = agxNewExporter();
// Set subtype
agxSetObjectSubtype(ex, "triangle");
// Set constants
const float bboxMin[3] = {0.f, 0.f, 0.f};
const float bboxMax[3] = {1.f, 1.f, 1.f};
agxSetParameter(ex, "bbox.min", ANARI_FLOAT32_VEC3, bboxMin);
agxSetParameter(ex, "bbox.max", ANARI_FLOAT32_VEC3, bboxMax);
// Constant index array (triangles)
std::vector<uint32_t> index = {0, 1, 2, 2, 3, 0};
agxSetParameterArray1D(
ex, "primitive.index", ANARI_UINT32_VEC3, index.data(), index.size() / 3);
// Time steps
const uint32_t T = 4;
agxSetTimeStepCount(ex, T);
// Per-time-step positions
std::vector<float> positions;
positions.resize(4 * 3);
for (uint32_t t = 0; t < T; ++t) {
agxBeginTimeStep(ex, t);
// 4 vertices, each vec3
float phase = 0.5f * t;
positions[0] = 0.f;
positions[1] = 0.f;
positions[2] = std::sin(phase);
positions[3] = 1.f;
positions[4] = 0.f;
positions[5] = std::cos(phase);
positions[6] = 1.f;
positions[7] = 1.f;
positions[8] = std::sin(phase + 0.3f);
positions[9] = 0.f;
positions[10] = 1.f;
positions[11] = std::cos(phase + 0.3f);
agxSetTimeStepParameterArray1D(
ex, t, "vertex.position", ANARI_FLOAT32_VEC3, positions.data(), 4);
// Also a per-time-step single value
float timeValue = float(t) / float(T - 1);
agxSetTimeStepParameter(ex, t, "time", ANARI_FLOAT32, &timeValue);
agxEndTimeStep(ex, t);
}
// Write file
int rc = agxWrite(ex, "animated_geometry_dump.agxb");
agxReleaseExporter(ex);
return rc;
}