Three.js - mtlLoader materials - three.js

mtlLoader.load('.mtl_file_path', function (materials) {
materials.preload()
console.log(materials.materials)
objLoader.setMaterials(materials)
objLoader.load('/resource/obj/mycar.obj', function (car) {
do somthing
})
})
This is my code. I want to know my mtl's values.
So, console.log(materials.materials)
console result is
I can see in my brower console, but i don't know how can approach it on code.
I tried
console.log(materials.materials[0])
console.log(materials.materials{"midnight_blue"})
console.log(materials.materials.midnight_blue)

materials.preload()
console.log(materials.materials.midnight_blue)

Related

casperjs evaluate function returns invalid value

I'm now using casperjs for web crawling. Almost everything is good, but I faced some trouble. First, my code is like below.
casper.start().each(SOME_URLS, function(self, URL) {
self.thenOpen(URL, function() {
self.then(function() {
var getDatas = function() {
var title = $('SOME_SELECTOR').map(function() {
return $(this).text();
}).get();
return {
title: title
};
}
data = self.evaluate(getDatas);
console.log(JSON.stringify(data));
});
});
}).run();
I want to get some data from webpage to 'data' variable. Sometimes data is perfectly good(on console.log), but sometimes, data is empty!
Why this happening? What did I wrong?
The problem is you cant call casper.start more than once. Your loop needs to inside the casper.start function or inside a casper.then
See this excellent SO answer to help you do this.
Basically only call casper.start once and place your loop inside a casper.then

How to clear editor.scene before loading a new file?

Working in editor, loading a new geometry, I am trying to query the scene and remove existing geometries. The editor.scene.children and editor.scene.__webglObjects are both undefined. If I console.log( editor.scene ); and expand the object the children and __webglObjects have the elements I am trying to access. My clicker fingers are getting worn out trying to understand this.
Placing a
function deleteOnLoad(){
editor.storage.init( function () {
editor.config.clear();
editor.storage.clear( function () {
} );
});
}
deleteOnLoad();
before the main editor.storage.init seems to be one way to handle this.

jquery each on new elements not working

$('.collapse').each(function() {
var title= $(this).siblings('.accordion-heading').find('a');
$(this).on('show hide', function (e) {
if(!$(this).is(e.target))return;
title.parent().toggleClass('active', 300);
title.parent().hasClass('active') ? $('input.party').prop('value', '') : $('input.party').val(title.siblings('.delete').prop('id'));
var id = title.siblings('.delete').prop('id');
var data = {id: id};
$.post("times.php", data, function(result) {
if(title.parent().hasClass('active')){
$('.times').html('');
} else {
$('.times').html($.parseJSON(result));
}
})
})
})
So I am adding a new accordion-group to my html by adding a new party and I wan't all this to work on the newly added elements as well. I didn't find topics that could help me since it is a bit more specific than any random each function (I think).
This future elements thing is new to me, so I would appreciate some explanations or a good link to a place other that the jquery website which I already checked.
Thank you for your time!
Basically what I want to do this replace $(this).on('show hide', function (e) { with something like $(document).on('show hide', $(this), function (e) {. What I just wrote doesn't work though.
If it is just about the event handler, then you can use event delegation to capture the event on dynamically created elements as well.
There is not reason why you have to use .each here, so just omit it:
$(document.body).on('show hide', '.collapse', function() {
var title = $(this).siblings('.accordion-heading').find('a');
if(!$(this).is(e.target))return;
// rest of the code...
});
this will apply on any new objects matching selector
jQuery(document).on('show hide', '.accordion-heading a', function(event){
...
});

casper js screenshot not working with svg masks

I'm creating visualizations with d3 that use svg masks and I'm trying to get a screenshot using casper js. It usually works fine except it's not rendering the mask properly; it shows all of the layers rather than just the one being masked. This is the casper code:
var casper = require('casper').create();
casper.start('http://localhost:3000', function() {
this.captureSelector('bicycles.png', 'svg');
});
casper.run();
Anybody else having issues with this?
Thanks, Tom
I don't know if it will help, but in my tests I always set the viewport size and then add a delay before running any other code. One reason for the delay is because we are using knockout and DOM elements have not been fully created by the time the 'start' function is called.
So your test would look like this:
var casper = require('casper').create();
casper.start('http://localhost:3000', function () {
casper.viewport(1024, 768);
});
casper.wait(1000); // Wait for knockout bindings and animations...
casper.then(function () {
this.captureSelector('bicycles.png', 'svg');
});
casper.run();
Probably won't help you, but worth a try?

How to animate a dojo gauge?

I'm trying to animate the duration of the value change in a dojo gauge, but I think I'm missing out something, and I can't figure out what it is.
So far, I've got this code working, but the indicator just moves from one point to another, with no animation whatsoever.
require(["dojo/ready", "dojo/dom", "dojox/dgauges/components/black/CircularLinearGauge", "dojox/dgauges/GaugeBase"],
function(ready, dom, CircularLinearGauge, GaugeBase) {
var gauge = new CircularLinearGauge({value:10, animationDuration:5000}, dom.byId("circularGauge"));
setInterval(function() {
var randomValue = Math.floor((Math.random() * 100) + 1);
gauge.set("value", randomValue);
gauge.refreshRendering();
}, 10000);
});
Any help would be highly appreciated, thanks in advance
Looks like its an issue with dojox.dgauges.components.DefaultPropertiesMixin. If you replace the _setValueAttr function to
_setValueAttr: function(v) {
this.getElement("scale").getIndicator("indicator").set("value", v);
}
it should animate for you.
As a side note, all the other functions in DefaultPropertiesMixin sets each property directly instead of using the set function. It might be advisable to change them to use the set function instead.

Resources