2nd uv in Aframe for ambient occlusion - java

I would like to use baked AO on an obj-model in Aframe. Don Mccurdy explains
that AO needs a 2nd UV channel and how to solve this in Java here:
https://github.com/aframevr/aframe/issues/2721
I tried it but I don`t get it to work!
var geometry = mesh.geometry;
geometry.addAttribute( 'uv2', new THREE.BufferAttribute( geometry.attributes.uv.array, 2 ) );
How do I point this js-lines to my obj-model in Aframe?
Thanks a lot for help, appreciate! Best, can

Ideally, I'd suggest opening the OBJ file in Blender, adding the Ambient Occlusion texture as described in the Blender docs, then exporting to glTF. The rest will be handled automatically with A-Frame's gltf-model component, and will load more quickly.
If converting to another format isn't an option, you'll need to write a custom component that listens for the model to load, then traverses every mesh in the model (there might be more than one!) and creates an extra UV set:
AFRAME.registerComponent('copy-uvs', {
init: function () {
this.el.addEventListener('model-loaded', function (e) {
e.detail.model.traverse(function(object) {
if (object.isMesh && object.geometry.attributes.uv) {
var geometry = object.geometry;
geometry.setAttribute('uv2', geometry.attributes.uv);
console.log('copied UVs!');
}
});
});
}
});
This copy-uvs component would need to be attached to the same element as your OBJ model.

Related

Why does SWT Edge browser stuck on browser.evaluate()?

all! Asking for your help.
I'm pretty new to SWT - so please do not judge me strictly for questions.
I have a big/old RCP app. It has many views that use embedded browser.
Recently made 2 major updates:
Updated Eclipse platform from 3.7.2 to 4.21;
switch from IE to Edge browser;
The package that I'm using has version:
org.eclipse.swt.win32.win32.x86_64
Bundle-Version: 3.117.0.v20210906-0842
OS: Windows 10
Problem:
After clicking the button on embedded browser page, JavaScript calls the Java MyFunction extends BrowserFunction. Which prepares the data to refresh the page. And before refresh it calls browser.evaluate() to get some number from JS side:
Double numberFromJS = (Double) browser.evaluate("return 2+2; //this expression just for example")
The main thread stuck in the while loop, because pstr[0] == null always true.
package org.eclipse.swt.browser;
class Edge extends WebBrowser {
...
static int callAndWait(String[] pstr, ToIntFunction<IUnknown> callable) {
int[] phr = new int[1];
IUnknown completion = newCallback((result, pszJson) -> {
phr[0] = (int)result;
if ((int)result == COM.S_OK) {
pstr[0] = wstrToString(pszJson, false);
}
return COM.S_OK;
});
pstr[0] = null;
phr[0] = callable.applyAsInt(completion);
completion.Release();
Display display = Display.getCurrent();
while (phr[0] == COM.S_OK && pstr[0] == null) { // <-------------- here
if (!display.readAndDispatch()) display.sleep();
}
return phr[0];
}
}
investigation:
Here https://www.eclipse.org/swt/faq.php I found a limitation about Edge and evaluate, but there is no Exception throwed;
Tried to debug the display.readAndDispatch(), but there is lack of java docs and it jumps into native methods - not clear for me what should exactly happen.
As I understood in general it should handle message from OS and pass it into completion callback from above and set some value into pstr[0];
interesting observation - the evaluate() method for this browser is successfully passed just on it creation. Looks like it became broken after something.
Questions:
Any suggestion to pay attention/check some places?
Is there known issues for that method and workarounds for it?
Is it possible that the messages from system are intercepted from some other place?
Thanks in advance!

Why getAllTrackables method return only one face?

I'm running the arcore sample of new version (1.7.0).
In the sample of AugmentedFace, why below statement return only one face?
Collection<AugmentedFace> faceList =
sceneView.getSession().getAllTrackables(AugmentedFace.class);
Did I miss something? or is it just kind of limitation?
ARCore's Augmented Faces feature was designed to work primarily with one face. But you can use it for more faces.
// Get a list of detected faces.
Collection<AugmentedFace> faceList = session.getAllTrackables(AugmentedFace.class);
for (AugmentedFace face : faceList) {
// Create a face nodes and add it to the scene.
AugmentedFaceNode faceNode1 = new AugmentedFaceNode(face);
AugmentedFaceNode faceNode2 = new AugmentedFaceNode(face);
faceNode1.setParent(scene);
faceNode2.setParent(scene);
// Overlay the 3D assets on faces.
faceNode1.setFaceRegionsRenderable(faceRegionsRenderable1);
faceNode2.setFaceRegionsRenderable(faceRegionsRenderable2);
// Overlay textures on faces.
faceNode1.setFaceMeshTexture(faceMeshTexture1);
faceNode2.setFaceMeshTexture(faceMeshTexture2);
}
It returns multiple faces when possible.
Access it using a for loop:
for (AugmentedFace face : faceList) {
AugmentedFaceNode node = new AugmentedFaceNode(face);
//create models/texture, setParent, etc
}

Issue with browser zoom in Flex app

We have an issue with our Flex application. It has Flex UI component and a backend java component.
When the browser is zoomed to more than 100%, application becomes completely frozen (no component not even scroll bar responds).
Am new to Flex, any pointers to fix this issue would be really helpful.
-------UPDATE
Actuallly I figured out that problem occurs when invalidateProperties function is called on UIComponent.as for one of our custom components.
If I comment this call, it works all fine.Any idea?
------- UPDATE2
setDataList method makes a call to invalidateProperties which trigger commitProperties. Issue happens # the line
vboxContainer.addChild(checkBox);
in commitProperties function.
Below is the code for setDataList and commitProperties.
public function set dataList(value:ArrayCollection):void{
//_dataList = value;
_dataList = ObjectUtil.copy(value) as ArrayCollection;
dataListChanged = true;
invalidateProperties();
}
override protected function commitProperties():void{
super.commitProperties();
if(dataListChanged){
vboxContainer.removeAllChildren();
for each(var itemLabel:VO in _dataList){
var checkBox:MultilineCheckBox = new MultilineCheckBox();
checkBox.label = itemLabel.principleName;
checkBox.selected = itemLabel.checked;
/*checkBox.setStyle("paddingBottom",0);
checkBox.setStyle("paddingTop",0);
checkBox.setStyle("verticalGap",0);
checkBox.setStyle("fontSize",10); */
//checkBox.setStyle("height",10);
//checkBox.setStyle("width",700);
checkBox.width = 850;
checkBox.addEventListener(MouseEvent.CLICK, updateSelectedValues);
vboxContainer.addChild(checkBox);
}
dataListChanged = false;
}
}

Add space between graph and tick labels in GraphView?

I am trying out the GraphView Library for creating charts on Android. It looks quite decent, but I am wondering if there is a way to add some space between the tick labels and the graph itself. As you can see, there is basically none:
I use the following code to set up the graph (very similar to the example):
GraphView graph = (GraphView)view.findViewById(R.id.graph);
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[] {
new DataPoint(0, 1),
new DataPoint(1, 5),
new DataPoint(2, 3)
});
graph.addSeries(series);
I tried using graph.getGridLabelRenderer().setPadding(), but that just added padding around the whole graph.
So, is there a way to put some padding around those labels?
yes it is possible in the current version in github (will be released in 4.0.1).
There is the method:
graph.getGridLabelRenderer().setLabelsSpace(x)
Follow this example to give your graph a custom label formatter. By doing so, you can at least add space padding to your y-axis labels (if not newline spacing to your x-axis labels).
// GraphView 4.x
graph.getGridLabelRenderer().setLabelFormatter(
new DefaultLabelFormatter() {
#Override
public String formatLabel(double value, boolean isValueX) {
if (isValueX) {
// show normal x values
return super.formatLabel(value, isValueX);
} else {
// show currency for y values
return super.formatLabel(value, isValueX) + " €";
}
}
}
);
I pulled this example from the GraphView documentation.
Otherwise, I found it interesting that someone chose this answer as the best response for a similar question.

How do I set the position of the mouse in Java?

I'm doing some Swing GUI work with Java, and I think my question is fairly straightforward; How does one set the position of the mouse?
As others have said, this can be achieved using Robot.mouseMove(x,y). However this solution has a downfall when working in a multi-monitor situation, as the robot works with the coordinate system of the primary screen, unless you specify otherwise.
Here is a solution that allows you to pass any point based global screen coordinates:
public void moveMouse(Point p) {
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
// Search the devices for the one that draws the specified point.
for (GraphicsDevice device: gs) {
GraphicsConfiguration[] configurations =
device.getConfigurations();
for (GraphicsConfiguration config: configurations) {
Rectangle bounds = config.getBounds();
if(bounds.contains(p)) {
// Set point to screen coordinates.
Point b = bounds.getLocation();
Point s = new Point(p.x - b.x, p.y - b.y);
try {
Robot r = new Robot(device);
r.mouseMove(s.x, s.y);
} catch (AWTException e) {
e.printStackTrace();
}
return;
}
}
}
// Couldn't move to the point, it may be off screen.
return;
}
You need to use Robot
This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed. The primary purpose of Robot is to facilitate automated testing of Java platform implementations.
Using the class to generate input events differs from posting events to the AWT event queue or AWT components in that the events are generated in the platform's native input queue. For example, Robot.mouseMove will actually move the mouse cursor instead of just generating mouse move events...
Robot.mouseMove(x,y)
Check out the Robot class.
The code itself is the following:
char escCode = 0x1B;
System.out.print(String.format("%c[%d;%df",escCode,row,column));
This code is incomplete by itself, so I recommend placing it in a method and calling it something like 'positionCursor(int row, int column)'.
Here is the code in full (method and code):
void positionCursor(int row, int column) {
char escCode = 0x1B;
System.out.print(String.format("%c[%d;%df",escCode,row,column));
}

Categories

Resources