Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
how to access properties in another module in JavaScript?

I have one module called LoadingBar:

   ...
      export default class LoadingBar
      {
        constructor()
     {
    ...


    const overlayGeometry = new THREE.PlaneGeometry(2, 2, 1, 1)
    const overlayMaterial = new THREE.ShaderMaterial
             ({
                 //wireframe: true,
                 transparent: true,
                 uniforms:
                 {
                     uAlpha: {value: 0.5}
                 },
             vertexShader: `
              void main()
              {
                  gl_Position = vec4(position, 1.0);
              }
              `,
              fragmentShader: `
              uniform float uAlpha;

              void main()
              {
                  gl_FragColor = vec4(0.0, 0.0, 0.0, uAlpha);
              }
              `
              })

    const overlay = new THREE.Mesh(overlayGeometry, overlayMaterial)
    this.scene.add(overlay)

 }

 }

and another called Resources:

import LoadingBar from '../World/LoadingBar.js'
export default class Resources extends EventEmitter
{
    constructor(sources)
    {
        super()

    this.sources = sources
    
  ...

    this.LoadingBar = new LoadingBar()
    
}

setLoaders()
{
    const loadingManager = new THREE.LoadingManager(
        // Loaded
() =>
{
   
    ***gsap.to(overlayMaterial.uniforms.uAlpha, { duration: 3, value: 1 })***

},

// Progress
() =>
{
    console.log('progress')
}
    )
    this.gltfLoader = new GLTFLoader(loadingManager)
    this.loaders = {}
    this.loaders.gltfLoader = new GLTFLoader()
    this.loaders.textureLoader = new THREE.TextureLoader()
    this.loaders.cubeTextureLoader = new THREE.CubeTextureLoader(loadingManager)
}

Despite importing it I get an error saying overlay material is not defined I cant see why it cant access the loading Bar module? I have deleted as much unnecessary code as I think I possibly can without making it impossible to answer I PUT ASTERIKS where on the line that gives the error.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The variable overlayMaterial is only available locally inside the class LoadingBar. If you want it to be available elsewhere, you will have to define it outside of the LoadingBar class (it does not like you are, it is not clear from your example...), and export it separately:

export const overlayMaterial = [your code here]

You can then import in your other module: import {overlayMaterial} from "../World/LoadingBar.js"

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda