How to change transparency of a node? - arcore

I'm trying to change transparency of a node. This node has a Renderable attached to it, which is imported from .obj converted to .sfb file. However, nothing seems to be working.
So far, I've tried setting "opacity" property for the material to 0.5, but haven't had much success. Below you can see an example of the code:
this.sceneView.getScene().callOnHierarchy(node -> {
Renderable r = node.getRenderable();
if (r != null) {
for (int i = 0; i < r.getSubmeshCount(); i++) {
Material m = r.getMaterial(i).makeCopy();
m.setFloat("opacity", 0.5f);
r.setMaterial(i, m);
}
}
});

Related

Can't access GLTF/GLB submesh nor material info when using (archived) Sceneform 1.16.0

Under Sceneform 1.16.0 is not possible to access to submeshes nor materials info present in a GLTF/GLB file, as their count is always zero.
Regarding that this is now an open-source (and archived-abandoned) project by Google, it's possible to inspect the code of Renderable class in order to try to locate where the problem is generated.
This brings us to the constructor:
#SuppressWarnings("initialization")
protected Renderable(Renderable other) {
if (other.getId().isEmpty()) {
throw new AssertionError("Cannot copy uninitialized Renderable.");
}
// Share renderableData with the original Renderable.
renderableData = other.renderableData;
// Copy materials.
Preconditions.checkState(other.materialNames.size() == other.materialBindings.size());
for (int i = 0; i < other.materialBindings.size(); i++) {
Material otherMaterial = other.materialBindings.get(i);
materialBindings.add(otherMaterial.makeCopy());
materialNames.add(other.materialNames.get(i));
}
renderPriority = other.renderPriority;
isShadowCaster = other.isShadowCaster;
isShadowReceiver = other.isShadowReceiver;
// Copy collision shape.
if (other.collisionShape != null) {
collisionShape = other.collisionShape.makeCopy();
}
changeId.update();
}
...where the original Renderable (other) has zero submeshes (other.renderableData) and materials (other.materialBindings).
Any help with this?
Best regards.

Where is threshold for cluster strategy in openlayers 3?

In openlayers 2.8 there was a threshold associated with the cluster strategy as per ticket https://trac.osgeo.org/openlayers/ticket/1815.
In openlayers 3 there is no mention of it anywhere (and the strategy paradigm seems to be gone as well).
http://openlayers.org/en/master/apidoc/ol.source.Cluster.html
Does anyone know if there exist a ticket for this feature?
The paradigm has changed considerably. In OpenLayers 3 you create a new layer, with a cluster style, and the "threshold" is set as a maxResolution, or minResolution in the layer's options.
Similar to:
var clusterLayer = new ol.layer.Vector({
visible: true,
zIndex: insightMap.totalServcies - element.SortOrder,
id: Id,
serviceId: element.Id,
minResolution: clusteringThreshold,
cluster: true,
});
You can also use minZoom and maxZoom according to the documentaiton, but I've encountered issues with them performing consistently.
Update
It's actually possible to have a proper cluster threshold without recompiling the library. You need to use the geometry of each feature (from the features property of the cluster) in the style function.
const noClusterStyles = [];
vectorLayer.setStyle(feature => {
const features = feature.get('features');
if (features.length > 5) {
return clusterStyle;
} else {
for (let i = 0; ii = features.length; i < ii; ++i) {
const clone = noClusterStyles[i] ? noClusterStyles[i] : noClusterStyle.clone();
clone.setGeometry(features[i].getGeometry());
noClusterStyles[i] = clone;
}
noClusterStyles.length = features.length;
return noClusterStyles;
}
});
Thank you to #ahocevar for the code snippet.
Another solution would require modifying the OL3 library itself.
The ol.source.Cluster.prototype.cluster_ function has the following code snippet :
var neighbors = this.source_.getFeaturesInExtent(extent);
ol.DEBUG && console.assert(neighbors.length >= 1, 'at least one neighbor found');
neighbors = neighbors.filter(function(neighbor) {
var uid = ol.getUid(neighbor).toString();
if (!(uid in clustered)) {
clustered[uid] = true;
return true;
} else {
return false;
}
});
// Add the following
// If one element has more too many neighbors, register it as a cluster of one
// Size-based styling should be handled separately, in the layer style function
let THRESHOLD= 3;
if(neighbors.length > THRESHOLD) {
this.features_.push(this.createCluster_(neighbors));
} else {
for(var j = 0 ; j < neighbors.length ; j++) {
this.features_.push(this.createCluster_([neighbors[j]]));
}
}

Updating a point in a line chart when data grouping is in effect

