Hey @alessandro_guarino
Thank you for your quick response. That’s how I tried it before. However, I get the error in the console
Uncaught TypeError: Cannot read property ‘parent’ of undefined
at ws.render (three.min.js:6)
at tick (main.js:201)
at main.js:208
main.js 208
renderer.render (scene, blender_camera);
Code full (sorry its a mess)
import {GLTFLoader} from “/lib/GLTFLoader.js”
var scene, renderer
//var camera
var light
//Debug
const gui = new dat.GUI()
// Canvas
const canvas = document.getElementById('canvas')
document.body.appendChild( canvas )
// Sizes
const sizes = {
width: window.innerWidth,
height: window.innerHeight
}
window.addEventListener('resize', () =>
{
// Update sizes
sizes.width = window.innerWidth
sizes.height = window.innerHeight
// Update camera
// camera.aspect = sizes.width / sizes.height
// camera.updateProjectionMatrix()
// Update renderer
renderer.setSize(sizes.width, sizes.height)
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
})
// Mouse
document.addEventListener('mousemove', animateParticles)
let mouseX = 0
let mouseY = 0
let nmouseX= 1
function animateParticles(event) {
mouseX = event.clientY
mouseY = event.clientX
nmouseX = event.clientX / sizes.height
}
document.addEventListener('wheel', onMouseWheel)
let y = 0
let position = 0
function onMouseWheel(event){
y = event.deltaY * 0.0007
}
// Scene
scene = new THREE.Scene();
scene.background = new THREE.Color( '#21282a' );
// Grid
var gridXZ = new THREE.GridHelper(100, 100);
scene.add(gridXZ);
// Objects (Geometrie)
const geometry = new THREE.TorusGeometry( 0.7, 0.2, 16, 100);
const particlesGeometry = new THREE.BufferGeometry
const particlesCnt = 5000;
gui.add('particlesCnt', 0, 100000)
const posArray = new Float32Array (particlesCnt * 3)
// xyz, xyz, xyz, xyz
for (let i = 0; i < particlesCnt * 3; i++){
posArray[i] = (Math.random () - 0.5 ) * 100
}
particlesGeometry.setAttribute('position', new THREE.BufferAttribute(posArray, 3))
// Material
const material = new THREE.PointsMaterial({
size: 0.0005
})
// Mesh
const sphere = new THREE.Points(geometry, material)
const particlesMesh = new THREE.Points(particlesGeometry, material)
scene.add(sphere, particlesMesh)
// Lights
light = new THREE.HemisphereLight(0xFFFFFF, 0x000000, 1.8)
const spotLight = new THREE.SpotLight( 0xffffff )
gui.add(light,'intensity', 0, 1.8)
scene.add(light, spotLight);
/* Camera
// Base camera
camera = new THREE.PerspectiveCamera(45, sizes.width / sizes.height, 0.1, 1000)
camera.position.x = 0
camera.position.y = 15
camera.position.z = 10
camera.lookAt (new THREE.Vector3(0,0,0))
scene.add(camera) */
// Renderer
renderer = new THREE.WebGLRenderer({
antialias: true
})
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.setSize(sizes.width, sizes.height)
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
canvas.appendChild (renderer.domElement);
/* Controls
const controls = new THREE.OrbitControls(camera, renderer.domElement)
controls.enableDamping = false
controls.maxDistance = 19
*/
// EventListener
//window.addEventListener("scroll", function(e) {
// code to increment object.position.z
// }, true);
// LOADER
var loader = new GLTFLoader();
var obj, blender_camera;
loader.load(
// resource URL
'/models/gltf/rekorderplatte.gltf',
// called when the resource is loaded
function ( gltf ) {
obj = gltf.scene
blender_camera = gltf.cameras[ 0 ]; //if you have one camera or you need the first
scene.add( obj, blender_camera );
gltf.animations; // Array<THREE.AnimationClip>
gltf.scene; // THREE.Group
gltf.scenes; // Array<THREE.Group>
gltf.cameras; // Array<THREE.Camera>
gltf.asset; // Object
},
// called while loading is progressing
function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
if (xhr.loaded / xhr.total * 100 == 100) {
console.log('Model geladen.')
scene.background = new THREE.Color( '#21282F' );
}
},
// called when loading has errors
function ( error ) {
console.log( 'An error happened' );
}
);
// Animate
const clock = new THREE.Clock()
const tick = () =>
{
const elapsedTime = clock.getElapsedTime()
//Update Objects
particlesMesh.rotation.y = mouseY * (elapsedTime * 0.000009) * -1
particlesMesh.rotation.x = mouseX * (elapsedTime * 0.000009)
// position += y
// y *= 0.9
//camera.position.y = y;
//Update Orbital Control
//controls.update();
// Consolole Log
// console.log(nmouseX)
// Render
renderer.render (scene, blender_camera);
// Call tick again on next frame
window.requestAnimationFrame( tick )
}
tick();