mirror of
https://github.com/gre/gl-react.git
synced 2026-01-18 16:16:59 +00:00
61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
// @flow
|
|
import "webgltexture-loader-expo-camera";
|
|
import { RGBAFormat, RGBFormat } from "three";
|
|
import { Camera } from "expo-camera";
|
|
import * as Permissions from "expo-permissions";
|
|
import { resolveAsync } from "expo-asset-utils";
|
|
import { GLView } from "expo-gl";
|
|
|
|
import { Surface } from "gl-react-native";
|
|
export const name = "gl-react-native";
|
|
|
|
export { Surface };
|
|
|
|
export const EXGLView = GLView;
|
|
|
|
function GLImage() {
|
|
if (!(this instanceof GLImage)) {
|
|
throw new Error(
|
|
"Failed to construct 'Image': Please use the 'new' operator."
|
|
);
|
|
}
|
|
this.onload = null;
|
|
this._src = null;
|
|
}
|
|
|
|
GLImage.prototype = {
|
|
//$FlowFixMe
|
|
get src() {
|
|
return this._src;
|
|
},
|
|
//$FlowFixMe
|
|
set src(src) {
|
|
if (this._src === src) return;
|
|
delete this.localUri;
|
|
this._src = src;
|
|
|
|
if (src) {
|
|
resolveAsync(src).then(({ localUri }) => {
|
|
this.localUri = localUri;
|
|
if (this.onload) this.onload();
|
|
});
|
|
}
|
|
},
|
|
};
|
|
|
|
export const endFrame = (gl) => gl.endFrameEXP();
|
|
export const loadThreeJSTexture = (gl, src, texture) => {
|
|
let image = new GLImage();
|
|
image.onload = function () {
|
|
texture.image = image;
|
|
texture.format = RGBFormat;
|
|
texture.needsUpdate = true;
|
|
};
|
|
image.src = src;
|
|
};
|
|
export { Camera };
|
|
export const askCameraPermission = async () => {
|
|
const permission = await Permissions.askAsync(Permissions.CAMERA);
|
|
return permission;
|
|
};
|