-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented the Container Object Utility. Co-Authored-By: Faru Nuri Sönmez <[email protected]>
- Loading branch information
1 parent
9a2f044
commit 3808a8f
Showing
7 changed files
with
165 additions
and
40 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/app/types/interfaces/utils/scene/objects/container.object.util.interface.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { IScene } from "../scene.util.interface.type"; | ||
|
||
export interface IContainerObjectUtil extends IScene { | ||
width: number; | ||
height: number; | ||
length: number; | ||
capacity: number; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/app/types/interfaces/utils/scene/objects/floor.object.util.interface.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { IScene } from "../scene.util.interface.type"; | ||
|
||
export interface IFloorObjectUtil extends IScene{ | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/app/types/interfaces/utils/scene/scene.util.interface.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as THREE from "three"; | ||
|
||
export interface IScene { | ||
scene: THREE.Scene; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React, { useEffect } from "react" | ||
import * as THREE from "three" | ||
import { IContainerObjectUtil } from "@/app/types/interfaces/utils/scene/objects/container.object.util.interface.type" | ||
import { scale_meter_px } from "@/app/constants/scene/scene.constants" | ||
|
||
const ContainerObjectUtil = (props: IContainerObjectUtil) => { | ||
const weight = props.width * 100; | ||
const height = props.height * scale_meter_px; | ||
const length = props.length * scale_meter_px; | ||
const containerCapacity = weight * height * length; | ||
|
||
var material = new THREE.MeshLambertMaterial({ | ||
color: 0x949494, | ||
side: THREE.DoubleSide | ||
}); | ||
|
||
var transparentMaterial = new THREE.MeshLambertMaterial({ | ||
color: 0x949494, | ||
side: THREE.DoubleSide, | ||
transparent: true, | ||
opacity: 0.5, | ||
}); | ||
|
||
useEffect(() => { | ||
loadContainer(); | ||
}, [props.scene]) | ||
|
||
const loadContainer = () => { | ||
var plane; | ||
var container = new THREE.Group(); | ||
|
||
/** | ||
* Oluşturulan kutunun alt kısmını temsil eden geometriyi oluşturur. | ||
* @param {number} weight - Kutunun genişliği. | ||
* @param {number} length - Kutunun uzunluğu. | ||
* @returns {THREE.BoxGeometry} - Oluşturulan geometri. | ||
* */ | ||
const frontGeometry = new THREE.BoxGeometry(weight + 5, 5, length + 5); | ||
// Geometriyi belirli bir konuma çevirme: | ||
// Kutunun ortasından -5 birim sol ve yukarıda, ve uzunluğunun yarısı kadar sağ ve geride konumlandırılır. | ||
frontGeometry.translate(weight / 2 - 5 / 2, - 5 / 2 - 0.1, length / 2 - 5 / 2); | ||
|
||
plane = new THREE.Mesh(frontGeometry, material) | ||
plane.name = "front" | ||
container.add(plane) | ||
plane.castShadow = true; | ||
plane.receiveShadow = true; | ||
|
||
const backGeometry = new THREE.BoxGeometry(weight + 5, 5, length + 5); | ||
backGeometry.translate(weight / 2 - 5 / 2, -5 / 2 - 0.1, -(length / 2 - 5 / 2)); // Negative z-axis translation | ||
plane = new THREE.Mesh(backGeometry, transparentMaterial) | ||
plane.name = "back" | ||
//container.add(plane) | ||
|
||
const topGeometry = new THREE.BoxGeometry(weight + 5, height, 5); | ||
topGeometry.translate(weight / 2 - 5 / 2, height / 2, -5 / 2 - 0.1); | ||
plane = new THREE.Mesh(topGeometry, transparentMaterial) | ||
container.add(plane) | ||
|
||
const bottomGeometry = new THREE.BoxGeometry(weight + 5, 5, length + 5); | ||
bottomGeometry.translate(weight / 2 - 5 / 2, height + 5 / 2 + 0.1, length / 2 - 5 / 2); | ||
plane = new THREE.Mesh(bottomGeometry, transparentMaterial) | ||
//container.add(plane) | ||
|
||
const rightSideGeometry = new THREE.BoxGeometry(5, height, length); | ||
rightSideGeometry.translate(-5 / 2 - 0.1, height / 2, length / 2); | ||
plane = new THREE.Mesh(rightSideGeometry, transparentMaterial) | ||
container.add(plane) | ||
|
||
const leftSideGeometry = new THREE.BoxGeometry(5, height, length); | ||
leftSideGeometry.translate(weight - 5 / 2 + 0.1, height / 2, length / 2); | ||
plane = new THREE.Mesh(leftSideGeometry, transparentMaterial) | ||
//container.add(plane) | ||
|
||
loadTruck(container) | ||
} | ||
|
||
const loadTruck = (container: THREE.Group) => { | ||
props.scene.add(container); | ||
} | ||
|
||
return null | ||
} | ||
|
||
export default ContainerObjectUtil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { useEffect } from "react"; | ||
import * as THREE from "three"; | ||
|
||
import { IFloorObjectUtil } from "@/app/types/interfaces/utils/scene/objects/floor.object.util.interface.type"; | ||
|
||
const FloorObjectUtil = (props:IFloorObjectUtil) => { | ||
|
||
useEffect(() => { | ||
const textureLoader = new THREE.TextureLoader(); | ||
|
||
const WIDTH: number = 3000; | ||
const LENGTH: number = 3000; | ||
const NUM_X: number = 6; | ||
const NUM_Z: number = 6; | ||
|
||
const geometry: THREE.PlaneGeometry = new THREE.PlaneGeometry(WIDTH, LENGTH, 1, 1); | ||
|
||
const material: THREE.MeshStandardMaterial = new THREE.MeshStandardMaterial({ | ||
displacementScale: 0.3, | ||
roughness: 1, | ||
}); | ||
|
||
for (let i: number = 0; i < NUM_X; i++) { | ||
for (let j: number = 0; j < NUM_Z; j++) { | ||
const floor: THREE.Mesh = new THREE.Mesh(geometry, material); | ||
floor.castShadow = false; | ||
floor.receiveShadow = true; | ||
floor.rotation.x = -Math.PI / 2; | ||
floor.position.y = -10; | ||
|
||
props.scene.add(floor); | ||
} | ||
} | ||
|
||
}, [props.scene]); | ||
|
||
return null; // No need to render anything | ||
}; | ||
|
||
export default FloorObjectUtil; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters