3D Window Events

3D Window Events are sent to notify code of interesting things that have taken place. Each event is repsented by an object with common properties:

code type of notification. For list of possible values see table below
wnd 3d window - source of notifications
doDef [Optional], if exist you set to false in order to stop default processing.

Event may have additional custom fields used to get additional information about what happened.

Following events are currently implemented:

"selection" Selection was changed. Additional event properties:
  • event.old - array of old selected nodes.
  • event.current - array of currently selected nodes.
  • event.node - node currently selected by mouse.
"dataReady"

File has loaded, but wasn't displayed yet. This is the right time to preprocess scene and make final adjustments. After displaying, there will "firstFrame" be event.

  • JSON file. This Notification means availability of scene tree file only. Meshes may be available later.
  • IV3D file. Everything but textures is ready.

Additional properties:

  • event.space - 3d space.
  • event.file - url of loaded file.
"firstFrame" First frame, after loading file is ready. There may be relatively big delay after "dataReady" event. Delay depends on file size and it's complexity.
"merged" File has loaded and merged. Additional properties:
  • event.space - 3d space.
  • event.file - url of loaded file.
  • event.group - group with all nodes of this file.
  • event.iid - optional iid, passed to .load method.
"textures" Textures were loaded. Additional properties:
  • event.loaded - number of loaded textures.
  • event.total - total textures used by scene. This number may be changed.
  • event.failed - number of not found textures.
  • event.queue - number of textures in loading queue.
"updated" (obsolete)
Scene has been changed/updated and UI controls should be updated. Used by standard tree-view control.
"progress"

called during load of iv3d file. Additional properties:

  • event.loaded - number of loaded bytes.
  • event.total - totla file size.
"mousedown"

This notification is part of extended API. Additional properties:

  • event.node - node under mouse pointer.
  • event.x - x mouse coordinate.
  • event.y - y mouse coordinate.
  • event.hitInfo - information about hit test result.

set event.doDef to false in order to prevent default processing.

"mouseup" This notification is part of extended API. Additional properties:
  • event.x - x mouse coordinate.
  • event.y - y mouse coordinate.

set event.doDef to false in order to prevent default processing. 

"mousehover" Mouse hover notification. Additional properties:
  • event.x - x mouse coordinate.
  • event.y - y mouse coordinate.

There is no information about node below mouse pointer. Use hit test functionality in order to obtain node.

"camera" Notification for pan, orbit or zoom operations.
Common additional properties:
  • event.type - on of following "pan", "orbit", "dolly", "fov"
  • event.dX - x mouse delta.
  • event.dY - y mouse delta.

set event.doDef in order to prevent changes in view.

pan, orbit

You may change dX, dY in order to change behaviour of pan function.

dolly

event.scale - for orthogonal cameras. You may modify this value in order to limit min/max scale factor.

event.len - for persepctive cameras. You may modify this value in order to limit distance from camera.

fov

For perspective cameras only.

event.fov - for perspective cameras. Modify this value in order to limit min/max field of view. 

"error"

WebGL error.

event.type - type of error. Currentl valuaes are: "hardware", "compile". For compile error, compilation error log and shader text is provided.

These errors happened only in case of out of memory or video memory problems.

"animstart"

Window animation is added to activate animations.

  • event.type - type of animation
  • event.anim - animation object

 

"animend"

Window animation is going to be removed from list of activate animations.

  • event.type - type of animation
  • event.anim - animation object

Sample

view.addRefTarget(function(event)
{
  switch(event.code)
   {
    case "dataReady":
     {
     ivDataReady(event.wnd.space);
     if(event.wnd.space.anim){
        var btn=document.getElementById("ivanimate");
        if(btn)btn.style.visibility="visible";
       }
     }break;
    case "selection":ivOnSelChanged(event.node);break;
   }
});
	  

See Also

In this article