Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading external textures causes hiccups #1061

Open
1 task
nearnshaw opened this issue Dec 29, 2023 · 0 comments
Open
1 task

Loading external textures causes hiccups #1061

nearnshaw opened this issue Dec 29, 2023 · 0 comments
Labels
bug Something isn't working new
Milestone

Comments

@nearnshaw
Copy link
Member

Issue Description:

Reported by Picazzo on Discord

Hi, I found an issue with using textures from external URLs, when you spawn a texture of this type the game fps lower a lot until the texture is loaded, this doesn't happen with normal local textures
I'm only speculating but could this be happening because internally the call to the URL is making other processes of the engine wait?
Here is a simple example to replicate it

let index = 0
for (let i = 0; i < 10; i++) {
  for (let j = 0; j < 5; j++) {
    const entity = engine.addEntity()
    Transform.create(entity, {
      position: Vector3.create(1+i*1.2, 0.5+j*1.2, 1)
    })
    MeshRenderer.setPlane(entity)
    //Creating a material from an external url causes the game to stop until the image is loaded
    Material.setPbrMaterial(entity,{
      texture: Material.Texture.Common({
          src:"https://storage.lowpoly3d.com/avatargarden/RendersChar_"+(index)+".png",
      }),
      transparencyMode: MaterialTransparencyMode.MTM_ALPHA_TEST
    })
    index++;
  }
}

And here is an example with a 1 second delay between create material calls, you can see the game totally collapsing every 1 second the call to get the external texture is made

import { Vector3 } from '@dcl/sdk/math'
import { Entity, Material, MaterialTransparencyMode, MeshRenderer, Transform, engine } from '@dcl/sdk/ecs'
import * as DclTimers from '@dcl-sdk/utils/dist/timer'

let index = 0
for (let i = 0; i < 10; i++) {
  for (let j = 0; j < 5; j++) {
    const entity = engine.addEntity()
    Transform.create(entity, {
      position: Vector3.create(1+i*1.2, 0.5+j*1.2, 1)
    })
    MeshRenderer.setPlane(entity)
    const constantIndex = index
    DclTimers.timers.setTimeout(()=>{
      //Creating a material from an external url causes the game to stop until the image is loaded
      createMaterial(entity, constantIndex)
    }, 1000*index)
    index++;
  }
  
}

function createMaterial(entity: Entity, index: number) {
  Material.setPbrMaterial(entity,{
    texture: Material.Texture.Common({
        src:"https://storage.lowpoly3d.com/avatargarden/RendersChar_"+(index)+".png",
    }),
    transparencyMode: MaterialTransparencyMode.MTM_ALPHA_TEST
  })
}

SDK:

  • SDK6
  • [ x] SDK7
@nearnshaw nearnshaw added bug Something isn't working new labels Dec 29, 2023
@nearnshaw nearnshaw added this to the Workspace milestone Dec 29, 2023
@nearnshaw nearnshaw added this to SDK Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new
Projects
Status: No status
Development

No branches or pull requests

1 participant