Human Viewer API

scene

The scene is the collection of 3D objects currently being rendered. Scene messages allow you to control what scenes are loaded, how they're rendered and to gather information about what's currently in the scene.

Messages

scene.capture

Captures the current scene state

Usage

human.send( 'scene.capture' , callback)

Parameters:

Name callback
Type scene.SceneCaptureCallback

Example

Scene capture and restore

Launch Example
var sceneState;

// Initialize API
var human = new HumanAPI("embeddedHuman");

human.on("human.ready", function() {

    console.log("Highlighting objects");

    human.send("scene.selectObjects", {
        "maleAdult_standard-Right_Craniofacial_Bones_ID": true
    });

    console.log("Setting camera");

    human.send("camera.set", {
        position: {
            x: 20,
            y: 40,
            z: 0
        }
    }, function() {
        console.log("Capturing scene state");

        // Capturing the scene state provides a JavaScript object
        // containing the data necessary to recreate the scene.
        // This object can be passed to "scene.restore" to re-create
        // the scene.
        human.send("scene.capture",
            function (scene) {
                sceneState = scene;
            });

        console.log("Resetting scene in 2s")
        setTimeout(function() {
            human.send("scene.reset");

            console.log("Restoring scene state in 2s");
            setTimeout(function() {

                // Here, we pass the scene state object that
                // was captured by "scene.capture" to "scene.restore"
                // so it can restore the scene to the captured state.
                human.send("scene.restore", sceneState);

            }, 2000);
        }, 2000);
    });

});

// Fired whenever scene is restored to a captured state
human.on("scene.restored", function() {
    console.log("Scene restored!");
});

scene.colorObject

Modify object colors

Usage

human.send( 'scene.colorObject' , params)

Parameters:

Name params
Type object
Properties
Name Type Required Description
objectId string Y ID of object to color
tintColor array N RGB triplet to tint the object with. RGB values can be between 0 and 1
saturation number N Saturation of object colors. Values between -1 and 1.
brightness number N Brightness of object colors. Values between -1 and 1.
contrast number N Contrast of object colors. Values between -1 and 1.
opacity number N Opacity of object colors. Values between 0 and 1.

Example

Color Object

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

human.send("scene.colorObject", {
    objectId: "maleAdult_standard-Frontal_bone_52734_ID",
    tintColor: [1, 0, 0],
    brightness: 0.1,
    saturation: -0.5,
    contrast: 0.5,
    opacity: 1.0
});

scene.colorObjects

Modify colors on multiple objects

Usage

human.send( 'scene.colorObjects' , params)

Parameters:

Name params
Type object
Description Map of object IDs to paint recipes
Properties
Name Type Required Description Properties
<OBJECT_ID> object N Paint recipe
Name Type Required Description
tintColor array N RGB triplet to tint the object with. RGB values can be between 0 and 1
saturation number N Saturation of object colors. Values between -1 and 1.
brightness number N Brightness of object colors. Values between -1 and 1.
contrast number N Contrast of object colors. Values between -1 and 1.
opacity number N Opacity of object colors. Values between 0 and 1.

Example

Color Objects

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

human.send("scene.colorObjects", {
    "maleAdult_standard-Frontal_bone_52734_ID": {
        tintColor: [1, 0, 0],
        saturation: -0.5,
    },
    "bd_brain-right_superior_frontal_gyrus_ID": {
        tintColor: [0, 1, 0],
        brightness: 0.1,
    }
});

scene.disableHighlight

Disables highlight mode

Usage

human.send( 'scene.disableHighlight' , callbackopt)

Parameters:

Name callback (optional)
Type function

scene.disableXray

Disable xray mode (see scene.enableXray)

Usage

human.send( 'scene.disableXray' , callbackopt)

Parameters:

Name callback (optional)
Type function

Fires:

scene.xrayDisabled

scene.enableHighlight

Enables highlight mode

Usage

human.send( 'scene.enableHighlight' , callbackopt)

Parameters:

