room.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import * as three from "three-js";
  2. import { functional_factor } from "./functional_factor.js";
  3. const room = (space) => {
  4. const cube = new functional_factor(() => {
  5. const material = new three.MeshStandardMaterial({
  6. color: 0xA000A0
  7. });
  8. const geometry = new three.BoxGeometry(1, 1, 1);
  9. const mesh = new three.Mesh(geometry, material);
  10. mesh.position.x = 10;
  11. mesh.position.z = -10;
  12. mesh.position.y = 1;
  13. return mesh;
  14. }, (item) => {
  15. item.rotation.x += 0.01;
  16. });
  17. const light = new functional_factor(() => {
  18. const light = new three.HemisphereLight(0x707070);
  19. light.position.x = -10;
  20. light.position.z = 10;
  21. light.position.y = 10;
  22. return light;
  23. }, (item) => {
  24. if (item.rotation.x == 0) {
  25. item.position.y += 0.1;
  26. } else {
  27. item.position.y -= 0.1;
  28. }
  29. if (item.position.y > 10) {
  30. item.rotation.x = 0.1;
  31. }
  32. if (item.position.y < 0) {
  33. item.rotation.x = 0;
  34. }
  35. });
  36. space.add_factor(cube);
  37. space.add_factor(light);
  38. };
  39. export { room };