How to use the troika-core.utils.assign function in troika-core

To help you get started, we’ve selected a few troika-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github protectwise / troika / packages / troika-3d-ui / src / facade / UIBlock3DFacade.js View on Github external
}
    }
    return hits && hits.length ? hits : null
  }


  destructor() {
    this.layers.destructor()
    super.destructor()
  }
}

// Extend as FlexNode
const UIBlock3DFacade$FlexNode = UIBlock3DFacade = extendAsFlexNode(UIBlock3DFacade)

utils.assign(UIBlock3DFacade.prototype, {
  font: 'inherit',
  fontSize: 'inherit',
  lineHeight: 'inherit',
  letterSpacing: 'inherit',
  whiteSpace: 'inherit',
  overflowWrap: 'inherit',
  color: 'inherit'
})



function wheelHandler(e) {
  if (!e._didScroll) {
    const facade = e.currentTarget
    let {deltaX, deltaY, deltaMode} = e.nativeEvent
    let deltaMultiplier
github protectwise / troika / packages / troika-xr / src / facade / XRInputSourceFacade.js View on Github external
this.isXRInputSource = true

    // Required props
    this.xrInputSource = null
    this.xrSession = null
    this.xrReferenceSpace = null

    // Current frame state data, passed to all children:
    this.targetRayPose = null
    this.gripPose = null
    this.rayIntersection = null

    // Child object configs:
    this.cursor = utils.assign(DEFAULT_CURSOR)
    this.targetRay = utils.assign(DEFAULT_TARGET_RAY)
    this.grip = utils.assign(DEFAULT_GRIP)

    // Pointing - true for all inputs by default
    this.isPointing = true

    this.children = [
      null, //cursor
      null, //targetRay
      null //grip
    ]

    this._ray = new Ray()

    this._onSessionEvent = this._onSessionEvent.bind(this)
    this._onSceneRayEvent = this._onSceneRayEvent.bind(this)
    this.addEventListener('xrframe', this._onXrFrame.bind(this))
github protectwise / troika / packages / troika-3d / src / facade / WorldTextureProvider.js View on Github external
this.worldTexture.image = canvas

          innerWorld = this._worldFacade = new newWorldConfig.facade(canvas)

          // Trigger texture update whenever the inner world is rerendered
          innerWorld.onAfterRender = () => {
            this.worldTexture.needsUpdate = true
            this.notifyWorld('needsRender')
          }
        }
      }

      // Update the inner world
      if (innerWorld) {
        innerWorld.renderingScheduler = this._getOuterWorld().renderingScheduler
        utils.assign(innerWorld, newWorldConfig)
        innerWorld.afterUpdate()
      }

      super.afterUpdate()
    }
github protectwise / troika / packages / troika-2d / src / facade / Text2DFacade.js View on Github external
import { utils } from 'troika-core'
import Object2DFacade from './Object2DFacade'

class Text2DFacade extends Object2DFacade {
  render(context) {
    context.font = `${ this.fontStyle } ${ this.fontWeight } ${ this.fontStretch } ${ this.fontSize } ${ this.fontFamily }`
    context.textAlign = this.textAlign
    context.textBaseline = this.textBaseline
    context.fillStyle = this.color
    context.globalAlpha = this.opacity
    context.fillText(this.text, 0, 0)
  }
}

// Defaults
utils.assign(Text2DFacade.prototype, {
  color: '#fff',
  fontFamily: 'sans-serif',
  fontSize: '12px',
  fontStretch: '',
  fontStyle: '',
  fontWeight: '',
  textAlign: 'start',
  textBaseline: 'alphabetic',
  text: '',
  opacity: 1
})

export default Text2DFacade
github protectwise / troika / packages / troika-examples / troika-dat-gui / DatGuiFacade.js View on Github external
children: (this.items || []).map((item, i) => {
          if (!item) return null
          const facade = item && TYPE_FACADES[item.type]
          return facade ?
            utils.assign({
              key: item.path || i,
              facade,
              height: item.height || this.itemHeight,
              margin: [i ? 0 : 0.02, 0, 0.02],
              value: objectPath.get(this.data, item.path),
              onUpdate: this._onItemUpdate.bind(this, item.path)
            }, item) :
            {
              facade: UIBlock3DFacade,
              text: `Unknown Type: ${item.type}`
            }
        })
      }
