-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainScene3.js
65 lines (59 loc) · 1.64 KB
/
MainScene3.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
import React from 'react';
import { asset, Pano, View, Scene, Sphere } from 'react-vr';
import { Query } from 'react-apollo';
import gql from 'graphql-tag';
const PLANET_QUERY = gql`
query Planets {
allPlanets {
planets {
id
name
}
}
}
`;
const MAX_DISTANCE = 25;
const MIN_DISTANCE = 10;
const getTranslate = () => [
genPos(MIN_DISTANCE, MAX_DISTANCE), // x
genPos(MIN_DISTANCE, MAX_DISTANCE), // y
genPos(MIN_DISTANCE, MAX_DISTANCE) // z
];
const genPos = (min, range) =>
Math.max(min, Math.random() * range) * (Math.random() > 0.5 ? 1 : -1);
const TRANSLATE_ARRAY = [];
for (let i = 0; i <= 100; i++) {
TRANSLATE_ARRAY.push(getTranslate());
}
export default class MainScene extends React.Component {
render() {
return (
<Scene>
<Pano source={asset('textures/milky_way.jpg')}>
<Query query={PLANET_QUERY}>
{({ loading, error, data = [] }) => {
if (loading || error || !data.allPlanets) return null;
return (
<View>
{data.allPlanets.planets.map((planet, index) => (
<Sphere
key={planet.id}
wireframe={true}
radius={2}
widthSegments={10}
heightSegments={10}
style={{
transform: [{ translate: TRANSLATE_ARRAY[index] }],
color: 'red'
}}
/>
))}
</View>
);
}}
</Query>
</Pano>
</Scene>
);
}
}