Cannot apply matrix to loaded model using three.js - three.js

I would like to load a model using three.js and then apply a transformation matrix on top of it. This is the code I am using:
var loader = new THREE.OBJMTLLoader();
loader.addEventListener('load', function (event)
{
var object = event.content;
object.matrixAutoUpdate = false;
object.applyMatrix(object_accumulated_matrix);
scene.add(object);
},
{
useWorker: true
});
// should check if ".mtl" file exists but there is no access to the filesystem
loader.load(dir_file_name + ".obj", dir_file_name + ".mtl");
and these are the contents of the object_accumulated_matrix variable:
({elements:{0:1, 1:0, 2:0, 3:0, 4:0, 5:1, 6:0, 7:322, 8:0, 9:0, 10:1, 11:0, 12:0, 13:0, 14:0, 15:1}})
There is a 322 translation value on the Y-axis but I can not seem to get it to work. I have also tried:
object.matrix.copy(object_accumulated_matrix);
but that did not work either.
I would appreciate any help.
Thank you.

Your object_accumulated_matrix is transposed.
You can also try
object.geometry.applyMatrix( object_accumulated_matrix );
which will modify the geometry itself.

Related

Access GlideRecord from within service portal widget

How can I run a Glide query from in a widget? (Service Portal)
This code runs fine in the script-background editor, but it doesn't work in the Server-script section of my widget:
var grTask = new GlideRecord('task');
grTask.get('number', "REQ0323232"); // hardcoded good sample
destination_sys_id = grTask.sys_id;
When I run the code in Scripts, I get:
*** Script: sys_id: 0f4d[...]905
When I run it in the widget, I get:{}
To elaborate on my Widget code:
Body HTML template
data.destination_sys_id = {{data.destination_sys_id }}
Server script
(function(){
var destination_sys_id = "initialized";
var grTask = new GlideRecord('task');
grTask.get('number', "REQ0323232");
destination_sys_id = grTask.sys_id;
data.destination_sys_id = destination_sys_id;
})()
you can add it as c.data.destination_sys_id nad at the time of assigning the value to object always use .toString() in order to stringify the field value.
I needed a .toString(); in my server script:
(function(){
var destination_sys_id = "initialized";
var grTask = new GlideRecord('task');
grTask.get('number', "REQ0323232");
destination_sys_id = grTask.sys_id.toString(); // <- note the addition of .toString()
data.destination_sys_id = destination_sys_id;
})()
Another way is to use grTask.getUniqueValue() instead of grTask.sys_id.toString().
Also, getters and setters are recommended with GlideRecord, so use grTask.getValue('sys_id') instead of grTask.sys_id.toString().

THREE.RGBELoader() HDR exposure does not change

I want to use sibl.
const loadHDR = () => {
new THREE.RGBELoader().load('./resource/textures/HDR/Etnies_Park_Center_3k.hdr', (texture, textureData)=> {
texture.encoding = THREE.RGBEEncoding;
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.NearestFilter;
texture.flipY = true;
console.log(texture)
textureData.height = 1200
textureData.width = 1200
textureData.exposure = 10
console.log(textureData)
const cubemap = new THREE.EquirectangularToCubeGenerator(texture, { resolution: 3200, type: THREE.UnsignedByteType });
exrBackground = cubemap.renderTarget;
cubeMapTexture = cubemap.update(renderer);
texture.dispose();
})
}
This is my code. and
console.log(textureData)
The above code results show the revised values well.
But cubemap's exposure does not change.
Another problem is reading .ibl file
I have to read the position of the sun in webgl, but I can't read the file.
I am using webpack. fs library no exist.
I've been trying to adjust exposure with RGBELoader as well. It looks like you have to set it as a property to the renderer, since the properties that you list are only returned by the module in the callback function. They don't "set" anything.
It looks like the functions related to environment maps have changed significantly since you asked this question. For instance, THREE.EquirectangularToCubeGenerator apparently no longer exists. It looks like pmremGenerator.fromEquirectangular is intended as the replacement, but I'm not entirely sure.
Here is my code, which loads an Equirectangular image and converts it to a cube map, then applies it as a background. The exposure can be set with renderer.toneMappingExposure, which works in r112. Note that this is the module version.
new RGBELoader()
.load('filename.hdr', (hdrEquiRect, textureData) => {
hdrCubeRenderTarget = pmremGenerator.fromEquirectangular(hdrEquiRect);
pmremGenerator.compileCubemapShader();
scene.background = hdrCubeRenderTarget.texture;
renderer.toneMapping = LinearToneMapping;
renderer.toneMappingExposure = 0.5;
});
This example uses renderer.toneMappingExposure to adjust the exposure of the HDRi background:
https://threejs.org/examples/?q=hdr#webgl_materials_envmaps_hdr
Edit - since r116 you also need to set renderer.toneMapping to LinearToneMapping1.

