8 #ifndef META_OCEAN_INTERACTION_JS_EXTERNAL_H
9 #define META_OCEAN_INTERACTION_JS_EXTERNAL_H
109 inline Type type()
const;
116 template <
typename TNative>
117 inline TNative& value();
124 template <
typename TNative>
125 static inline Type type();
147 template <
typename TNative>
148 static inline void setValue(v8::Local<v8::Object>&
object, TNative&& value);
156 template <
typename TNative>
157 static inline void setValue(v8::Local<v8::Object>&
object,
const TNative& value);
166 template <
typename TNative>
167 static JSExternal* create(TNative* data, v8::Local<v8::Object>& owner, v8::Isolate* isolate);
178 JSExternal(
void* data,
const Type type, v8::Local<v8::Object>& owner, v8::Isolate* isolate);
209 template <
typename TNative>
212 return new JSExternal((
void*)(data), type<TNative>(), owner, isolate);
223 ocean_assert(
data_ !=
nullptr);
232 ocean_assert(
data_ !=
nullptr);
241 ocean_assert(
data_ !=
nullptr);
250 ocean_assert(
data_ !=
nullptr);
259 ocean_assert(
data_ !=
nullptr);
268 ocean_assert(
data_ !=
nullptr);
277 ocean_assert(
data_ !=
nullptr);
286 ocean_assert(
data_ !=
nullptr);
295 ocean_assert(
data_ !=
nullptr);
304 ocean_assert(
data_ !=
nullptr);
313 ocean_assert(
data_ !=
nullptr);
322 ocean_assert(
data_ !=
nullptr);
325 return *
static_cast<RGBAColor*
>(
data_);
331 ocean_assert(
data_ !=
nullptr);
340 ocean_assert(
data_ !=
nullptr);
349 ocean_assert(
data_ !=
nullptr);
358 ocean_assert(
data_ !=
nullptr);
367 ocean_assert(
data_ !=
nullptr);
376 ocean_assert(
data_ !=
nullptr);
382 template <
typename TNative>
385 static_assert(oceanFalse<TNative>(),
"This function is not defined for the data type");
391 return TYPE_DEVICE_SAMPLE;
427 return TYPE_RENDERING_ENGINE;
433 return TYPE_RENDERING_OBJECT;
440 return TYPE_MEDIA_OBJECT;
446 return TYPE_SCENE_DESCRIPTION_NODE;
497 template <
typename TNative>
500 static_assert(oceanFalse<TNative>(),
"This function is not defined for the data type");
504 template <
typename TNative>
508 ocean_assert(externalObject !=
nullptr);
510 externalObject->
value<TNative>() = std::move(
value);
513 template <
typename TNative>
517 ocean_assert(externalObject !=
nullptr);
This class implements an euler rotation with angles: yaw, pitch and roll.
Definition: Euler.h:80
This class is a lightweight helper class for device objects to allow event callback handling.
Definition: JSDevice.h:35
This class implements a type-safe object wrapper for non-JavaScript objects.
Definition: JSExternal.h:50
Type type() const
Returns the type of the wrapped C++ object.
Definition: JSExternal.h:215
static void destructorCallback(const v8::WeakCallbackInfo< JSExternal > &info)
The callback function which will be called from v8 once the wrapped object is not used anymore.
~JSExternal()
Destructs this object.
v8::Persistent< v8::Object > persistent_
The v8 Persistent object ensuring that we get informed when the JS object is not needed anymore.
Definition: JSExternal.h:206
static JSExternal * create(TNative *data, v8::Local< v8::Object > &owner, v8::Isolate *isolate)
Creates a new type-safe wrapper object for a specific native C++ object.
Definition: JSExternal.h:210
static JSExternal * external(const v8::Local< v8::Object > &object)
Returns the external object from a given JavaScript object.
TNative & value()
Returns the wrapped C++ object.
Definition: JSExternal.h:383
static void setValue(v8::Local< v8::Object > &object, TNative &&value)
Sets or changes the native C++ object of an external JavaScript object.
Definition: JSExternal.h:505
static JSExternal * external(const v8::Local< v8::Value > &value)
Returns the external object from a given JavaScript object.
void * data_
The pointer to the actual native object.
Definition: JSExternal.h:200
Type type_
The type of the native object.
Definition: JSExternal.h:203
JSExternal(const JSExternal &)=delete
Disabled copy constructor.
JSExternal & operator=(JSExternal &)=delete
Disabled assign operator.
JSExternal(void *data, const Type type, v8::Local< v8::Object > &owner, v8::Isolate *isolate)
Creates a new type-safe wrapper object for a specific native C++ object.
Type
Definition of different external object types.
Definition: JSExternal.h:57
@ TYPE_RENDERING_OBJECT
Rendering object object.
Definition: JSExternal.h:81
@ TYPE_SQUARE_MATRIX_3
SquareMatrix3 object.
Definition: JSExternal.h:87
@ TYPE_ROTATION
Rotation object.
Definition: JSExternal.h:83
@ TYPE_DEVICE_SAMPLE
Device sample object.
Definition: JSExternal.h:65
@ TYPE_VECTOR_2
Vector2 object.
Definition: JSExternal.h:91
@ TYPE_SQUARE_MATRIX_4
SquareMatrix4 object.
Definition: JSExternal.h:89
@ TYPE_SCENE_DESCRIPTION_NODE
Scene description node.
Definition: JSExternal.h:85
@ TYPE_VECTOR_4
Vector4 object.
Definition: JSExternal.h:95
@ TYPE_EULER
Euler object.
Definition: JSExternal.h:67
@ TYPE_VECTOR_3
Vector3 object.
Definition: JSExternal.h:93
@ TYPE_DEVICE_OBJECT
Device object object.
Definition: JSExternal.h:63
@ TYPE_QUATERNION
Quaternion object.
Definition: JSExternal.h:77
@ TYPE_RENDERING_ENGINE
Rendering engine object.
Definition: JSExternal.h:79
@ TYPE_UNDEFINED
Undefined object.
Definition: JSExternal.h:59
@ TYPE_PLANE_3
Plane3 object.
Definition: JSExternal.h:75
@ TYPE_COLOR
Color object.
Definition: JSExternal.h:61
@ TYPE_MEDIA_OBJECT
Media object object.
Definition: JSExternal.h:73
@ TYPE_LINE_3
Line3 object.
Definition: JSExternal.h:71
@ TYPE_HOMOGENOUS_MATRIX_4
HomogenousMatrix4 object.
Definition: JSExternal.h:69
This template class implements a object reference with an internal reference counter.
Definition: base/ObjectRef.h:58
QuaternionT< Scalar > Quaternion
Definition of the Quaternion object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with sin...
Definition: Quaternion.h:33
LineT3< Scalar > Line3
Definition of the Line3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single o...
Definition: Line3.h:21
SquareMatrixT3< Scalar > SquareMatrix3
Definition of the SquareMatrix3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with ...
Definition: SquareMatrix3.h:35
RotationT< Scalar > Rotation
Definition of the Rotation object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag either with ...
Definition: Rotation.h:31
VectorT4< Scalar > Vector4
Definition of a 4D vector.
Definition: Vector4.h:22
VectorT3< Scalar > Vector3
Definition of a 3D vector.
Definition: Vector3.h:22
PlaneT3< Scalar > Plane3
Definition of the Plane3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single ...
Definition: Plane3.h:24
SquareMatrixT4< Scalar > SquareMatrix4
Definition of the SquareMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with ...
Definition: SquareMatrix4.h:32
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition: Vector2.h:21
Ocean::ObjectRef< Engine > EngineRef
Definition of an engine reference object.
Definition: Engine.h:24
Ocean::ObjectRef< Object > ObjectRef
Definition of a rendering object reference with an internal reference counter.
Definition: Object.h:28
Ocean::ObjectRef< Node > NodeRef
Definition of a scene description node reference with an internal reference counter.
Definition: scenedescription/Node.h:29
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15