Name callback (optional)
Type function

scene.enableXray

Enable xray mode (make all unselected objects transparent)

Usage

human.send( 'scene.enableXray' , callbackopt)

Parameters:

Name callback (optional)
Type function

Fires:

scene.xrayEnabled

scene.getColor

Gets the object's color properties

Usage

human.send( 'scene.getColor' , callback)

Parameters:

Name callback
Type scene.ColorInfoCallback

Example

Get object color

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

human.send("scene.getColor", function (data) {
    console.log(JSON.stringify(data));
});

scene.getHighlightColor

Gets the current highlight color for selected objects.

Usage

human.send( 'scene.getHighlightColor' , callback)

Parameters:

Name callback
Type scene.HighlightColorInfoCallback

Example

Get highlight color

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

human.send("scene.getHighlightColor", function (data) {
console.log(JSON.stringify(data));
});

scene.getLayers

Gather the current anatomy slider layers

Usage

human.send( 'scene.getLayers' , callback)

Parameters:

Name callback
Type scene.SceneSliderLayersCallback

Example

Get Anatomy Slider Layers

Launch Example

    // Initialize API
    var human = new HumanAPI("embeddedHuman");
    
    human.send("scene.getLayers", function (layers) {
        console.log(layers);
    });

scene.info

Gather information about the objects in the scene

Usage

human.send( 'scene.info' , callback)

Parameters:

Name objectId (optional)
Type string
Description The (optional) object id of a single object to retrieve additional metadata (i.e., description).
Name callback
Type scene.SceneInfoCallback

Example

Scene info

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

human.send("scene.info", function (data) {
    console.log(JSON.stringify(data));
});

scene.load

Load new content into the scene. This can be either a module (core content created by BioDigital), or bookmark

Usage

HumanAPI.call( 'scene.load' , idopt, callback)

Parameters:

Name id (optional)
Type string
Description ID of the module or bookmark to load
Name callback
Type scene.PickInfoCallback

Fires:

scene.picked

Example

Load a scene programmatically

Launch Example
var sceneState;

// Initialize API
var human = new HumanAPI("embeddedHuman");

var sceneIds = ["production/maleAdult/heart.json", "production/maleAdult/artery.json", "1FAM", "1FAQ"];
var i = 0;

console.log("Loading scenes programmatically");

(function loadScene() {
    console.log("Loading scene ID: " + sceneIds[i]);

    human.send("scene.load", sceneIds[i], function() {
        i = (i + 1) % sceneIds.length;

        setTimeout(loadScene, 5000);
    });
})();

scene.metadata

Gather information about the current scene and chapters, including titles, descriptions and animation details.

Usage

human.send( 'scene.metadata' , callback)

Parameters:

Name callback
Type scene.SceneMetadataCallback

Example

Scene metadata

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

human.send("scene.metadata", function (data) {
    console.log("scene metadata", data);
});

scene.pick

Get info about the 3D scene at a given canvas location. Optionally, trigger actions associated with the current pick mode

Usage

human.send( 'scene.pick' , params, callback)

Parameters:

Name params
Type object
Properties
Name Type Required Default Description
x number Y Canvas X-coordinate
y number Y Canvas Y-coordinate
triggerActions booleans N false Trigger pick actions
Name callback
Type scene.PickInfoCallback

Fires:

scene.picked

Example

Programmatic picking

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

var iframe = document.getElementById("embeddedHuman");

var w = iframe.clientWidth;
var h = iframe.clientHeight;

setInterval(function () {
    var canvasX = Math.round(Math.random() * 300 - 150 + w / 2);
    var canvasY = Math.round(Math.random() * 300 - 150 + h / 2);

    console.log("Try pick at " + canvasX + ", " + canvasY);
    human.send("scene.pick", { x: canvasX, y: canvasY },
        function (hit) {
            if (hit) {
                console.log("Hit: " + JSON.stringify(hit));
            } else {
                console.log("Miss");
            }
        });
}, 2000);

