Display glTF scenes in a Jupyter Notebook - jupyter-notebook

I use Jupyter notebooks to teach fluid mechanics. It allows me to present students with various forms of media from basic python examples to videos and 3D models.
https://github.com/nolankucd/MEEN20010
Currently I use pyGEL3D to display simple OBJ files and it works reasonably well. The models can be rotated and zoomed etc but there is no support for materials or animation. I can export the notebooks to embedded html and everything works. This is convenient because I can support students with different technical abilities.
I’d like to transition to glTF files created in Blender to avail of animation and material support. I want to keep the solution simple or self contained to keep the simplicity of the material.
I’ve tried a few different approaches. I’ve found pyVista can load the scene but does not support animation and performance can be poor.
Using an iframe I’ve tried a few viewers.
Don McCurdy’s viewer (https://gltf-viewer.donmccurdy.com) works well but I need to manually load local files via drag and drop. I can load a file hosted via CORS but I’d like to load a local file automatically.
from IPython.display import IFrame
model_url = "https://www.khronos.org/assets/gltf/BusterDrone.glb"
IFrame("https://gltf-viewer.donmccurdy.com#kiosk=1&model="+model_url, width=800, height=600)
There is a loader example on threejs.org which works nicely and loads the example files but I’m unsure how to modify it to load a local file.
https://threejs.org/examples/#webgl_loader_gltf
Can anyone help me understand how display a glTF file in Jupyter?

Related

Is there a way to generate windows and/or components in Ignition?

I was hoping that Ignition had a way to import/export windows to a non-binary format such as JSON or XML, but that seems not to be the case (or is there a way?).
Is there a way to use the script console to generate and populate a new window, or to insert components into an existing window?
This would be used for inserting templates and other components, such as navigation buttons etc.
Yes, but...
I assume here that you're referring to Vision windows. The windows are indeed binary serialized, but the underlying structure is XML. But getting the deserialization done programmatically is a pain and probably not worth it.
You can get a feel for what this looks like by opening a Vision window in the designer, right-clicking its Root Container and choosing Copy, then pasting it into Notepad. I myself tried to find a way to do this from a module and decided it wasn't worth it. For more detail, you can view that thread in the Ignition forum here.
However, that's not really useful for generating and populating a new window.
To do that, you need to do some Java programming. Vision is Java Swing under the hood. There are a couple ways you can dynamically build / populate a Window.
From Python, you can import any Java libraries you need and generate the window dynamically. For relatively simple things, you're probably better off working with the Template Canvas component. There's an Ignition forum thread discussing this topic here. This would be more of a run-time generation, not from the Script Console.
You can write your own module to do it.
Module SDK Vision Component Guide
Vision Component Module Example
Good luck!

Download complex 3D JS/Canvas webpage for offline

I'm attempting to download a truly offline version of this interactive 3D model of a home, as seen on this webpage: https://my.matterport.com/show/?m=bDbFD5mSEb5&play=1&lang=en
Because it loads dynamically, all the basic offline downloaders won't work.
I'm wondering if there's a way to extract a browser's cache, after all the page's content has downloaded? But all modern browsers seem to cache in strange encrypted DB files, and it's not easy to convert that into basic HTML/CSS/JS.
Is there a more sophisticated tool to extract a dynamic website? Ideally I'd end up with just pure HTML, CSS, and JS, as it's only an HTML5 webpage that loads images onto a canvas. Definitely possible in theory.

using RStudio as an pseudo shiny app

This is a rather general, and curious question.
I am working on a moderately complex shiny app, using custom HTML and Javascript code (with menus and independent dialogs), using shiny as a communication protocol with the base R. Everything looks very nice, until I realised that RStudio itself is a web page (or am I wrong?)
The main reason to design a GUI in a shiny app is it's cross-platform, but it still needs to be opened in a web browser. Conversely, RStudio is also a web page but opens just like any other installed software. To me, it looks like a self-contained web browser with different menus.
Now the question: is it possible to use parts of RStudio in a different "app"?
For example, I would love to separate the code editor and the console from RStudio and use them in conjunction with other HTML and Javascript code to produce a GUI similar to RStudio but with different purposes.
To better explain why: RStudio is fantastic, but it has the one big disadvantage (no flame intended, others think this is a feature) that everything must fit in the same page. In order to make the code editor larger, one needs to shrink other parts of the interface. I would like to make them separate dialogs, creating divs when a menu is selected.
Thanks in advance,
Adrian
engineer from RStudio here. You are correct about RStudio itself being "a web page"; the whole UI is effectively done in HTML. There's even a version of RStudio which already runs in a web browser called RStudio Server.
There are unfortunately no extensibility points to do what you want. RStudio internals are largely anonymized and insulated from external access, which make them difficult to separate, re-use, or connect to other services. Here are a few pointers that may be helpful, however:
As a commenter pointed out, it is now possible to pop out the editor window.
You can make an RStudio Add-in which runs in a separate browser window when invoked. Depending on what you want to do in your separate window, you may be able to accomplish it with an add-in.
If you can't use add-ins, the easiest thing to do is actually to just change RStudio itself. It's an open source project, so you're welcome to hack on it and make improvements in reusability or UI flexibility. We welcome pull requests. :-)

Any way to analyze the size of a SWF built in Flex?

I have a Flex application that seems larger than it should be. There is a lot of code in it, but not a lot of assets and it just seems large, but I'm not sure how to go about figuring out where the space is going.
I know about the –link-report option, but it only gives the sizes of externally linked library classes. I'm very interested in seeing a report of the sizes of all the classes and resources in my application and it would be a huge bonus if I could also view their dependencies. Not knowing how the code is compiled I'm not sure if this is even possible, but it seems like it should since the compiler can give me the sizes of individual classes linked from other libraries.
I did some searching around, but couldn't find anything helpful. Everything points to the optimization techniques of modularizing and externally linking libraries, which I understand and will implement, but I would really love some more detailed reports of what my compiled application looks like.
To be clear, I'm not really interested in tips on how to reduce the file size, just a report on what is used for and which classes are referencing what.
Anybody have any ideas?
CORRECTION - The link report does show all classes. My particular project in Flex Builder had several CSS files set to compile to swfs. My link report for the main app was being overwritten by these css compiles!
The link report actually contains all compiled classes and not just the ones in external libraries (at least with the Flex 4 SDK). There is an xsl available that will generate an html file of the link report so it is easier to read.
Check this post: http://blog.iconara.net/2007/02/25/visualizing-mxmlcs-link-report/
There is a command-line utility called flash.swf.tools.SwfxPrinter in swfkit.jar, which comes with Flex Builder (or the plug-in or the SDK) and which you can use to analyze information about class sizes. Joe Berkovitz wrote some good instructions on how to make use of it in his blog, and he was working on an AIR-based GUI tool that leverages it, but I'm not sure if he ever published the tool. Still, you can use his instructions to leverage the utility directly from the JAR.
I found a handy little AIR app that really helps organize the link report info.
http://www.kahunaburger.com/2008/03/08/air-link-report-visualizer/
It's old but still works very well.

Is there another way to integrate PDF viewing in a Flex application?

I'm looking at ways to embed PDF viewing in a Flex application.
Currently the only option I've seen is by using the flash.html.HTMLLoader class, which only works if you're using AIR. This isn't a big deal -- I'm willing to use AIR if I have to -- but based on my experimentation with viewing a PDF this way it appears that AIR simply integrates the embedded Adobe PDF browser Plug-in for viewing, which not only shows the PDF page(s), but provides all of the manipulation controls as well (zooming, printing, etc.) which I don't want to see.
I'm looking for something that works somewhat along the lines of the JPedal library for Java -- an embedded component that simply renders the PDF alone.
Has anyone found a way to do this with either AIR's built-in component or via some other method?
There are a couple of ways, but neither actually have the PDF in the Flex App:
Convert the PDF to SWF. Use this tool or one like it to convert the file over.
Use HTMLComponent, a method that uses an iframe over your flash/flex to make it appear like an external page is in your app. There are a few downsides to this method however - most of them described in detail at Deitte.com.
What you want is possible with AIR and described in this Adobe article:
http://www.adobe.com/devnet/air/flex/quickstart/scripting_pdf.html
Take a look at http://www.adobe.com/devnet/flex/quickstart/embedding_assets/ and see if it helps.
I don't think you can embed PDF files directly (but I'm not really sure) but if you totally need to do it and you don't want to open a new window you could convert the PDF to another format that can be inserted in your app.
If your goal is to simply display the PDF in the Flex environment then you could use the IFrame approach. You can find an example here http://www.deitte.com/archives/2006/08/finally_updated.htm
By using this approach you can load any HTML content which includes PDF's.
Take a look.
Okay guys here is the exact one we're looking
http://subinsugunan.blogspot.com/2009/06/embed-pdf-in-flex-application.html

Resources