• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

297
Vistas
Threejs - creating a class, unable to pass Vector3 through position variable

I've tried to pass the position of a Vector3 into this.positon = position; where the position is == x, y, z. i.e: 0, 2, 0; joe = new people((0, 2, 0)) however, it does not work. The sphere does not appear. I don't get any errors, and when I console.log(joe) the position = 0

class people {
constructor(name, age, color, position, radius)
{
    this.name = name,
    this.age = age,
    this.color = color,
    this.position = position,
    this.radius = radius,
    this.createperson()
}
createperson() // runs script below
{
    this.person = new THREE.Mesh(
        new THREE.SphereGeometry(this.radius, 32, 16),
        new THREE.MeshStandardMaterial({
            color: this.color,
            metalness: 0,
            roughness: 0.5
        })     
    )
    this.person.position.set(this.position)
    scene.add(this.person)
}

}

let joe = new people('Joe', 26, '#00ff00', (0, 1, 0), 2)

but when I pass it through individually as, this.x = x, this.y = y, this.z = z. joe = new people(0, 2, 0) this works. It appears as it should. When I console.log(joe), the position is a Vector3.

class people {
constructor(name, age, color, x, y, z, radius)
{
    this.name = name,
    this.age = age,
    this.color = color,
    this.x = x, // this
    this.y = y, // part
    this.z = z, // here works
    this.radius = radius,
    this.createperson()
}
createperson() // runs script below
{
    this.person = new THREE.Mesh(
        new THREE.SphereGeometry(this.radius, 32, 16),
        new THREE.MeshStandardMaterial({
            color: this.color,
            metalness: 0,
            roughness: 0.5
        })     
    )
    this.person.position.set(this.x, this.y, this.z)
    scene.add(this.person)
}

}

let joe = new people('Joe', 26, '#00ff00', 0, 1, 0, 2)

almost 3 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

let joe = new people('Joe', 26, '#00ff00', (0, 1, 0), 2)
=> let joe = new people('Joe', 26, '#00ff00', new THREE.Vector3(0, 1, 0), 2)

and

this.person.position.set(this.position) => this.person.position.copy(this.position)

almost 3 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda