Community
Forma Developer Forum
Welcome to Autodesk Forma Developer Forum. Share your knowledge, ask questions, and explore popular Forma API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to alternate between textures?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
iklimis
248 Views, 3 Replies

How to alternate between textures?

Is there a way to load a specific texture that has been previously loaded without creating and adding a new canvas element.

Currently when I create two textures and I want to alternate between them, I have to create a canvas for each one from the start.

Is there a more convenient, efficient way for example loading a texture using just the texture name?

Tags (1)
Labels (1)
3 REPLIES 3
Message 2 of 4
havard.hoiby
in reply to: iklimis

Hello 🙂 

 

There is no mechanism at our end for storing and loading the texture. You would need to do this inside the extension. Here is an example of how to create to canvases ahead of time and then just swap between them on a button click:

 

import { Forma } from "https://esm.sh/forma-embedded-view-sdk/auto"

const canvas1 = document.createElement("canvas")
canvas1.width = canvas1.height = 100;
const ctx1 = canvas1.getContext("2d")
ctx1.fillStyle = "green";
ctx1.fillRect(0, 0, 100, 100);

const canvas2 = document.createElement("canvas")
canvas2.width = canvas2.height = 200;
const ctx2 = canvas2.getContext("2d")
ctx2.fillStyle = "blue";
ctx2.fillRect(0, 0, 200, 200);


document.getElementById("c1").onclick = async () => {
  await Forma.terrain.groundTexture.add({
    name: "my-ground",
    canvas: canvas1,
    position: { x: 0, y: 0, z: 1000 },
    scale: { x: 1, y: 1 },
  });
}

document.getElementById("c2").onclick = async () => {
  await Forma.terrain.groundTexture.add({
    name: "my-ground",
    canvas: canvas2,
    position: { x: 0, y: 0, z: 1000 },
    scale: { x: 1, y: 1 },
  });
}

 

I would also suggest the newly added storage api under `Forma.extensions.storage` here you can store and load named objects. This way a user their texture and then load it afterwards from our servers. The docs for this is on the way but a gist of the usage is:

 

Forma.extensions.storage.setItem
Forma.extensions.storage.getBinaryItem or getTextItem

 

There is an example on its way which uses it here: https://github.com/spacemakerai/forma-extensions-samples/pull/13/files

 

Does this answer your question? And importantly are you asking this for convenience or have you uncovered a performance issue?

Message 3 of 4
iklimis
in reply to: iklimis

Thanks for your reply! I had imagined that such a solution would be more likely.
the new storage api is most helpful btw

Message 4 of 4
havard.hoiby
in reply to: iklimis

Great that you find it useful.

 

The docs are now available here: https://aps.autodesk.com/en/docs/forma/v1/reference/embedded-view-sdk/extension-storage/

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Technology Administrators