scene.reset

Reset the scene to its original state

Usage

human.send( 'scene.reset' , callbackopt)

Parameters:

Name callback (optional)
Type function

Example

Scene reset

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

console.log("Setting camera")
human.send("camera.set", {
    position: {
        x: 20,
        y: 40,
        z: 0
    }
}, function() {
    console.log("Scene reset in 2s");
    setTimeout(function() {
        human.send("scene.reset");
    }, 2000);
});

scene.restore

Restores scene state from description captured by scene.capture

Usage

human.send( 'scene.restore' , sceneState, callbackopt)

Parameters:

Name sceneState
Type object
Description Scene state captured from scene.capture
Name callback (optional)
Type function

Fires:

scene.restored

scene.selectObjects

Select or deselect objects in the scene

Usage

human.send( 'scene.selectObjects' , selectionMap)

Parameters:

Name selectionMap
Type object
Description Map of object IDs or FMA IDs to true to select, false to deselect
Properties
Name Type Required Default Description
replace boolean Y false Deselect any objects not selected in the current map

Fires:

scene.objectsSelected

Example

Select object

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

var select = true;

console.log("Intermittent switching of selected objects");

(function toggleSelect() {
    human.send("scene.selectObjects", {
        "maleAdult_standard-Left_Craniofacial_Bones_ID": select,
        "maleAdult_standard-Right_Craniofacial_Bones_ID": !select
    });

    select = !select;

    setTimeout(toggleSelect, 3000);
})();

human.on("scene.objectsSelected", function(event) {
    var selected = [];
    var deselected = [];

    // Event contains a map of objects that were selected
    // or deselected by this update.
    Object.keys(event).forEach(function(objectId) {
        if (event[objectId]) {
            selected.push(objectId);
        } else {
            deselected.push(objectId);
        }
    });

    console.log("Selected objects: " + selected.join(", "));
    console.log("Deslected objects: " + deselected.join(", "));
});

scene.setHighlightColor

Set the highlight color for selected objects.

Usage

human.send( 'scene.setHighlightColor' , params)

Parameters:

Name params
Type object
Properties
Name Type Required Description
tintColor array N RGB triplet to tint the object with. RGB values can be between 0 and 1
saturation number N Saturation of object color. Values between -1 and 1.
brightness number N Brightness of object color. Values between -1 and 1.
contrast number N Contrast of object color. Values between -1 and 1.

Example

Set Highlight Color

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

human.send("scene.setHighlightColor", {
    tintColor: [1, 0, 0],
    brightness: 0.1,
    saturation: -0.5,
    contrast: 0.5,
});

scene.setLayersSliderPosition

Set the position of the anatomy layers slider.

Usage

human.send( 'scene.setLayersSliderPosition' , params)

Parameters:

Name params
Type object
Properties
Name Type Required Default Description
position number Y A fraction between 0 - 1 to set the slider.
record boolean N false Whether or not to record the new position with the application state, ie. include it in the Undo / Redo stack. Useful when implementing your own slider.

Example

Show objects

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");
                
console.log("Intermittent setting of slider position");
                
(function setPosition() {
    human.send("scene.setLayersSliderPosition", {
        position: Math.random(),
        record: true
    });

    setTimeout(setPosition, 3000);
})();

scene.showObjects

Show or hide objects in the scene

Usage

human.send( 'scene.showObjects' , selectionMap)

Parameters:

Name selectionMap
Type object
Description Map of object IDs or FMA IDs to true to show, false to hide
Properties
Name Type Required Default Description
replace boolean Y false Hide any objects not shown in the current map

Fires:

scene.objectsShown

Example

Show objects

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

var show = true;

console.log("Intermittent showing and hiding of scene objects");

(function toggleShow() {
    human.send("scene.showObjects", {
        "maleAdult_standard-Left_Craniofacial_Bones_ID": show,
        "maleAdult_standard-Right_Craniofacial_Bones_ID": !show
    });

    show = !show;

    setTimeout(toggleShow, 3000);
})();

