src/staging/replace-furniture.js
function updateElementsById(sceneStructure, id, replacement) {
  var isArray = Array.isArray(sceneStructure)
  sceneStructure = isArray ? sceneStructure : [sceneStructure]

  sceneStructure = sceneStructure.map(function(element3d) {
    // furniture id is stored in src param
    if (element3d.type === 'interior' && element3d.src.substring(1) === id && replacement.furniture) {
      // apply new id
      element3d.src = '!' + replacement.furniture.id
      // compute new position for items that differ in size and mesh origin
      var newPosition = getNewPosition(element3d, replacement.offset)
      // apply new position
      element3d.x = newPosition.x
      element3d.y = newPosition.y
      element3d.z = newPosition.z
    }
    // recursivley search tree
    if (element3d.children && element3d.children.length) {
      element3d.children = updateElementsById(element3d.children, id, replacement)
    }
    return element3d
  })

  return isArray ? sceneStructure : sceneStructure[0]
}
function updateElementsById(sceneStructure, id, replacement) {
  var isArray = Array.isArray(sceneStructure)
  sceneStructure = isArray ? sceneStructure : [sceneStructure]

  sceneStructure = sceneStructure.map(function(element3d) {
    // furniture id is stored in src param
    if (element3d.type === 'interior' && element3d.src.substring(1) === id && replacement.furniture) {
      // apply new id
      element3d.src = '!' + replacement.furniture.id
      // compute new position for items that differ in size and mesh origin
      var newPosition = getNewPosition(element3d, replacement.offset)
      // apply new position
      element3d.x = newPosition.x
      element3d.y = newPosition.y
      element3d.z = newPosition.z
    }
    // recursivley search tree
    if (element3d.children && element3d.children.length) {
      element3d.children = updateElementsById(element3d.children, id, replacement)
    }
    return element3d
  })

  return isArray ? sceneStructure : sceneStructure[0]
}
function updateElementsById ( sceneStructure , id , replacement ) { var isArray = Array . isArray ( sceneStructure ) sceneStructure = isArray ? sceneStructure : [ sceneStructure ] sceneStructure = sceneStructure . map ( function ( element3d ) { // furniture id is stored in src param if ( element3d . type === 'interior' && element3d . src . substring ( 1 ) === id && replacement . furniture ) { // apply new id element3d . src = '!' + replacement . furniture . id // compute new position for items that differ in size and mesh origin var newPosition = getNewPosition ( element3d , replacement . offset ) // apply new position element3d . x = newPosition . x element3d . y = newPosition . y element3d . z = newPosition . z } // recursivley search tree if ( element3d . children && element3d . children . length ) { element3d . children = updateElementsById ( element3d . children , id , replacement ) } return element3d } ) return isArray ? sceneStructure : sceneStructure [ 0 ] }
search by furniture id and replace params
search by furniture id and replace params