Browse Source

making the directional light shadow fix intuitive

Justin Gilman 1 year ago
parent
commit
284332f751

+ 36 - 0
Assets/Components/DirectionalLightFixForMobileCamera.re.ts

@@ -0,0 +1,36 @@
+import * as RE from 'rogue-engine';
+import * as THREE from 'three'
+
+export default class DirectionalLightFixForMobileCamera extends RE.Component {
+  initialOffset: THREE.Vector3 = new THREE.Vector3()
+  currentOffset: THREE.Vector3 = new THREE.Vector3()
+  awake() {
+
+  }
+
+  start() {
+    const activeCamera = RE.App.currentScene.getObjectByProperty("uuid", RE.App.activeCamera) as THREE.Object3D
+    const directionalLight: THREE.DirectionalLight = this.object3d as THREE.DirectionalLight
+
+    this.initialOffset.copy(this.object3d.position)
+    this.initialOffset.sub(new THREE.Vector3(0, 0, 0))
+    this.updatePositions()
+    directionalLight.target = activeCamera
+  }
+
+  update() {
+    this.updatePositions()
+  }
+
+  updatePositions() {
+    const activeCamera = RE.App.currentScene.getObjectByProperty("uuid", RE.App.activeCamera) as THREE.Object3D
+    const directionalLight: THREE.DirectionalLight = this.object3d as THREE.DirectionalLight
+    
+    this.currentOffset.copy(this.initialOffset).add(activeCamera.position)
+    directionalLight.position.set(this.currentOffset.x, this.currentOffset.y, this.currentOffset.z)
+    directionalLight.shadow.camera.position.set(this.currentOffset.x, this.currentOffset.y, this.currentOffset.z)
+  }
+}
+
+RE.registerComponent(DirectionalLightFixForMobileCamera);
+        

+ 0 - 31
Assets/Components/MobileDirectionalLight.re.ts

@@ -1,31 +0,0 @@
-import * as RE from 'rogue-engine';
-import * as THREE from 'three'
-
-export default class MobileDirectionalLight extends RE.Component {
-  @RE.props.object3d() target: THREE.Object3D
-  initialOffset: THREE.Vector3
-  awake() {
-
-  }
-
-  start() {
-    const directionalLight: THREE.DirectionalLight = this.object3d as THREE.DirectionalLight
-    this.initialOffset = this.object3d.position.clone()
-    this.initialOffset.sub(new THREE.Vector3(0, 0, 0))
-    this.updatePositions()
-    directionalLight.target = this.target
-  }
-
-  update() {
-    this.updatePositions()
-  }
-
-  updatePositions() {
-    const directionalLight: THREE.DirectionalLight = this.object3d as THREE.DirectionalLight
-    const offset: THREE.Vector3 = this.initialOffset.clone().add(this.target.position)
-    directionalLight.position.set(offset.x, offset.y, offset.z)
-    directionalLight.shadow.camera.position.set(offset.x, offset.y, offset.z)
-  }
-}
-
-RE.registerComponent(MobileDirectionalLight);

File diff suppressed because it is too large
+ 0 - 0
Assets/MainScene.rogueScene


File diff suppressed because it is too large
+ 0 - 0
dist/rogue-editor-user-scripts.js


+ 52 - 58
dist/rogue-engine-user-scripts.js

@@ -467,6 +467,57 @@ __decorateClass([
 rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(BallRaycastReceiver);
 
 
+/***/ }),
+
+/***/ "./Assets/Components/DirectionalLightFixForMobileCamera.re.ts":
+/*!********************************************************************!*\
+  !*** ./Assets/Components/DirectionalLightFixForMobileCamera.re.ts ***!
+  \********************************************************************/
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+__webpack_require__.r(__webpack_exports__);
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */   "default": () => (/* binding */ DirectionalLightFixForMobileCamera)
+/* harmony export */ });
+/* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! rogue-engine */ "rogue-engine");
+/* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(rogue_engine__WEBPACK_IMPORTED_MODULE_0__);
+/* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! three */ "three");
+/* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(three__WEBPACK_IMPORTED_MODULE_1__);
+var __defProp = Object.defineProperty;
+var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
+
+
+class DirectionalLightFixForMobileCamera extends rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Component {
+  constructor() {
+    super(...arguments);
+    this.initialOffset = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3();
+    this.currentOffset = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3();
+  }
+  awake() {
+  }
+  start() {
+    const activeCamera = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.currentScene.getObjectByProperty("uuid", rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.activeCamera);
+    const directionalLight = this.object3d;
+    this.initialOffset.copy(this.object3d.position);
+    this.initialOffset.sub(new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(0, 0, 0));
+    this.updatePositions();
+    directionalLight.target = activeCamera;
+  }
+  update() {
+    this.updatePositions();
+  }
+  updatePositions() {
+    const activeCamera = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.currentScene.getObjectByProperty("uuid", rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.activeCamera);
+    const directionalLight = this.object3d;
+    this.currentOffset.copy(this.initialOffset).add(activeCamera.position);
+    directionalLight.position.set(this.currentOffset.x, this.currentOffset.y, this.currentOffset.z);
+    directionalLight.shadow.camera.position.set(this.currentOffset.x, this.currentOffset.y, this.currentOffset.z);
+  }
+}
+__name(DirectionalLightFixForMobileCamera, "DirectionalLightFixForMobileCamera");
+rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(DirectionalLightFixForMobileCamera);
+
+
 /***/ }),
 
 /***/ "./Assets/Components/DummyShooter.re.ts":
