Draw 3D text being local THREE.js - three.js

I downloaded three.js, gltfloader.js to my pc, and run site with threejs scene, as a local file in opera.
To draw text using TextGeometry I need to load font using FontLoader, but the problem is that it loads font file using ajax, that is impossible for local files in opera.
What to do?
What if to modify my local GLTFLoader.js file, by just pasting there as a string plain text from my json font file and change httprequest function to read from that string?

No chrome-need, no plugins, no flags
So, with help prisoner849, I had to do this:
Create string variable and put the entire text from json font file here. Attention! There will be characters like "\\" or "\"" or"\r". Easiest way to deal with it, if you don’t need to use them, is just replace them with any non-conflicted character like ї
var data=JSON.parse(your_variable);
var loader=new THREE.FontLoader(); var font=loader.parse(data);
Use font in TextGeometry

Related

Issues adding texture to Reality Converter?

Anyone having issues with Reality Converter by Apple. Mainly, when I add an .obj file, it’s able to display the white object. However, when I go ahead and add a texture .png files into the Materials folder, nothing gets updated. I end up with a plain white 3d object (even after restarting/exporting).
The only way it works is if I upload a .gITF folder, where it will actually add in the textures/color.
Not sure if this is a glitch? Or if I’m doing something wrong?
In order to apply a texture to .obj file you need not only a texture file but also its inseparable companion .mtl file (Material Template Library) – a special material definitions file for .obj.

How to save images into playerprefs and display them to another scene?

I'm a beginner in Unity. And so far of what I read, playerprefs could store image in a byte form. Still, I'm having trouble in this one. Because, I'm having an error in converting texture2d to bytes. In which, I use this code
Texture tex = Resources.Load("Sprites/white_black") as Texture2D;
byte[] texbyte = tex.EncodeToPNG();
// ^ this line always result as NullReferenceException on my console.
I have two scenes: Scene1 is images that were going to save to playerprefs which is an example below:
While in Scene 2, all the images that were saved in playerprefs will be show using a button like in below pic:
Also, if you could recommend me other solution I'll search on it. Thank you.
You should not save images in PlayerPrefs but you could just save the name of the sprite to PlayerPrefs, and then load it in another scene from resources, like so: Resources.Load(spriteName);

replacing text in Swiffy

I have a Swiffy file and can see the text converted from Flash in the swiffyobject.
Tried to simply replace the text with new text, but the old text still displays in the movie.
Is text replacement even possible?
Yes you can, easily, but the results can be problematic.
First, are you viewing your file off a test server? - maybe it's a cache issue. On a local swiffy file, I had no problem changing a word (from "dawn" to "sunset"). But the letter spacing went haywire, and the "t" went missing. It looks like swiffy assigns an x-y position and height to each piece of text, so you can only reliably replace text with text of the exact same length.

Importing X3d files into three.js

is there a way to import X3d files into three.js?
Maybe convert the X3d file into something that three.js can read? Like OBJ or STL?
Thanks for the help!
X3DOM
There is no X3D loader for three.js at the moment, but you could use X3DOM instead if you have to use that file format.
Otherwise, you'd have to write your own loader or convert to another format as you suspected.
Convert X3D to OBJ
However you could use the command-line tool AOPT mentioned in the X3DOM issue to make a webservice, then you could make ajax queries to the webservice to use it in client-side javascript.
aopt -i filename.x3db -e filename.obj
Otherwise X3DOM being open source, so you could dig into its code and try to extract only the parts that deal with parsing the file, and write an OBJ file accordingly, but that would require good knowledge of the X3D and OBJ formats, and solid javascript knowledge. You could skip the first part by having a 1-pixel canvas with X3DOM to feed it the files to parse though.

BitmapFont in Skin doesn't draw labels correctly

I made a bitmap font using Hiero, called default.fnt and default.png. I can use these as a BitmapFont in LibGDX, and draw text with the font without problems, using font.draw(). But I can't use this font as the default font in a Skin. I've used the uiskin.json file from here(along with the rest of the skin, but I deleted the Droid Sans files before making my own font), because I have no idea how to make one of my own. From what I've read on the Internet, the .json file is correctly set up: it has the line com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: default.fnt } }, which should make the default.fnt the default font for widgets that use the skin. Still, when I run the program, I see this:
There should be a label above the buttons, and the buttons should have text.
If I do this: startGameButton.getStyle().font = font;, where startGameButton is one of the buttons, and font is the BitmapFont created like this: font = new BitmapFont(Gdx.files.internal("uiskin/default.fnt"), Gdx.files.internal("uiskin/default.png"), false);, the buttons shows the text properly. I don't want to do this since it feels too much like a hack.
I'm following this tutorial, but I've had to look some things up in later revisions of his code, because LibGDX has changed since it was written.
MenuScreen.java(the screen where there are problems)
AbstractScreen.java
Also please tell me if there's a better way to make the menu UI, or if you need other files. The uiskin.json is linked above.
Thank you.
I fixed it. The Droid Sans bitmap image existed in two places, it was part of uiskin.png too. I don't know how, but it probably read the font's letters from that file instead of default.png. So in the end I just renamed the font's .fnt and .png(and the file parameter in the .fnt) and did a search-replace inside the skin's .json, and it all works fine now. I don't know exactly what caused it, but maybe default-font is a reserved word or something.
Anyway, it works now. Thanks to Jyro117 for making me think maybe I shouldn't replace the default but add my own font.

Resources