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


TypeScript Mesh.add方法代码示例

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


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

示例1: makeModel

export function makeModel(avatar: Game.AvatarPub, name: string, isMe: boolean): Model {
  const root = new THREE.Group();
  root.position.x = avatar.x;
  root.position.z = avatar.z;

  const nametagCanvas = document.createElement("canvas");
  nametagCanvas.width = 256;
  nametagCanvas.height = 64;
  const nametagCtx = nametagCanvas.getContext("2d");

  const nametagTexture = new THREE.Texture(nametagCanvas, null, THREE.ClampToEdgeWrapping, THREE.ClampToEdgeWrapping, THREE.NearestFilter, THREE.LinearFilter);
  const nametag = new THREE.Mesh(nametagGeometry, new THREE.MeshBasicMaterial({ transparent: true, opacity: 0.5, map: nametagTexture }));
  nametag.position.y = 1.8;
  root.add(nametag);

  const body = new THREE.Mesh(bodyGeometry, teamMaterials[avatar.teamIndex]);
  body.rotateY(avatar.angleY);
  body.castShadow = true;
  body.receiveShadow = true;
  body.position.y = 0.7;
  root.add(body);

  const head = new THREE.Mesh(headGeometry, headMaterial);
  head.castShadow = true;
  head.receiveShadow = true;
  head.position.y = 0.5;
  body.add(head);

  const shoulders = new THREE.Group();
  // NOTE: Global Y must match up with shared.shoulderHeight
  shoulders.position.y = 0.2;
  shoulders.rotateX(avatar.angleX);
  body.add(shoulders);

  // NOTE: Arm length must match up with shared.armLength
  const leftArm = new THREE.Mesh(armGeometry, skinMaterial);
  leftArm.castShadow = true;
  leftArm.receiveShadow = true;
  leftArm.position.z = 0.3;
  shoulders.add(leftArm);

  const rightArm = new THREE.Mesh(armGeometry, skinMaterial);
  rightArm.castShadow = true;
  rightArm.receiveShadow = true;
  rightArm.position.z = -0.3;
  shoulders.add(rightArm);

  const pelvis = new THREE.Group();
  pelvis.position.y = -0.1;
  body.add(pelvis);

  const leftLeg = new THREE.Mesh(legGeometry, skinMaterial);
  leftLeg.castShadow = true;
  leftLeg.receiveShadow = true;
  leftLeg.position.z = 0.1;
  pelvis.add(leftLeg);

  const rightLeg = new THREE.Mesh(legGeometry, skinMaterial);
  rightLeg.castShadow = true;
  rightLeg.receiveShadow = true;
  rightLeg.position.z = -0.1;
  pelvis.add(rightLeg);

  const model = { root, nametag, nametagCtx, body, head, shoulders, leftArm, rightArm, leftLeg, rightLeg };
  updateNametag(model, name, isMe);

  return model;
}
开发者ID:elisee,项目名称:bball,代码行数:68,代码来源:character.ts

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