Display a custom Babylon JS scene as the Babylon viewer does? - babylonjs

I have a Babylon JS based program that creates (from simple objects (cubes)) and displays that scene.
I can also save that scene as a GLB file.
There is also a Babylon JS Viewer which is able to display that GLB file.
Is there a way to display the created scene as the viewer does (ie create the same space cube, lights and camera)?

If you export your scene as a GLB file if you want to reimport it you have to use BABYLON Gltf loader
https://doc.babylonjs.com/how_to/load_from_any_file_type
The scene will be loaded by default to the (0, 0, 0) position.
For further info and discuss with the community you can directly go to https://forum.babylonjs.com/

Related

Create my own icons from png files in vaadin 23

I have couple .png files and I need to create icons for the button.
Initially it will be a first image and when button is clicked and action is successful, the image shall be replaced with the second one.
What I can see, you can create only predetermined Vaadin icons. Documentation does not even provide images of these icons, only names, therefore I can't even decide if any of those icon will be suitable for me.
If anyone knows how to do it, I will appreciate the tip.
The setIcon method of the Button component actually accepts any component as a parameter. Thus if you want to use png-file as a icon, you can just create Image component using png as a resource for it.
Image image = new Image(png);
Button button = new Button("Button");
button.setIcon(image);
The font-icons from Vaadin Icons collection are naturally more light weight, and you can find visual map of the icons here if you use them instead: https://vaadin.com/docs/latest/components/icons

Using more than 2 marker presets

I want to use 3 markers in a script. I've started to use Kanji and Kiro marker preset without problem.
When i've started to add a third marker (a pattern with letterA.patt file via ar.js url), google chrome (and firefox) complained about a memory problem !
The only solution founded was to modify aframe-ar.js and added letterA as marker preset, like Kiro and Kanji.
Question1: what about that memory problem with my pattern ?
Question2: why not added more marker preset (letterD...) by default in aframe-ar.js ?
Best regards,
Emmanuel
Not really the right platform for this question. You can use any number of markers that you want, you're not limited to just two. The AR.js preset might be limited but you can add your own markers with a .patt file. You can create your AR.js ready tag using the ARjs marker generator or by uploading your model and image target to the echoAR platform and then download the image marker.
After you get you .patt file you can add it to your scene like so:
<a-marker type='pattern' url='./<path to your .patt>'>
Inside your marker just add whatever you would do in a preset marker, just don't forget to close the marker tag.

JAVA FX ImageView only loads certain images when launched

I'm currently working on a poker application for fun and I've encountered another issue when trying to work with imageviews.
Right now my structure for my images is the following:
JavaFXApplication1\src\images
that "images" folder contains two more folders, one being "cards" and the other "playerImages".
Here is a screenshot of it also:project structure
Currently I am using a document relative path within scene builder to initially load the images for each of the cards and players. for each of the cards, the imagepath initially is "#..\images\cards\back.png" which is set in scenebuilder. this method works perfectly fine when launching the application. however, for the player images next to the cards, i have "#..\images\playerImages\player1.png" for example and this doesnt work for some reason.
In scenebuilder the "player1.png" image shows up where it should, but disappears when i launch everything.
I read through Images not showing on launch by the main, but showed on Scene builder but Im not not sure the solution for that is the same for me, as my images are in my source folder.
I tried using the fx:id and setting the image manually in my controller class, but was receiving an error stating that my input stream was null.
I also tried just adding "player1.png" to my root images folder and using that path, and that still didnt work. yet, when I change the player1 image path to anything in the cards folder it works. I dont understand why it works for the images in the cards folder but not in the playerImages folder. Both of those folders are in the same location.
I apologize if this was already answered somewhere else and i am too oblivious to see it, but any insight into this seemingly simple problem would be greatly appreciated.
if you have a similar project structure:
--main
--java
--src
--resources
--images
--cards
back.png
--players
player1.png
you can set images from resources in your java-code. But you need to use getResources()
For example:
#FXML
private ImageView imageView;
Image image = new Image(getClass().getResourceAsStream("/images/players/player1.png"));
imageView = new ImageView(image);
Of course directory "resources: shuild be marked as resources root

What has happened to SwingFXUtils?

I just started using JavaFX 11, and SwingFXUtils seems to be gone (or renamed?)
I tried to download it manually, but the module-system complained about import sun.awt.image.IntegerComponentRaster;, and I couldn't get it to work.
I need to convert Swing Icon to JavaFX image.
Since Java 9, SwingFXUtils has been moved to the javafx.swing module, under the package javafx.embed.swing.
See JavaFX 9 Javadoc and the new JavaFX 11 Javadoc, hosted at https://openjfx.io.
If you have any issue with your sample, make sure you are adding the proper VM options. See the samples from the getting started guide.
Probably you will need to add something like:
--module-path <path-to>/javafx-sdk-11/lib --add-modules=javafx.controls,javafx.swing
SwingFXUtils is still there if you have correctly added the javafx.swing module to your build path (see answer from José) but importing an internal class like sun.awt.image.IntegerComponentRaster is not allowed anymore.
To convert your icon you can try this:
Icon icon; // Your icon
BufferedImage image = (BufferedImage)((ImageIcon)icon).getImage();
WritableImage writable = SwingFXUtils.toFXImage(image, null);
Whether this works or not depends on how your icon was created but it is worth a try.

Flex ItemRenderer Images not appearing at runtime

in datagrid I have an ItemRenderer (which extends UIComponent) which loads images based on a data value, eg:
_img.source = "assets/images/flags/" + value[dglistData.dataField] + ".gif";
When I run my application the images (flags) are appearing in the ItemRenderer. When I build and deploy the application into BlazeDS as an SWF file - the images do not appear. Instead there is the standard "missing icon" link that appears in Internet explorer.
As far as I can tell, my ANT build script includes the above directory "assets/images/flags/" and all the images into the SWF file.
Is this a relative path issue? Not sure, any help would be appreaciated.
Thanks
Mike
When you are assigning a path as source Flash Player is trying to load the images via HTTP requests. Therefore, embedding your images in the SWF has no effect.
There are two possible solutions. Either deploy the folder containing your images to the server and use the corresponding path as your source or embed all your images into the SWF.
A simple example for the second solution. The code assumes that value[dglistData.dataField] corresponds to one of the variables with the [Embed] metadata.
[Embed(source='assets/images/flags/Image1.png')]
private var image1:Class;
[Embed(source='assets/images/flags/Image2.png')]
private var image2:Class;
[Embed(source='assets/images/flags/Image3.png')]
private var image3:Class;
// access the image like this...
_img.source = this[value[dglistData.dataField]];

Resources