Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
Cómo importar un archivo JS en el archivo JS principal en Threejs

Todavía soy nuevo en Threejs... Quiero poner algo de mi código threejs en otro archivo JS y luego usarlo en mi archivo main.js. Este es un código similar simple:

principal.js

 import * as THREE from 'three' import Box from './classes/Parts.js' const box = new Box() scene.add(box)

Piezas.js

 class Box { constructor() { this.geom = new THREE.BoxGeometry(2, 2, 2); this.mat = new THREE.MeshBasicMaterial({ color: 0xff0000 }); this.mesh = new THREE.Mesh(this.geom, this.mat); } } export default Box;
esto es algo parecido a esto

Pero recibo este error: THREE.Object3D.add: object not an instance of THREE.Object3D.

¿Qué hice mal?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Solo puede agregar objetos personalizados al gráfico de escena que se deriven de THREE.Object3D . Ese no es el caso de su clase Box . Reescribe tu código así:

 class Box extends THREE.Mesh { constructor() { const geom = new THREE.BoxGeometry(2, 2, 2); const mat = new THREE.MeshBasicMaterial({ color: 0xff0000 }); super(geom,mat); } } export default Box;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!