I’m trying to access any property of my imported point-cloud model.
When I console.log the model within the function loader.load it works. The first problem is that I don’t know how to get the same result outside the function. I did it only with the last three lines of code but initializing the object with different name.
I used the code for point-cloud models from three.js docs and everything works fine except when I want to change the size of the points. I guess it is due to the different structure of my model (photo attached).
Here’s the code that I use.
import ‘./style.css’
import * as THREE from ‘three’import { OrbitControls } from ‘three/examples/jsm/controls/OrbitControls.js’;
import { PCDLoader } from ‘three/examples/jsm/loaders/PCDLoader’
import { BufferAttribute, BufferGeometry } from ‘three’;let camera, scene, renderer;
init(); render(); function init() { renderer = new THREE.WebGLRenderer( { antialias: true } ); renderer.setPixelRatio( window.devicePixelRatio ); renderer.setSize( window.innerWidth, window.innerHeight ); document.body.appendChild( renderer.domElement ); scene = new THREE.Scene(); camera = new THREE.PerspectiveCamera( 30, window.innerWidth / window.innerHeight, 0.01, 40 ); camera.position.set( 0, 0, 7 ); scene.add( camera ); const controls = new OrbitControls( camera, renderer.domElement ); controls.addEventListener( 'change', render ); // use if there is no animation loop controls.minDistance = 0.5; controls.maxDistance = 10; //scene.add( new THREE.AxesHelper( 1 ) ); const loader = new PCDLoader(); loader.load( 'pointcloud.pcd', function ( points ) { points.geometry.center(); points.geometry.rotateY( Math.PI ); points.geometry.rotateX( Math.PI ); points.geometry.rotateZ( Math.PI ); scene.add( points ); console.log(points) render(); } ); window.addEventListener( 'resize', onWindowResize ); window.addEventListener( 'keypress', keyboard ); } function onWindowResize() { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize( window.innerWidth, window.innerHeight ); } function keyboard( ev ) { const points = scene.getObjectByProperty( 'pointcloud.pcd' ); switch ( ev.key || String.fromCharCode( ev.keyCode || ev.charCode ) ) { case '+': points.material.size *= 1.2; break; case '-': points.material.size /= 1.2; break; } render(); } function render() { renderer.render( scene, camera ); }
// How I accessed attributes
const points2 = scene.getObjectByProperty( ‘points’ );console.log(points2)`