if metadata

Recommended Posts


If i want to check if a mesh has some metadata, I have to check first if it has metadata, then thing specific metadata... eg:

if (evt.pickInfo.pickedMesh.metadata) {
	if (evt.pickInfo.pickedMesh.metadata.pointType === 'source') {
		console.log('mesh as metadata: source');

Can this be condensed into just one if line?

Thank you,

Share this post

Link to post
Share on other sites

@babbleon You can implement like:

let hasOwnNestedProperty = function(obj, path) {
    for (var i = 0, path = path.split('.'), len = path.length; i < len; i++)
        obj = obj[path[i]];
        if (!obj) return false;
    return true;

if (
    hasOwnNestedProperty(evt.pickInfo.pickedMesh,'metadata.pointType') &&
    evt.pickInfo.pickedMesh.metadata.pointType === 'source'
) {
        console.log('mesh as metadata: source');


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.