github protectwise / troika / packages / troika-3d / src / facade / Scene3DFacade.js View on Github external
let lights = this.lights.map((def, i) => {
        let realDef = utils.assign({}, def)
        delete realDef.type
        realDef.key = `$$$light_${ i }`
        realDef.facade = realDef.facade || LIGHT_TYPES[def.type]
        return realDef.facade ? realDef : null
      })
      children = lights.concat(children)
github protectwise / troika / packages / troika-xr / src / webvr-deprecated / react / VrAware.jsx View on Github external
const vrEvents = ['vrdisplayconnect', 'vrdisplaydisconnect', 'vrdisplaypresentchange']

const vrCanvasStyles = {
  both: {
    position: 'absolute',
    height: '100%',
    width: 'auto', //adjusts per aspect ratio to match full height
    left: '50%',
    transform: 'translate(-50%)'
  }
}
vrCanvasStyles.left = utils.assign({}, vrCanvasStyles.both, {
  transform: 'translate(-25%)',
  clipPath: `inset(0 50% 0 0)`
})
vrCanvasStyles.right = utils.assign({}, vrCanvasStyles.both, {
  transform: 'translate(-75%)',
  clipPath: `inset(0 0 0 50%)`
})


/**
 * Wraps a React component with the ability to manage/launch WebVR sessions. The wrapped
 * component will be passed
 *
 * @param {class|function} BaseReactComponent - the React component to wrap
 * @param {Object} [options]
 *   @param {class|function} [options.buttonRenderer] - a custom React component to render
 *          the button for launching a VR session. Defaults to a builtin component.
 *   @param {boolean|function(VRDisplay):boolean|null} [options.highRefreshRate] - for browsers
 *          that support it (e.g. Oculus browser), opts in to a higher refresh rate when in VR.
 *          Defaults to true for Oculus Quest and the browser's default value otherwise.
github protectwise / troika / packages / troika-3d / src / react / Canvas3D.jsx View on Github external
render() {
    const {props, context} = this
    return React.createElement(
      ReactCanvasBase,
      utils.assign({}, props, {
        onCanvasRef: this._onCanvasRef,
        canvasStyle: props.canvasStyle || context.canvasStyle,
        worldFacade: props.worldFacade || context.worldFacade || World3DFacade,
        worldProps: utils.assign(
          {
            antialias: props.antialias,
            rendererClass: props.rendererClass,
            backgroundColor: props.backgroundColor,
            shadows: props.shadows,
            camera: props.camera,
            lights: props.lights,
            objects: props.objects,
            fog: props.fog,
            onBackgroundClick: props.onBackgroundClick
          },
          context.worldProps,
          props.worldProps
        )
      }),
      props.children
github protectwise / troika / packages / troika-xr / src / webvr-deprecated / react / VrAware.jsx View on Github external
export function makeVrAware(BaseReactComponent, options) {
  options = utils.assign({
    buttonRenderer: VrButton,
    highRefreshRate: null, //vrDisplay => vrDisplay.displayName === 'Oculus Quest',
    foveationLevel: null,
    screenViewEye: 'both' //or 'right' or 'both' - TODO should this be a dynamic prop instead of a static config?
  }, options)

  class VrAware extends React.Component {
    constructor(props) {
      super(props)

      this.state = {
        vrAvailable: false,
        vrDisplay: null
      }

      this._onVrButtonClick = this._onVrButtonClick.bind(this)
github protectwise / troika / packages / troika-xr / src / facade / GripFacade.js View on Github external
function findModelConfig(xrInputSource) {
  for (let i = 0; i < PROFILE_MODELS.length; i++) {
    if (PROFILE_MODELS[i].match(xrInputSource)) {
      const result = utils.assign({}, PROFILE_MODELS[i])
      delete result.match
      return result
    }
  }
}