This repository was archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathEntity.js
executable file
·97 lines (90 loc) · 2.47 KB
/
Entity.js
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
96
97
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule Entity
* @flow
*/
import * as React from 'react';
import ReactNative from 'ReactNative';
import requireNativeComponent from 'requireNativeComponent';
import resolveAssetSource from 'resolveAssetSource';
import type {ViewProps} from 'ViewPropTypes';
type EntitySource =
| {
gltf2: string,
}
| {
obj: string | number,
}
| {
mtl: string | number,
obj: string | number,
};
type Props = ViewProps & {
source: EntitySource,
};
/**
* Entity allows you to render 3D objects.
*
* Entity currently supports the Wavefront OBJ file format, a common
* representation for 3D models. In the future, we hope to expand this with
* the ability to initialize custom loaders at runtime.
*
* The external resource (or resources) containing the model information is
* provided using a `source` attribute, which is an object of key-value pairs
* mapping resource types to their locations.
*
* The following properties are currently supported:
*
* * `obj` - Location of an OBJ-formatted model.
* * `mtl` - Location of a MTL-formatted material (the companion to OBJ)
*
* These values can be static strings, asset() calls, or require() statements.
*
* ```
* // Entity with a material
* <Entity
* source={{
* obj: asset('sculpture.obj'),
* mtl: asset('sculpture.mtl'),
* }}
* />
*
* // Entity without a material
* <Entity
* source={{
* obj: asset('standalone.obj'),
* }}
* />
* ```
*/
const RCTEntity = requireNativeComponent('Model', null, {
nativeOnly: {},
});
export default class Entity extends ReactNative.NativeComponent<Props> {
render() {
const {source, ...rest} = this.props;
if (source) {
if (typeof source.mtl === 'number') {
source.mtl = resolveAssetSource(source.mtl);
}
if (typeof source.obj === 'number') {
source.obj = resolveAssetSource(source.obj);
}
}
rest.style = rest.style || {};
if (!rest.style.position) {
rest.style.position = 'absolute';
}
// default meshes to being a render group
if (!rest.style.renderGroup) {
rest.style.renderGroup = true;
}
return <RCTEntity {...rest} source={source} />;
}
}