Unity: Loading image from URL failed

I am loading image from script to texture from URL. It is loading successfully, but the image is not reflecting on the texture.
How can I fix this?
you should UV unwrapped your model(that you want to put your image on it as a texture) you save the uv and then import it to unity then you can apply texture to it , here is tutorial that will show you how to do it in blender
Alright, if I'm gathering from the image correctly, it looks like you're using NGUI. If so, then you don't use Mesh Renderer. It's been a little bit since I used NGUI, but you need a reference to the game object or to the UITexture component that is on the game object. So I'll provide some code samples below for both scenarios. But you don't use a mesh renderer unless you're wrapping the texture around a 3D model. If this is for the UITexture then you would attach the image on there.
Game Object Reference:
imageObject.GetComponent<UITexture>().mainTexture = textureToUse;
UITexture Reference:
uiTextureReference.mainTexture = textureToUse;
I think that is what you were looking for, otherwise you need to do unwrapping and what not.
It is very easy if you are using NGUI.
Create a UITexture.
Refer it in you class either by declaring it public variable of getting it at runtime.
Import MiniJSON class that is easily available on internet. (Do not hesitate if you failed to find MiniJSON.Json, it could be MiniJSON.Deserialize or only Json.Deseiralize)
Following is the code snippet to get Facebook Display Picture with User_API_ID
string myImageUrl = "https://graph.facebook.com/"+API_ID+"/picture?type=large&redirect=0";
WWW myImageGraphRequest = new WWW(myImageUrl);
yield return myImageGraphRequest;
if (!string.IsNullOrEmpty(myImageGraphRequest.error))
Debug.Log("Could not fetch own User Image due to: " + myImageGraphRequest.error);
else
{
var myImageData = MiniJSON.Json.Deserialize (myImageGraphRequest.text) as Dictionary<string, object>;
var myImageLinkWithData = myImageData["data"] as Dictionary<string, object>;
string myImageLink = (string)myImageLinkWithData["url"];
WWW myImageRequest = new WWW(myImageLink);
yield return myImageRequest;
if (!string.IsNullOrEmpty(myImageRequest.error))
Debug.Log("Could not get user facebook image: " + myImageRequest.error);
else
{
userDP.mainTexture = myImageRequest.texture;
}
}
userDP is your UITexture.

Filtering a loaded kml file in OpenLayers

