I am currently working on creating a unique custom object using ThreeJS called Model
. This object is made up of other custom objects that I have defined, such as Part
. The problem arises when I encounter the following error:
const Model = function() {
this.mesh = new THREE.Object3D();
this.mesh.name = 'model';
//creating an instance of the Part object
this.lowerPart = new Part();
this.lowerPart.position.set(1, 2, 3, -75); //Error occurs here
this.lowerPart.rotation.set(0, 0, 0);
this.mesh.add(this.lowerPart);
}
Upon running the program, I receive an error message stating that it cannot read the property 'set' of undefined, specifically referencing
this.lowerPart.position.set(1, 2, 3, -75);
.
This is how I have defined the Part
object:
const Part = function () {
this.mesh = new THREE.Object3D();
this.mesh.name = 'part';
const partShape = new THREE.Shape();
partShape.lineTo( 40, 80 );
partShape.lineTo( 60, 80 );
partShape.lineTo( 60, 100 );
partShape.lineTo( 40, 100 );
//extrude settings defined....
const partGeometry = new THREE.ExtrudeGeometry(partShape, extrudeSettings);
const partMesh = new THREE.Mesh(partGeometry, new THREE.MeshStandardMaterial({
color: 0x1c4bc9,
flatShading: true
}));
this.mesh.add(partMesh);
};
Part.prototype = Object.create(THREE.Object3D.prototype);
Part.prototype.constructor = Part;
In my Model
function, there is also another issue where this.lowerPart
is labeled as unused. Despite being of type Object3D with the necessary properties, I am unsure of the reason for this indication.
The console confirms that this.lowerPart
is indeed an instance of Part
.
I have explored various suggestions from StackOverflow related to similar issues, but none have resolved my problem. One of the most relevant discussions can be found here: Uncaught TypeError: Cannot read property 'set' of undefined Unfortunately, these solutions did not work in my case.
If anyone has any suggestions or insights on how to address and resolve this issue, I would greatly appreciate your input!