import * as THREE from 'three';
import {
OrbitControls
} from 'three/addons/controls/OrbitControls.js';
import {
GLTFLoader
} from 'three/addons/loaders/GLTFLoader.js';
const truckModelPath = 'https://supplystack-devteam.s3.eu-west-1.amazonaws.com/POC-TCT-LightLoadOptimization-3dmodels/truck.glb';
const truckBedPath = 'https://supplystack-devteam.s3.eu-west-1.amazonaws.com/POC-TCT-LightLoadOptimization-3dmodels/truck-bed.glb'
const truckOnlyPath = 'https://supplystack-devteam.s3.eu-west-1.amazonaws.com/POC-TCT-LightLoadOptimization-3dmodels/truck-only.glb'
// Create a scene
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xffffff); // white color
// Create a camera
const camera = new THREE.PerspectiveCamera(
50,
window.innerWidth / window.innerHeight,
0.1,
1000
);
camera.position.set(7, 5, 10);
camera.lookAt(scene.position); // Ensure the camera looks at the center of the scene
// Create a renderer
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Define the dimensions of the truck trailer
const containerDimensions = {
length:10.19,
width: 2.44,
height: 2.59
};
// Define the number of boxes and their dimensions
const numBoxes = 10;
const boxDimensions = {
length: 0.5,
width: 0.75,
height: 0.5
};
const truckMaterial = new THREE.MeshStandardMaterial({
color: 0x808080,
wireframe: false,
transparent: true,
side: THREE.DoubleSide, // Render both sides of the faces
opacity: 0.5,
});
const helpers = {
loadModel(scene, position, scaleFactor, truckModelPath) {
const loader = new GLTFLoader();
loader.load(truckModelPath, function(gltf) {
const truckModel = gltf.scene;
// Position the truck model around your container
truckModel.position.set(position.x, position.y, position.z);
// Scale the truck model down by the scaleFactor
truckModel.scale.set(scaleFactor,...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.