human.on("scene.objectsShown", function(event) {
    var shown = [];
    var hidden = [];

    // Event contains a map of objects that were shown
    // or hidden by this update.
    Object.keys(event).forEach(function(objectId) {
        if (event[objectId]) {
            shown.push(objectId);
        } else {
            hidden.push(objectId);
        }
    });

    console.log("Shown objects: " + shown.join(", "));
    console.log("Hidden objects: " + hidden.join(", "));
});

scene.transformObject

Transform object to new position or orientation

Usage

human.send( 'scene.transformObject' , params)

Parameters:

Name params
Type object
Properties
Name Type Required Description Properties
objectId string Y ID of object to transform
translate object N Translation transform
Name Type Required Description
x number N Translation along x axis
y number N Translation along y axis
z number N Translation along z axis
rotate object N Rotation transform
Name Type Required Description
x number N Rotation about x axis
y number N Rotation about y axis
z number N Rotation about z axis
scale object N Scaling transform
Name Type Required Description
x number N Scaling along x axis
y number N Scaling along y axis
z number N Scaling along z axis
pivot object N 3D origin point for the defined transform
Name Type Required
x number N
y number N
z number N

Example

Transform objects

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

var t = 0;
var inc = 0.01;

console.log("Animating object position");

(function animate() {
    t += inc;

    if (t > 1) {
        t = 1;
        inc *= -1;
    }

    if (t < 0) {
        t = 0;
        inc *= -1;
    }

     human.send("scene.transformObject", {
        objectId: "maleAdult_standard-Frontal_bone_52734_ID",
        translate: {x: -8 * t, y: 2 * t, z: -8 * t},
        rotate: { y: t * 90 }
    });

    requestAnimationFrame(animate);
})();

scene.uncolorObject

Clear object colors

Usage

human.send( 'scene.uncolorObject' , params)

Parameters:

Name params
Type object
Properties
Name Type Required Description
objectId string Y ID of object to clear color

Example

Undo object coloring

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

human.send("scene.uncolorObject", {
    objectId: "maleAdult_standard-Frontal_bone_52734_ID"
});

Type Definitions

scene.ColorInfoCallback

Usage

ColorInfoCallback(tintColor, saturation, brightness, contrast, opacity)

Parameters:

Name tintColor
Type array
Description RGB triplet to tint the object with. RGB values can be between 0 and 1
Name saturation
Type number
Description Saturation of object colors. Values between -1 and 1.
Name brightness
Type number
Description Brightness of object colors. Values between -1 and 1.
Name contrast
Type number
Description Contrast of object colors. Values between -1 and 1.
Name opacity
Type number
Description Opacity of object colors. Values between 0 and 1.

scene.HighlightColorInfoCallback

Usage

HighlightColorInfoCallback(tintColor, saturation, brightness, contrast)

Parameters:

Name tintColor
Type array
Description RGB triplet to tint the object with. RGB values can be between 0 and 1
Name saturation
Type number
Description Saturation of object colors. Values between -1 and 1.
Name brightness
Type number
Description Brightness of object colors. Values between -1 and 1.
Name contrast
Type number
Description Contrast of object colors. Values between -1 and 1.

scene.PickInfoCallback

Usage

PickInfoCallback()

Properties:
Name Type Description
pick object
Properties
Name Type Description
objectId string ID of the object that was picked
mode string The mode of the pick
canvasPosition object 2D coordinates of the pick location on the canvas
Properties
Name Type Description
x number
y number
position object 3D coordinates of the pick location in the scene
Properties
Name Type Description
x number
y number
z number
normal object 3D normal coordinates of the pick location in the scene
Properties
Name Type Description
x number
y number
z number

scene.SceneCaptureCallback

Usage

SceneCaptureCallback(sceneState)

Parameters:

Name sceneState
Type object
Description Captured scene state. Can be passed to scene.restore

scene.SceneInfoCallback

Usage

SceneInfoCallback(name, objectMap)

