diff --git a/src/Scene3.jsx b/src/Scene3.jsx
index 730c0b6..c8ad928 100644
--- a/src/Scene3.jsx
+++ b/src/Scene3.jsx
@@ -1,125 +1,39 @@
-import { Canvas, useFrame, useThree } from "@react-three/fiber";
-import { OrbitControls, PerspectiveCamera } from "@react-three/drei";
-import React, {
- Suspense,
- useState,
- useEffect,
- useRef,
- createContext,
- useContext,
- forwardRef,
- memo,
- useMemo,
-} from "react";
-import { Earth } from "./earth.jsx";
-import { Mars } from "./mars.jsx";
-import { Jupiter } from "./jupiter.jsx";
-import { Saturn } from "./saturn.jsx";
-import { Mercury } from "./mercury.jsx";
-import { Venus } from "./venus.jsx";
-import { Neptune } from "./neptune.jsx";
-import { Uranus } from "./uranus.jsx";
-import { Sun } from "./sun.jsx";
-import * as THREE from "three";
-import { PlanetInfo } from "./planetInfo.jsx";
+import { Canvas } from "@react-three/fiber";
+import { OrbitControls } from "@react-three/drei";
+import React, { Suspense, useRef, createContext, memo } from "react";
+
+import { ScreenOverlay } from "./omnioverlay.jsx";
+import { SharedPlanetState } from "./SharedPlanetState.jsx";
import { Skybox } from "./skybox.jsx";
-import {
- Selection,
- Select,
- EffectComposer,
- Outline,
-} from "@react-three/postprocessing";
export const MyContext = createContext();
-export const OtherContext = createContext();
-
-import { SharedPlanetState } from "./SharedPlanetState.jsx";
const SolarSystemScene = () => {
- const [data, setData] = useState(null);
- const [vis, setVis] = useState("hidden");
const controls = useRef();
- const planetinfo = useRef();
let customData = useRef({});
- useEffect(() => {
- const fetchData = async () => {
- let res = await fetch(
- "http://127.0.0.1:8000/duration?date=2023-08-06T21:53" //example and simple data
- );
- let response = await res.json();
- setData(response); // parse json
- //console.log(response);
- };
- fetchData();
- }, []);
-
- function toggleVisibility() {
- console.log(vis);
- if (vis === "hidden") {
- setVis("visible");
- console.log("what");
- } else if (vis === "visible") {
- setVis("hidden");
- console.log("asdasd");
- }
- }
-
- function handleChange(event) {
- console.log(event.target.value);
- customData.current.changeEarthSpeed(event.target.value);
- customData.current.changeMarsSpeed(event.target.value);
- customData.current.changeVenusSpeed(event.target.value);
- customData.current.changeSaturnSpeed(event.target.value);
- customData.current.changeUranusSpeed(event.target.value);
- customData.current.changeJupiterSpeed(event.target.value);
- customData.current.changeMercurySpeed(event.target.value);
- customData.current.changeNeptuneSpeed(event.target.value);
- }
-
- if (data)
- return (
- <>
-
-
-
-
-
-
-
-
-
- >
- );
+ return (
+ <>
+
+
+
+
+
+
+ >
+ );
};
const Smemo = memo(SolarSystemScene, true);
diff --git a/src/SharedPlanetState.jsx b/src/SharedPlanetState.jsx
index e6dcd14..26da2bc 100644
--- a/src/SharedPlanetState.jsx
+++ b/src/SharedPlanetState.jsx
@@ -23,74 +23,105 @@ import { Sun } from "./sun.jsx";
import * as THREE from "three";
import { PlanetInfo } from "./planetInfo.jsx";
import { Skybox } from "./skybox.jsx";
-import {
- Selection,
- Select,
- EffectComposer,
- Outline,
-} from "@react-three/postprocessing";
+import { ReactPropTypes } from "react";
+import { MyContext } from "./Scene3.jsx";
export const SharedPlanetState = () => {
- const [data, setData] = useState(null);
- const [vis, setVis] = useState("hidden");
- const controls = useRef();
- const planetinfo = useRef();
- let customData = useRef({});
+ const { customData } = useContext(MyContext);
- function toggleVisibility() {
- console.log(vis);
- if (vis === "hidden") {
- setVis("visible");
- console.log("what");
- } else if (vis === "visible") {
- setVis("hidden");
- console.log("asdasd");
+ let [nameVis, setNameVis] = useState("visible");
+ let [iconVis, setIconVis] = useState("visible");
+
+ const handleVisibility = () => {
+ if (nameVis == "visible" && iconVis == "visible") {
+ setNameVis("hidden");
+ console.log(nameVis);
+ console.log("hiding names");
+ } else if (nameVis == "hidden" && iconVis == "visible") {
+ setIconVis("hidden");
+ console.log(nameVis);
+ console.log("hiding icons");
+ } else if (nameVis == "hidden" && iconVis == "hidden") {
+ setIconVis("visible");
+ setNameVis("visible");
+ console.log(nameVis);
+ console.log("showing everything");
}
- }
+ };
+ customData.current["handleVisibility"] = handleVisibility;
- function handleChange(event) {
- console.log(event.target.value);
- customData.current.changeEarthSpeed(event.target.value);
- customData.current.changeMarsSpeed(event.target.value);
- customData.current.changeVenusSpeed(event.target.value);
- customData.current.changeSaturnSpeed(event.target.value);
- customData.current.changeUranusSpeed(event.target.value);
- customData.current.changeJupiterSpeed(event.target.value);
- customData.current.changeMercurySpeed(event.target.value);
- customData.current.changeNeptuneSpeed(event.target.value);
- }
+ //set speed (timeinterval between positions 60000ms*speed)
+ const [speed, setSpeed] = useState(0);
+ const updateSpeed = (newSpeed) => {
+ setSpeed(newSpeed);
+ speedChanged.current = true;
+ };
+ customData.current["updateSpeed"] = updateSpeed;
- const [speed, setSpeed] = useState();
+ //get position data and reset if necessary
+ const dateTime = useRef(new Date(Date.now()));
+ const speedChanged = useRef(false);
+
+ const getPositions = (planet, setPosState, oldState, posCounter) => {
+ //if speed was changed delete old data an get new data
+
+ //???????Why when i set the speed to 0 it doesnt immidiatly stop? good enough for know
+ if (speedChanged.current) {
+ console.log(oldState.length);
+ setPosState(oldState.slice(0, posCounter));
+ speedChanged.current = true;
+ console.log(oldState.length);
+ console.log("SPEEDUPDOWNLEFTRIGHT!");
+ }
+
+ if (posCounter % 250 == 0 || speedChanged.current) {
+ if (oldState.length > 0 && speed > 0) {
+ dateTime.current = new Date(
+ oldState[oldState.length - 1].date
+ ).toUTCString();
+ }
+
+ const fetchData = async () => {
+ let res = await fetch(
+ `http://127.0.0.1:8000/duration/${planet}` +
+ `?date=${dateTime.current}&speed=${speed}`
+ );
+ let response = await res.json();
+ //console.log(response);
+ if (speed > 0) {
+ setPosState(oldState.concat(response));
+
+ //console.log(dateTime.current);
+ } else if (speed == 0) {
+ //this requests every frame do a function
+ //that requests every minute and clear intervall
+ //when apead is changed to above 0
+ setPosState([response]);
+ posCounter = 0;
+ }
+ speedChanged.current = false;
+ };
+ fetchData();
+ //console.log(speed);
+ }
+ };
- const updateSpeed = (newSpeed) => setSpeed(newSpeed);
return (
<>
-
-
-
-
+
+
+
+
+
+
+
+
+
>
);
};
diff --git a/src/earth.jsx b/src/earth.jsx
index 7f4e122..4b0b63c 100644
--- a/src/earth.jsx
+++ b/src/earth.jsx
@@ -37,12 +37,12 @@ import { PlanetInfo } from "./planetInfo";
import { PlanetPath } from "./path";
import { MyContext } from "./Scene3";
-export const Earth = ({ positions }) => {
+export const Earth = ({ positions, speed, getPosition, nameVis, iconVis }) => {
let distanceScaleFactor = 1000000;
const [poss, setPos] = useState([]);
const [lineposs, setLinePos] = useState([]);
const [getAgain, setGetAgain] = useState(false);
- const [speed, setSpeed] = useState(60);
+ //const [speed, setSpeed] = useState(60);
const line = useRef();
const clouds = useRef("clouds");
const earth = useRef();
@@ -62,38 +62,18 @@ export const Earth = ({ positions }) => {
return group;
}
+ useEffect(() => {
+ console.log(speed);
+ }, [speed]);
+
let currLinePoss = [];
useFrame(() => {
- if (poss.length % 1000 == 0) {
- setPos(poss.slice(0, 500));
- }
- let date;
- if (firstRef.current) {
- date = new Date(Date.now());
- date.setMilliseconds(0);
- date.setSeconds(0);
- }
- //console.log(poss.length);
- //console.log(group.current.userData.counter);
- if (group.current.userData.counter % 250 == 0 || getAgain) {
- if (!firstRef.current)
- date = new Date(poss[poss.length - 1].date).toUTCString();
- const fetchData = async () => {
- let res = await fetch(
- `http://127.0.0.1:8000/duration/earth?date=${date}&speed=${speed}` //example and simple data
- );
- let response = await res.json();
-
- setPos(poss.concat(response)); // parse json
- firstRef.current = false;
- setGetAgain(false);
- //console.log(`psss : ${poss.length}`);
- };
- fetchData();
- }
+ //console.log(nameVis);
clouds.current.rotation.y += 0.00025;
earth.current.rotation.y += 0.00015;
+ getPosition("earth", setPos, poss, group.current.userData.counter);
+ console.log(poss);
if (true && group.current.userData.counter < poss.length) {
group.current.position.set(
Number(
@@ -111,15 +91,6 @@ export const Earth = ({ positions }) => {
}
}, []);
- const changeSpeed = (newSpeed) => {
- setPos(poss.slice(0, group.current.userData.counter + 10));
- setGetAgain(true);
- console.log(poss);
- setSpeed(newSpeed);
- };
-
- customData.current["changeEarthSpeed"] = changeSpeed;
-
const col = useLoader(TextureLoader, "../img/earth/6k_earth_daymap.jpg");
const bump = useLoader(TextureLoader, "../img/earth/earth_bump_1k.jpg");
const spec = useLoader(
@@ -137,17 +108,8 @@ export const Earth = ({ positions }) => {
});
return (
<>
-
-
+
{
+ const { customData } = useContext(MyContext);
+
+ const handleChange = (event) => {
+ customData.current.updateSpeed(event.target.value);
+ };
+
+ const handleReset = () => {
+ console.log("reset");
+ };
+
+ const handlePlanetOverlayVisibility = () => {
+ customData.current.handleVisibility();
+ console.log("asd");
+ };
+
+ return (
+ <>
+
+
+
+
+
+
+ >
+ );
+};
diff --git a/src/overlay.jsx b/src/overlay.jsx
deleted file mode 100644
index 8b13789..0000000
--- a/src/overlay.jsx
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/src/planetOverlay.jsx b/src/planetOverlay.jsx
index 96b48a8..dce5040 100644
--- a/src/planetOverlay.jsx
+++ b/src/planetOverlay.jsx
@@ -27,10 +27,11 @@ import "./styles.css";
import PropTypes from "prop-types";
-export const PlanetOverlay = ({ planet }) => {
+export const PlanetOverlay = ({ planet, nameVis, iconVis }) => {
const ref = useRef();
let [opacity, setOpacity] = useState(0);
let [minDistance, setMinDistance] = useState(0);
+
let [scolor, setSColor] = useState("white");
let [follow, setFollow] = useState(false);
const { camera } = useThree();
@@ -74,7 +75,7 @@ export const PlanetOverlay = ({ planet }) => {
setName(planet.current.userData.name);
setMinDistance(planet.current.userData.nearOvOp);
setSColor(planet.current.userData.scolor);
- }, [planet, name, minDistance, customData]);
+ }, [planet, name, minDistance, customData, iconVis, nameVis]);
useFrame(() => {
var distance = camera.position.distanceTo(planet.current.position);
@@ -87,6 +88,7 @@ export const PlanetOverlay = ({ planet }) => {
controls.current.target.copy(planet.current.position.clone());
controls.current.maxDistance = 20;
}
+ //console.log(iconVis);
}, []);
function startFollow() {
@@ -112,6 +114,7 @@ export const PlanetOverlay = ({ planet }) => {
className="icon"
onClick={handleClick}
onContextMenu={handleClick}
+ style={{ visibility: iconVis }}
>
- {name}
+
+ {name}
+