SuperDex Physics C++ API
Loading...
Searching...
No Matches
mochi_context_inl.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
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
17#pragma once
18
19#include "mochi_context.h" // Reverse include for intellisense
20
21namespace superdex {
22
23inline ShapeHandle
24Context::LoadShapeFromFile(std::string_view filePath, Real3 const& bakeScale, Error& error) {
25 return LoadShapeFromFile(filePath, bakeScale, TransformRT::Identity(), error);
26}
27
29 std::string_view filePath,
30 TransformRT const& bakeTransform,
31 Error& error) {
32 return LoadShapeFromFile(filePath, Real3{1_r, 1_r, 1_r}, bakeTransform, error);
33}
34
36 Span<char const> fileData,
37 MeshFileType format,
38 Real3 const& bakeScale,
39 Error& error) {
40 return LoadShapeFromBytes(fileData, format, bakeScale, TransformRT::Identity(), error);
41}
42
44 Span<char const> fileData,
45 MeshFileType format,
46 TransformRT const& bakeTransform,
47 Error& error) {
48 return LoadShapeFromBytes(fileData, format, Real3{1_r, 1_r, 1_r}, bakeTransform, error);
49}
50
54
55inline ShapeHandle
56Context::LoadShapeFromBytes(Span<char const> fileData, Real3 const& bakeScale, Error& error) {
57 return LoadShapeFromBytes(
58 fileData, MeshFileType::Legacy, bakeScale, TransformRT::Identity(), error);
59}
60
62 Span<char const> fileData,
63 TransformRT const& bakeTransform,
64 Error& error) {
65 return LoadShapeFromBytes(
66 fileData, MeshFileType::Legacy, Real3{1_r, 1_r, 1_r}, bakeTransform, error);
67}
68
70 Span<char const> fileData,
71 Real3 const& bakeScale,
72 TransformRT const& bakeTransform,
73 Error& error) {
74 return LoadShapeFromBytes(fileData, MeshFileType::Legacy, bakeScale, bakeTransform, error);
75}
76
77inline void Context::EnableLogChannel(LogChannel channel, bool enable) {
78 // Enable the log channel in the calling library or executable.
79 superdex::EnableLogChannel(channel, enable);
80
81 // Also enable inside the mochi_physics library. This is not redundant if mochi_physics is
82 // compiled as a DLL on Windows because static variables are not shared across DLL boundaries.
84}
85
86inline void Context::SetLogCallback(LogFn callback) {
87 // Set the log callback in the calling library or executable.
89
90 // Also set it inside the mochi_physics library. This is not redundant if mochi_physics is
91 // compiled as a DLL on Windows because static variables are not dynamically linked on Windows.
93}
94
96 // Set the assertion failure callback in the calling library or executable.
97 superdex::SetAssertionFailureCallback(callback);
98
99 // Also set it inside the mochi_physics library. This is not redundant if mochi_physics is
100 // compiled as a DLL on Windows because static variables are not dynamically linked on Windows.
101 superdex::Context::SetAssertionFailureCallbackInternal(callback);
102}
103
104} // namespace superdex
static void EnableLogChannel(LogChannel channel, bool enable)
Enable or disable log messages on the specified channel.
static void EnableLogChannelInternal(LogChannel channel, bool enable)
virtual ShapeHandle LoadShapeFromBytes(Span< char const > fileData, MeshFileType format, Error &error)=0
Load a shape from a file of supported format, where the file has already been loaded into memory,...
static void SetLogCallbackInternal(LogFn callback)
static void SetLogCallback(LogFn callback)
Optionally provide a callback function to redirect SuperDex Physics logging.
static void SetAssertionFailureCallback(OnAssertFn callback)
Optionally provide a callback function to customize the way in which assertion failures are reported.
virtual ShapeHandle LoadShapeFromFile(std::string_view filePath, Error &error)=0
Load a shape from a file of supported format.
static TransformRT Identity()
std::function< void(LogChannel, char const *message, char const *file, int line)> LogFn
Definition log.h:65
LogChannel
Definition log.h:37
void EnableLogChannel(LogChannel channel, bool enable)
Definition log.h:183
void SetLogCallback(LogFn fn)
Definition log.h:175
MeshFileType
Mesh file format hint for Context::LoadShapeFromBytes and model-loading APIs that read from byte buff...
Definition model_data.h:320
@ Legacy
Auto-detect between HDF5 and JSON (default behavior).
Definition model_data.h:321
NdArray< real, 3 > Real3
Definition nd_array.h:106
std::function< bool(char const *condition, char const *message, char const *file, int line)> OnAssertFn
Callback invoked when an assertion fails.
Definition debug.h:140
Handle to a shape (mesh, sphere, plane, etc.) within a Context.