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

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.

Related

Three.js - mtlLoader materials

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)

How to dispatch event on object method call in Three.js?

I've tried to dispatch an event on a method call like this:
Group.remove(obj).dispatchEvent({type:'remove', message:'Object removed'});
and listen to it on the canvas, like this:
document.getElementById('threeCanvas').addEventListener('remove', onObjRemove, false);
function onObjRemove(event){ console.log(event)}
but nothing happens...
On the page of Three.js Object3D says that Three.js EventDispatcher methods are available. Sooo what am I doing wrong?
r98
THREE.EventDispatcher has nothing to do with DOM events. It just enables an event-driven API on custom JavaScript objects. The following example from the github repository might help to better understand this:
function Car() {
this.start = function () {
this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );
};
}
Object.assign( Car.prototype, EventDispatcher.prototype );
// Using events
var car = new Car();
car.addEventListener( 'start', function ( event ) {
alert( event.message );
} );
car.start();
three.js R99

spotLightHelper not pointing to target when loaded from json scene

I am using the latest version of Three.js(82) and importing my spot light from blender exporter(json). I have the following code when looping over all the scene objects after loading:
// loop
if(object instanceof THREE.SpotLight){
lightHelper = new THREE.SpotLightHelper(object);
scene.add(lightHelper);
}
// after loop
spot = scene.getObjectByName("Spot",true);
spot.target = scene.getObjectByName("Cube",true);
// in render() funcition
lightHelper.update();
The spotlight helper shows up but it never points to the target. If I try to add a spotlight to the scene manually, it works fine. I think it has to do something with the spotlight being in the child scene. Can anyone suggest a fix for this?

Three.js import object from blender causes weird peeling of materials

I seem to have a problem importing a json object exported from Blender.
Everything seems to be working fine, but the materials aren't rendering correctly.
Does anyone have any idea as to why this peeling occurs?
I'm adding it simply via the ObjectLoader
function jsonLoad(url) {
var loader = new THREE.ObjectLoader();
loader.load(url, function (geometry, materials) {
scene.add(geometry);
});
}
Thank you very much in advance!

Data binding not working rivets js

I just started using rivets js a couple of days before. So i am studying it. But got stuck myself
I have created a fiddle here
What i want to do is. I want to remove the data from the div and put another set of data's inside that
So at first the binding is working. But second time when i empty the div and once again bind Its not working
Created Fiddle
http://fiddle.jshell.net/m8j4ycj1/
function render() {
rivets.bind($("#hello"), datas);
return this;
}
rivets.bind($("#hello"), data);
setTimeout(function(){
debugger;
$("#hello").empty();
render();
},1000)
In this code the first binding is working but not after the setTimeout
as i understand you just want to empty the div?
so try to emtpy the model.
if data is:
data = { username: '12345' };
do
data.username = '';
and the view should be updated automatically
greez

Resources