Parameters:

Name name
Type string
Description Name of the currently loaded scene
Name objectMap
Type object
Description A map of object IDs to object info
Properties
Name Type Required Description
objectId string Y
name string Y Object name
description string Y Object description
shown boolean Y Is the object currently being shown?
selected boolean Y Is the object currently being shown?
parent string Y parent objectId
children array Y objectIds of children

scene.SceneMetadataCallback

Usage

SceneMetadataCallback(name, objectMap)

Parameters:

Name metadata
Type object
Properties
Name Type Required Description
title string Y The title of the scene
description string Y The description of the scene
chapters array Y List of chapter scene.SceneChapterMetadataCallback

scene.SceneChapterMetadataCallback

Usage

SceneChapterMetadataCallback(name, objectMap)

Parameters:

Name metadata
Type object
Properties
Name Type Required Description
id string Y The chapter ID
title string Y The chapter title
description string Y The chapter description
isAnimated boolean Y Does the chapter have animations?
loop boolean Y Does the chapter's animation loop?
duration object Y The timerange of the chapter's animation
Properties
Name Type Description
firstTime number The starting time of the chapter
lastTime number The ending time of the chapter

scene.SceneSliderLayersCallback

Usage

Array<Array<SliderLayer>>

Parameters:

Type Array<SliderLayer>
Description An array of anatomy slider layers
SliderLayer
Name Type Required Description
name string Y Slider layer name
objectIds Array<string> Y A list of anatomy object IDs

Events

scene.objectsSelected

Usage

human.on( 'scene.objectsSelected' , callback)

Properties:
Name Type Description
event object Map listing object IDs and whether they were selected or deselected

scene.objectsShown

Usage

human.on( 'scene.objectsShown' , callback)

Properties:
Name Type Description
event object Map listing object IDs and whether they were shown or hidden

scene.picked

Usage

human.on( 'scene.picked' , callback)

Properties:
Name Type Description
event object
Properties
Name Type Description
objectId string ID of the object that was picked
mode string The mode of the pick event
canvasPosition object 2D coordinates of the pick location on the canvas
Properties
Name Type Description
x number
y number
position object 3D coordinates of the pick location in the scene
Properties
Name Type Description
x number
y number
z number
normal object 3D normal coordinates of the pick location in the scene
Properties
Name Type Description
x number
y number
z number

Example

Pick event

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

console.log("Pick or hover over something!");
human.on("scene.picked",
    function (pickEvent) {
        console.log("'scene.picked' event: " + JSON.stringify(pickEvent));
});

scene.restored

Usage

human.on( 'scene.restored' , callback)

Properties:
Name Type Description
event object Scene state captured by scene.capture

scene.xrayDisabled

Usage

human.on( 'scene.xrayDisabled' , callback)

Example

Enable xray

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

var enable = true;

human.on("scene.xrayEnabled", function() {
    console.log("Xray mode enabled");
});

human.on("scene.xrayDisabled", function() {
    console.log("Xray mode disabled");
});

human.on("human.ready", toggleXray);

function toggleXray() {
    human.send(enable ? "scene.enableXray" : "scene.disableXray");

    enable = !enable;

    setTimeout(toggleXray, 3000);
}

scene.xrayEnabled

Usage

human.on( 'scene.xrayEnabled' , callback)

Example

Enable xray

Launch Example
// Initialize API
var human = new HumanAPI("embeddedHuman");

var enable = true;

human.on("scene.xrayEnabled", function() {
    console.log("Xray mode enabled");
});

human.on("scene.xrayDisabled", function() {
    console.log("Xray mode disabled");
});

human.on("human.ready", toggleXray);

function toggleXray() {
    human.send(enable ? "scene.enableXray" : "scene.disableXray");

    enable = !enable;

    setTimeout(toggleXray, 3000);
}

Documentation generated by JSDoc 3.6.3 on Tue Jul 16 2019 16:35:55 GMT-0400 (Eastern Daylight Time)