How to retrieve the position of a textarea in AFrame - aframe

I was able to get the text value of my textarea by writing this line of code (thanks to Diego Marcos):
console.log("value="+els.components.textarea.textarea.value);
I now want to get the position of said textarea. The line of code:
console.log("value="+els.components.textarea.position); gives result=undefined.
console.log(getAttribute("position")) gives the result [object Object].

Posting Diego's answer:
That's expected. You're getting an object with an x,y and z properties. To print it do var position = el.getAttribute('position'); console.log('x: ' + position.x + ' y: ' + position.y + ' z: ' + position.z);

Related

Unable to see 2D text sprites in Autodesk Forge

I'm trying to render 2D text using Sprites in the Autodesk Forge viewer, but I can't get it to show up. If I consult the layer by console I see that it contains the created Sprite but nevertheless I can’t see it in the scene. I have tried different scaling and position settings but no results.
I attach the code below:
function createText(text, preferencia, tamanyo) {
var sprite = spriteTexto("Prueba texto sprite", preferencia, tamanyo);
if (!NOP_VIEWER.impl.overlayScenes['overlaySprites'])
NOP_VIEWER.impl.createOverlayScene('overlaySprites');
NOP_VIEWER.impl.addOverlay('overlaySprites', sprite);
}
function spriteTexto(text, preferencia, tamanyo) {
var fontface = NOP_VIEWER.fontName;
var fontsize = 18; //tamanyo
var borderThickness = 4;
var borderColor = { r:0, g:0, b:0, a:1.0 };
var backgroundColor = { r:0, g:0, b:0, a:0.0 };
var textColor = { r:0, g:0, b:255, a:1 }; //hexadecimalARgb(preferencia.color);
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
context.font = "Bold " + fontsize + "px " + fontface;
var metrics = context.measureText( text );
var textWidth = metrics.width;
context.fillStyle = "rgba(" + backgroundColor.r + "," + backgroundColor.g + "," + backgroundColor.b + "," + backgroundColor.a + ")";
context.strokeStyle = "rgba(" + borderColor.r + "," + borderColor.g + "," + borderColor.b + "," + borderColor.a + ")";
context.fillStyle = "rgba(" + textColor.r+", " + textColor.g + ", " + textColor.b + ", 1.0)";
context.fillText( text, borderThickness, fontsize + borderThickness);
var texture = new THREE.Texture(canvas);
texture.needsUpdate = true;
var spriteMaterial = new THREE.SpriteMaterial( { map: texture, useScreenCoordinates: false } );
var sprite = new THREE.Sprite( spriteMaterial );
sprite.scale.set(1*fontsize,1*fontsize,1*fontsize);
sprite.position.set(5,5,6);
return sprite;
}
I would be very grateful if you could help me find the error, thank you very much in advance for your help!
EDIT:------------------------------------------------
We want to render 2D text that can be interacted with (specifically select, rotate, and move).
To do this currently we are working with meshes (using MeshBasicMaterial, Mesh and TextGeometry), but it turns out that the text does not look perfectly sharp, it presents aliasing and we’ve found that according to the API reference, the antialiasing is not applicable to 2d.
Here are some examples of the problem, as you can see, the more we move away from the plane, the worse the text looks (and even up close it doesn't look perfect):
We were trying to make a test representing the text with Sprites (despite the fact that it would mean having to change the entire implementation already made with meshes) to try to implement it in another way that will solve the problem. But we see that it is not possible either.
How can we correct the rendering of the text then? Is there a way to fix it or is this the most we can get in 2D? We've tried searching for information on this but we haven't find anything helpful.
Unfortunately, Forge Viewer doesn't support THREE.Sprite at present. It uses a self-maintained three.js r71 and removes this support as I know.
Could you share the use case in detail on why you want to use THREE.Sprite with Forge Viewer? If you don't want to share that publicly, you can send it to forge (DOT) help (AT) autodesk (DOT) com.

Trying to assign a value to CSS in typescript doesn't work

I have script that is taking a HTMLElement and the css.top and css.marginLeft of an element which refuses to set the properties in TypeScript.
here's my code:
let moveable1: HTMLElement = document.getElementsByClassName('moveable1')[0] as HTMLElement;
Here's how I'm getting the values and "trying" to set the properties.
console.log("**style.top** = " + (moveable1.style.top =
String((+this.chatScrollTop + +this.boxScrollTop).toFixed(0))));
console.log("**style.marginLeft** = " + (moveable1.style.marginLeft = String((+this.chatScrollLeft + +this.boxScrollLeft).toFixed(0))));
moveable1.style.top = String(moveable1.style.top);
moveable1.style.marginLeft = String(moveable1.style.marginLeft);
What's happening is:
moveable1.style.marginLeft and moveable1.style.top ALWAYS equals ""
I don't understand.
The console logs are reporting the correct values
style.top = 69
style.marginLeft = 100
top: **<<<=== "EMPTY"** and should be 69
marginLeft: **<<<=== "EMPTY"** and should be 100
Thoughts, anyone?
UPDATE:
Zeh suggested the solution:
I modified it a wee bit...
let top = +this.chatScrollTop + +this.boxScrollTop;
const marginLeft = this.chatScrollLeft + this.boxScrollLeft;
moveable1.style.top = top.toFixed(0) + "px";
moveable1.style.marginLeft = String(parseInt(marginLeft).toFixed(0)) + "px";
console.log("top: " + moveable1.style.top);
console.log("marginLeft: " + moveable1.style.marginLeft);
THANK YOU ZEH!
You're setting a style property to a number and then trying to re-read and convert it to a string. This doesn't work; top (et al) cannot be numbers therefore they're kept at their previous value("").
Also, you need units ("px", "pt", etc) when setting a style, otherwise it won't set either, even if it's a string. Hence when you try converting them from number to string you get another blank string.
// This returns 1
console.log(document.body.style.top = 1);
// Nevertheless, it didn't work, since this returns ""
console.log(document.body.style.top);
This is not a TypeScript problem, this is a JavaScript (rather, a DOM) "problem".
My suggestion is to simplify this code. It's not just hard to read, it's doing a lot that it shouldn't be doing - unnecessary conversions, depending on assignment side effects, etc.
Something like this should work:
const top = this.chatScrollTop + this.boxScrollTop;
const marginLeft = this.chatScrollLeft + this.boxScrollLeft;
moveable1.style.top = top.toFixed(0) + "px";
moveable1.style.marginLeft = marginLeft.toFixed(0) + "px";

JSoup - how does HTML structure affect response?

Trying to learn JSoup but having problems with response that may be due to structure issues (or stupidity, you tell me!). I do a simple query for "a[href]" but it only finds a subset 13 (text search tells me there are 162!). Why does it not find all?
Document doc = Jsoup.connect(J_URL).get();
String srchCSS = "a[href]";
Elements select = doc.select(srchCSS);
Iterator<Element> iterator = select.iterator();
Log.w(TAG, "'" + srchCSS + "' # " + select.size());
while (iterator.hasNext()) {
Element x = iterator.next();
System.out.println("'" + srchCSS + "': " + x.text());
}
Log.e(TAG, "%%% COMPLETE %%%");
I want to get the text from 'p' (see RED arrow). The a[href] above it is NOT being found?!?

Tag type as string variable in selenium

How to pass tag type as a string variable in selenium?
suppose I am having given example:
By.cssSelector: li[__idx='0']
for given example I tried below part
webElement.findElement( By.cssSelector( "'" + tag + "'['" + property + "'='" + indexNumber + "']" ) )
where tag is li and __idx is property.
I am getting error as " Could not locate element with locator ". but if I tried as below then its working correctly.
webElement.getElement().findElement( By.cssSelector( "li[__idx='" + indexNumber + "']" ) )
Is there any syntactical mistake am doing ?
webElement.find( "" + tag + "[" + property + "='" + indexNumber + "']" );
This is the correct way to solve the issue.

TileList item location

In a flex tileList, is there a way to get the cell-address of a given item? i.e. for a given item, get the row/column location for that item in the list.
I've checked the documentation, and no directly, but with a bit of arithmetic you can get yourself sorted.
//asumming this is a change handler
function myTileListChanged(event:Event):void{
var itemsPerRow:Number = myTileList.dataProvider.length / myTileList.rowCount;
var selectedRow:int = Math.floor(myTileList.selectedIndex / itemsPerRow);
var selectedColumn:int = myTileList.selectedIndex - (itemsPerRow * selectedRow);
trace('index: ' + myTileList.selectedIndex + ' is at row: ' + selectedRow + ' column: ' + selectedColumn);
}
Note, I've used the TileList in Flash, so dataProvider might be slightly different, but you'll
still be able to get the picture.
HTH!

Resources