@@ -830,63 +881,6 @@ __name(MainMenuComponent, "MainMenuComponent");
 rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(MainMenuComponent);
 
 
-/***/ }),
-
-/***/ "./Assets/Components/MobileDirectionalLight.re.ts":
-/*!********************************************************!*\
-  !*** ./Assets/Components/MobileDirectionalLight.re.ts ***!
-  \********************************************************/
-/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
-
-__webpack_require__.r(__webpack_exports__);
-/* harmony export */ __webpack_require__.d(__webpack_exports__, {
-/* harmony export */   "default": () => (/* binding */ MobileDirectionalLight)
-/* harmony export */ });
-/* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! rogue-engine */ "rogue-engine");
-/* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(rogue_engine__WEBPACK_IMPORTED_MODULE_0__);
-/* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! three */ "three");
-/* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(three__WEBPACK_IMPORTED_MODULE_1__);
-var __defProp = Object.defineProperty;
-var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
-var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
-var __decorateClass = (decorators, target, key, kind) => {
-  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
-  for (var i = decorators.length - 1, decorator; i >= 0; i--)
-    if (decorator = decorators[i])
-      result = (kind ? decorator(target, key, result) : decorator(result)) || result;
-  if (kind && result)
-    __defProp(target, key, result);
-  return result;
-};
-
-
-class MobileDirectionalLight extends rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Component {
-  awake() {
-  }
-  start() {
-    const directionalLight = this.object3d;
-    this.initialOffset = this.object3d.position.clone();
-    this.initialOffset.sub(new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(0, 0, 0));
-    this.updatePositions();
-    directionalLight.target = this.target;
-  }
-  update() {
-    this.updatePositions();
-  }
-  updatePositions() {
-    const directionalLight = this.object3d;
-    const offset = this.initialOffset.clone().add(this.target.position);
-    directionalLight.position.set(offset.x, offset.y, offset.z);
-    directionalLight.shadow.camera.position.set(offset.x, offset.y, offset.z);
-  }
-}
-__name(MobileDirectionalLight, "MobileDirectionalLight");
-__decorateClass([
-  rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.object3d()
-], MobileDirectionalLight.prototype, "target", 2);
-rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(MobileDirectionalLight);
-
-
 /***/ }),
 
 /***/ "./Assets/Components/MovementController.re.ts":
@@ -5689,6 +5683,7 @@ const OutputShader = {
 /******/ 	// Load entry module and return exports
 /******/ 	__webpack_require__("./Assets/Components/Animator.re.ts");
 /******/ 	__webpack_require__("./Assets/Components/BallRaycastReceiver.re.ts");
+/******/ 	__webpack_require__("./Assets/Components/DirectionalLightFixForMobileCamera.re.ts");
 /******/ 	__webpack_require__("./Assets/Components/DummyShooter.re.ts");
 /******/ 	__webpack_require__("./Assets/Components/FaceDirectionOfVelocityComponent.re.ts");
 /******/ 	__webpack_require__("./Assets/Components/FloorCheckComponent.re.ts");
@@ -5696,7 +5691,6 @@ const OutputShader = {
 /******/ 	__webpack_require__("./Assets/Components/GameLogic.re.ts");
 /******/ 	__webpack_require__("./Assets/Components/LifetimeComponent.re.ts");
 /******/ 	__webpack_require__("./Assets/Components/MainMenuComponent.re.ts");
-/******/ 	__webpack_require__("./Assets/Components/MobileDirectionalLight.re.ts");
 /******/ 	__webpack_require__("./Assets/Components/MovementController.re.ts");
 /******/ 	__webpack_require__("./Assets/Components/ObjectSpinner.re.ts");
 /******/ 	__webpack_require__("./Assets/Components/PlayerPawnInput.re.ts");

File diff suppressed because it is too large
+ 0 - 0
dist/rogue-engine-user-scripts.js.map


+ 1 - 1
rogue-config.json

@@ -1 +1 @@
-{"title":"ShipShoot","scenes":[{"name":"Menu","uuid":"56445644-18ed-4c5b-8f26-b918e047fbb3"},{"name":"MainScene","uuid":"1aaeccac-8dcd-42b5-9eaf-69b66b6b54b6"}],"projectVersion":22,"lastOpenedScene":"\\Assets\\MainScene.rogueScene"}
+{"title":"ShipShoot","scenes":[{"name":"Menu","uuid":"56445644-18ed-4c5b-8f26-b918e047fbb3"},{"name":"MainScene","uuid":"1aaeccac-8dcd-42b5-9eaf-69b66b6b54b6"}],"projectVersion":22,"lastOpenedScene":"\\Assets\\Menu.rogueScene"}

Some files were not shown because too many files changed in this diff