Working with the options panel – Dragon3DGraff_Blog

Working with the options panel

0

When selected, a panel with options is displayed. Added a BoundingBox when selecting an object.
When changing a value in the options panel, the geometry of the selected object changes. I have done it so far for the ball and then crookedly, just to check what works. The fact is that when a parameter is changed in the Object3D geometry, the geometry does not rebuild. To rebuild the geometry you need to call new THREE.SphereGeometry. For the cube, respectively, new THREE.BoxGeometry, and so on for each object.
Therefore, it was decided in the Entity class to create the createGeometry() method, in which, depending on the type of object, I will generate new geometry:

let TA_Entities = function () {

	let GLOBALSCOPE = this;

	this.createGeometry = function ( geometryType ) {

		let geometry = null;

		switch ( geometryType, params ) {
			case 'BoxBufferGeometry':

					let data = {
						width: params.width,
						height: params.height,
						depth: params.depth,
						widthSegments: params.widthSegments,
						heightSegments: params.heightSegments,
						depthSegments: params.depthSegments
					};

					geometry = new BoxBufferGeometry(
						data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments
					);
				
				break;
		
			default:
				break;
		}

		return geometry;
	}

Accordingly, I will change the function of creating objects. Now, when you create, the old object is deleted and a new one is created at the same point, which affects performance. I will only change the geometry with the Object3D object. Like that:

let geom = entity.geometry;

let newGeom = new THREE.SphereGeometry( 
  +input.value,
  geom.parameters.widthSegments,
  geom.parameters.heightSegments,
  geom.parameters.phiStart,
  geom.parameters.phiLength,
  geom.parameters.thetaStart,
  geom.parameters.thetaLength
);

entity.geometry.dispose();
entity.geometry = newGeom; 
Это изображение имеет пустой атрибут alt; его имя файла - FK48qS0aJc-1024x860.jpg
0

Leave a Reply