I'm trying to create an interactive search engine (for finding event tickets) of which one of its features is a visual map that shows related venues using OpenLayers. I have a plethora of venues (3000+) in a kml file that I would like to selectively show a filtered subsection of. Below is the code I have but when I try to run it has a JavaScript error. Running firebug and chrome developer tools makes me think that it is not getting passed the parameters I give because it says that the variables are null. However, I cannot figure out why they are not getting passed. Any insight is greatly appreciated.
var map, drawControls, selectControl, selectedFeature, select;
$('#kml').load('venuesComplete.kml');
kml=$('#kml').html();
function showVenues(state, city, venue){
filterStrategy = new OpenLayers.Strategy.Filter({});
var kmllayer = new OpenLayers.Layer.Vector("KML", {
strategies: [filterStrategy,
new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "venuesComplete.kml",
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true
})
})
});
select = new OpenLayers.Control.SelectFeature(kmllayer);
kmllayer.events.on({
"featureselected": onFeatureSelect,
"featureunselected": onFeatureUnselect
});
map.addControl(select);
select.activate();
filter = new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.LIKE,
property: "",
value: ""
});
function clearFilter(){
filterStrategy.setFilter(null);
}
function setFilter(property, value){
filter.value = value;
filter.property = property;
filterStrategy.setFilter(filter);
}
var vector_style = new OpenLayers.Style();
if(venue!=""){
setFilter('name', venue);
}else if(city!=""){
setFilter('description', city);
}else if(state!=""){
setFilter('description', state);
}
map.addLayer(kmllayer);
function onPopupClose(evt) {
select.unselectAll();
}
function onFeatureSelect(event) {
var feature = event.feature;
var selectedFeature = feature;
var popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(100,100),
"<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description +'<br>'+feature.attributes,
null,
true,
onPopupClose
);
document.getElementById('venueName').value=feature.attributes.name;
document.getElementById("output").innerHTML=event.feature.id;
feature.popup = popup;
map.addPopup(popup);
}
function onFeatureUnselect(event) {
var feature = event.feature;
if(feature.popup) {
map.removePopup(feature.popup);
feature.popup.destroy();
delete feature.popup;
}
}
}
function init() {
map = new OpenLayers.Map('map');
var google_map_layer = new OpenLayers.Layer.Google(
'Google Map Layer',
{type: google.maps.MapTypeId.HYBRID}
);
map.addLayer(google_map_layer);
state="";
state+=document.getElementById('stateProvDesc').value;
city="";
city+=document.getElementById('cityZip').value;
venue="";
venue+=document.getElementById('venueName').value;
showVenues(state,city,'Michie Stadium');
map.addControl(new OpenLayers.Control.LayerSwitcher({}));
map.zoomToMaxExtent();
}
IF I UNDERSTAND CORRECTLY, your kml does not load properly. if this is not the case, please disconsider my answer.
it is very important to check if your kml layer was properly loaded. i have a map that loads multiple dynamic (from php) kml layers and it is not uncommon to have a large layer simply not load. when that happens, the operation is aborted, but, as far as openlayers is concerned, the layer was properly loaded.
so i do 2 things: i check if the amount of loaded data meets the expected number of features in my orginal php kml parser (i use a jquery or ajax call for that) and then, in case there is a discrepancy, i try reloading (since this is a loop, i limit it to 5 attempts, so as not to loop infinitely).
check out some of my code here

ReferenceError: "BarSeriesImpl" is not defined

My report works fine in BIRT- it shows some Bar chart graphic.
But when I import in some system (IBM maximo) I am getting this error instead of displaying the bar chart:
ReferenceError: "BarSeriesImpl" is not defined. at line 8 of chart script:''
I used this script to show me some values on Bar chart.
importPackage( Packages.java.util );
importPackage( Packages.org.eclipse.birt.chart.model.type.impl );
function afterDataSetFilled(series, dataSet, icsc)
{
if( series.getClass() == BarSeriesImpl ){
var inv =
parseInt(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("IN"));
var outv =
parseInt(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("OUT"));
var canv =
parseInt(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("CANCELED"));
var narray1 = new ArrayList( );
narray1.add(inv);
narray1.add(outv);
narray1.add(canv);
dataSet.setValues(narray1);
}else{
var catArray = new ArrayList();
catArray.add("IN");
catArray.add("OUT");
catArray.add("CANCELED");
dataSet.setValues(catArray);
}
}
How to solve this? Does I have to import somehow this class in my system or ..?
Thank you
I know I'm resurrecting an old question but this just caught my eye because it was similar to another post I answered this week. I think you might be missing org.eclipse.birt.chart.model.type.impl.BarSeriesImp in the systems that you are getting this error message. I think if you add the BIRT runtime jars to the lib path then it should resolve that error.

Resources