x3dom / x3dom

X3DOM. A framework for integrating and manipulating X3D scenes as HTML5/DOM elements.
http://x3dom.org
Other
813 stars 271 forks source link

Change MovieTexture url attribute in runtime based on the host OS #1251

Closed parthranawat closed 10 months ago

parthranawat commented 1 year ago

Hello,

https://metagrid2.sv.vt.edu/~parthranawat/StroublesTour/

In the above site, I am using the MovieTexture Node to show a video file on a Sphere. The file TriplePoint.x3d loads for the above URL.

I have different sets of videos that I need to show based on the OS of the host viewing the site. Is there a way, I can change the URL field of the MovieTexture in runtime so that different videos are loaded based on the OS?

I am accessing the MovieTexture node as document.querySelector('MovieTexture')

and from that, I can access the video as document.querySelector('MovieTexture')._x3domNode._video

Do I change the source of the video tag? or change the URL field of the MovieTexture?

Please let me know the correct way of moving forward.

andreasplesch commented 1 year ago

Changing the url field of MovieTexture would be the first thing to try. Then a switch node with videosphere choices per OS might be another option. Probably best to avoid managing internals as much as possible.

parthranawat commented 1 year ago

Thanks for the suggestions.

How do I know if my scene is loaded and if I can access the movie texture? Currently, with the code below movieTexture is null, and I cannot change the URL field. Is there some flag or runtime property that tells me that my scene is loaded so that I do not get a null pointer error?

Also after changing the URL field, do I need to redraw my scene? or will it update automatically?

x3dom.runtime.ready = function () {
    let MovieTexture = document.querySelector('MovieTexture');
    console.log("Movie texture is", MovieTexture); // null
};
MacrayBlackhand commented 1 year ago

This is what I use...

gr = document.getElementById("yourX3dElement");

gr.addEventListener("downloadsfinished",

    function () {

    // I have all of the controls for my scenes disabled by default and only enable them once the scene is fully loaded

    // Of course, you can do anything you like at this point

        $("#GameRoomHeader").find(".disabled.btn")

            .removeAttr("disabled")

            .removeClass("disabled");

    }

);

---- On Mon, 20 Feb 2023 16:40:41 -0600 parthranawat @.***> wrote ---

Thanks for the suggestions.

How do I know if my scene is loaded and if I can access the movie texture? Currently, with the code below movieTexture is null, and I cannot change the URL field. Is there some flag or runtime property that tells me that my scene is loaded so that I do not get a null pointer error?

Also after changing the URL field, do I need to redraw my scene? or will it update automatically?

x3dom.runtime.ready = function () { let MovieTexture = document.querySelector('MovieTexture'); console.log("Movie texture is", MovieTexture); // null };

— Reply to this email directly, https://github.com/x3dom/x3dom/issues/1251#issuecomment-1437638499, or https://github.com/notifications/unsubscribe-auth/AWTX3ZRSKZJLQDQE5IXGHV3WYPXGTANCNFSM6AAAAAAVAQYPTU. You are receiving this because you are subscribed to this thread.

andreasplesch commented 1 year ago

It is probably a good idea to look at the examples on x3dom.org and in the test folder on github.

Most use the load event of the inline or body to start processing, for example https://63f2a9fb0256df00084010f9--x3dom.netlify.app/examples/functional/runtime.html

parthranawat commented 1 year ago

Thanks for the suggestions.

I am able to implement a switch node with video sphere choices per OS. This loads different x3d files per OS and gets the desired output. I will still try to work on changing the URL of the MovieTexture tag on runtime as that avoids managing different files per OS. I will let you know how that turns out.

andreasplesch commented 1 year ago

You could also try to replace/append the complete MovieTexture node or the complete Shape node after sniffing the OS.

andreasplesch commented 10 months ago

Feel free to reopen or update.