当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript PerspectiveCamera.add方法代码示例

本文整理汇总了TypeScript中THREE.PerspectiveCamera.add方法的典型用法代码示例。如果您正苦于以下问题:TypeScript PerspectiveCamera.add方法的具体用法?TypeScript PerspectiveCamera.add怎么用?TypeScript PerspectiveCamera.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在THREE.PerspectiveCamera的用法示例。


在下文中一共展示了PerspectiveCamera.add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: init

function init() : void {
  scene = new THREE.Scene()
  camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 10 )
  scene.add(camera)
  const crosshair = new THREE.Mesh(
    new THREE.RingGeometry( 0.02, 0.04, 32 ),
    new THREE.MeshBasicMaterial( {
      color: 0xffffff,
      opacity: 0.5,
      transparent: true
    } )
  )
  crosshair.position.z = - 2
  camera.add(crosshair)
  room = new THREE.Mesh(
    new THREE.BoxGeometry(6, 6, 6, 10, 10, 10),
    new THREE.MeshBasicMaterial({ color: 0x202020, wireframe: true })
  )

  scene.add(room)
  scene.add(new THREE.HemisphereLight(0x404020, 0x202040, 0.5))

  const light = new THREE.DirectionalLight(0xffffff)
  light.position.set(1, 1, 1).normalize()
  scene.add(light)

  const geometry = new THREE.BoxGeometry( 0.15, 0.15, 0.15 )
  for(let i = 0; i < 200; i++) {
    const object = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) )
    object.position.x = Math.random() * 4 - 2
    object.position.y = Math.random() * 4 - 2
    object.position.z = Math.random() * 4 - 2
    object.rotation.x = Math.random() * 2 * Math.PI
    object.rotation.y = Math.random() * 2 * Math.PI
    object.rotation.z = Math.random() * 2 * Math.PI
    object.scale.x = Math.random() + 0.5
    object.scale.y = Math.random() + 0.5
    object.scale.z = Math.random() + 0.5
    object.userData.velocity = new THREE.Vector3()
    object.userData.velocity.x = Math.random() * 0.01 - 0.005
    object.userData.velocity.y = Math.random() * 0.01 - 0.005
    object.userData.velocity.z = Math.random() * 0.01 - 0.005
    room.add( object )
  }
  raycaster = new THREE.Raycaster()


  // renderer = new THREE.WebGLRenderer({ antialias: true })
  // renderer.setClearColor(0x101010)
  // renderer.setPixelRatio(window.devicePixelRatio)
  // renderer.setSize(window.innerWidth, window.innerHeight)
  // renderer.sortObjects = false

  renderer2 = new CSS3DRenderer()
  renderer2.setSize(window.innerWidth, window.innerHeight)
  renderer2.domElement.style.position = 'absolute'
  renderer2.domElement.style.top = '0'

  const container = document.createElement('div')
  document.body.appendChild(container)
  // container.appendChild(renderer.domElement)
  container.appendChild(renderer2.domElement)

  controls = new VRControls(camera, e => console.error(e))
  // effect = new VREffect(renderer, (err : string) => console.error('VREffect: ' + err) )
  effect2 = new CSS3DVREffect(renderer2, (err : string) => console.error('CSS3DVREffect: ' + err))


  // CSS Object
  const element = document.createElement('div')
  element.innerHTML = 'Plain text inside a div.'
  element.className = 'three-div'
  
  const div = new CSSObject3D(element)
  div.position.x = 0
  div.position.y = 0
  div.position.z = -185
  div.rotation.y = 0
  // div.rotation.y = Math.PI
  scene.add(div)

  if(WebVR.isAvailable()) {
    // document.body.appendChild(WebVR.getButton(effect))
    document.body.appendChild(WebVR.getButton(effect2))
  }
  // renderer.domElement.addEventListener('mousedown', onMouseDown, false)
  // renderer.domElement.addEventListener('mouseup', onMouseUp, false)
  // renderer.domElement.addEventListener('touchstart', onMouseDown, false)
  // renderer.domElement.addEventListener('touchend', onMouseUp, false)

  renderer2.domElement.addEventListener('mousedown', onMouseDown, false)
  renderer2.domElement.addEventListener('mouseup', onMouseUp, false)
  renderer2.domElement.addEventListener('touchstart', onMouseDown, false)
  renderer2.domElement.addEventListener('touchend', onMouseUp, false)

  window.addEventListener('resize', onWindowResize, false)
}
开发者ID:lostfictions,项目名称:cuberpunk-vr,代码行数:97,代码来源:index.ts


注:本文中的THREE.PerspectiveCamera.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。