Hello Folks,
I am sure most of you would have encountered this and there is an excellent workaround for this,
my main js file , is getting extremely long ,
is there a way like in other languages where you write the main in one and call this module in all other js files, i understand that is what we do with module calls, would like to know how i would execute this for this particular option,
example on what i am on about ,
can i create a .js file with all the camera settings , and call camera settings in the GLTF importer , and so on…
like,
main camera , scene and lights setup
import * as THREE from './build/three.module.js';
var scene, camera, renderer, directionalLight, canvas;
scene = new THREE.Scene();
const fov = 75;
const aspect = 2; // the canvas default
const near = 1;
const far = 1000000;
camera = new THREE.PerspectiveCamera(fov,window.innerWidth/window.innerHeight,near,far);
camera.position.set(0, 0, 5);
//canvas = document.querySelector('#canvasId');
renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setSize(window.innerWidth, window.innerHeight);
//setup Lights
directionalLight = new THREE.DirectionalLight(0xff8c19,1.5);
directionalLight.position.set(0,0,4);
scene.add(directionalLight);
document.body.appendChild(renderer.domElement);
say this is called cameraSetup.js
and in the gltfScene.js file can i call this some how ?
or if i call this first
<script type = "module" src="cameraSetup.js"></script>
and next call
<script type = "module" src="gltfScene.js "></script>
this did not work , so any help would save a lot of time going through pages of code
gltfScene.js
import { GLTFLoader } from 'https://threejsfundamentals.org/threejs/resources/threejs/r125/examples/jsm/loaders/GLTFLoader.js';
function initGLTF() {
time = new THREE.Clock();
speed = 2; //units a second
delta = 0;
raycaster = new THREE.Raycaster();
mouse = new THREE.Vector2();
rotateReset = new THREE.Matrix4();
LogotextureLoader = new THREE.TextureLoader();
Logomap = LogotextureLoader.load('images/weblogWebPage.png');
Logomaterial = new THREE.MeshPhongMaterial({ map: Logomap });
const gltfLoader = new GLTFLoader();
//GLtfSelection = new THREE.Object3D();
gltfLoader.load('models/testObj.glb', function(gltf) {
root = gltf.scene;
scene.add(root);
modelFemale = root.getObjectByName('geo');
//console.log(modelFemale);
});
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
}
thanks a lot for the excellent support forum