I need to update a specific point in the chart when new data arrives. I've written the following function:
function updatePoint(series, x, y) {
for (i = 0; i < series.data.length - 1; i++) {
var point = series.data[i];
if (point.x === x) {
point.update(y);
return;
}
}
}
This works fine, unless the chart has more than turboThreshold points, in which case the series.data is gone, and I only have series.xData and series.yData to work with. I tried the following variant, but the chart does not actually update:
function updateTurboPoint(series, x, y) {
for (i = 0; i < series.xData.length; i++) {
if (series.xData[i] === x) {
if (series.yData.length > i) {
series.yData[i] = y;
return;
}
}
}
}
Setting a breakpoint on the return, I verified that series.yData[i] has the new value, even though it did not appear on the chart. How can I get this to actually update the chart?
I am using HighStock 2.0.4.
EDIT: Created a JSFiddle: http://jsfiddle.net/swish014/2unh1cLa/
EDIT: Changed the title, as I (now) do not believe turbo mode has anything to do with it.
The two comments were key to figuring out my own problem.
It is related to dataGrouping (and not turbo mode as I first thought).
The series.points array does exist, and updating a point there does update the chart as desired.
In my question, I listed two separate functions to update points, but I believe I can use just one function:
function updatePoint(series, x, y) {
for (i = 0; i < series.points.length - 1; i++) {
var point = series.points[i];
if (point.x === x) {
point.update(y);
return;
}
}
}

my shapes aren't changing colors I'm not sure why

I have a code that draws a bunch of customized shapes from an xml... I want to make each shape select-able /de-selectable by changing the color of the object and changing backk all other colors when things change but my codes broken but i'm not getting any errors or anything it just doesn't work.
var graphicsShape
function drawLayer(layer){
for (var i =0; i < xmlDoc.getElementsByTagName("polygon").length; i++)
{
if (layer == xmlDoc.getElementsByTagName("polygon")[i].childNodes[0].attributes[4].value)
{ drawSegment(i);
}
}
}
// layer = index z
function drawSegment(a){
var vertexList = xmlDoc.getElementsByTagName("polygon")[a].childNodes;
var graphicsObject = new createjs.Graphics();
graphicsShape = new createjs.Shape(graphicsObject);
graphicsObject.setStrokeStyle(1);
graphicsObject.beginStroke(createjs.Graphics.getRGB(0,0,0));
graphicsObject.beginFill(createjs.Graphics.getRGB(255,0,0));
for(var i = 0; i < vertexList.length; i++){
graphicsObject.lineTo(vertexList[i].attributes[2].value, vertexList[i].attributes[3].value)
stage.addChild(graphicsShape);
}
segmentsArray.push(graphicsShape);
//createContainer(segmentsArray[i]);
}
function createArraysForSegments() {
for(var i=0; i <segmentsArray.length; i++){
segmentsData[i] = new Array;
}
}
function ColorChangeAddEventListener() {
for(var i = 0; i < segmentsArray.length; i++){
segmentsArray[i].addEventListener('click', colorChange(i));
}
}
function colorChange(index){
segmentsArray[index].graphics.beginFill('white');
stage.update();
}
i call the functions later
ColorChangeAddEventListener();
drawLayer(0);
stage.update();
if i type segmentsArray[0].alpha =0.5; it works for that shape, but when I put it in segmentsArray[0].addEventsListener('click', function){segmentsArray[0].alpha=0.5;}) that doesn't work
Just setting the beginFill won't affect the current shape, you will also have to segmentsArray[index].graphics.clear() and redraw the shape.
beginFill() is not the setter for a property but rather a command that affects subsequents commands, like drawRect() for example.

Weird lines in Skybox

I have a problem with visible lines appearing at the edges of the Skybox.
http://project-vanquish.co.cc/index.php <-- Shows the problem
Has anyone got any ideas as to why they are appearing? The textures don't have the white edge.
Rendering code block:
public override void Render(GraphicsDevice device)
{
device.DepthStencilState = DepthStencilState.None;
for (int i = 0; i < 6; i++)
{
this.sides[i].Position = CameraManager.ActiveCamera.Position + this.offsets[i];
EffectManager.ActiveShader.SetParameters(this.sides[i]);
foreach (EffectPass pass in EffectManager.ActiveShader.Effect.CurrentTechnique.Passes)
{
pass.Apply();
this.sides[i].Render(device);
}
}
device.DepthStencilState = DepthStencilState.Default;
}
Store your SamplerState:
SamplerState samplerState = device.SamplerStates[0];
Then, set it to AnisotropicClamp (or your preference):
device.SamplerStates[0] = SamplerState.AnisotropicClamp;
then after the render, reset your setting:
device.SamplerStates[0] = samplerState;

Resources