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


TypeScript Vector3.set方法代码示例

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


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

示例1: handleTriangle

        function handleTriangle(a, b, c) {

            vA.fromArray(positions, a * 3);
            vB.fromArray(positions, b * 3);
            vC.fromArray(positions, c * 3);

            uvA.fromArray(uvs, a * 2);
            uvB.fromArray(uvs, b * 2);
            uvC.fromArray(uvs, c * 2);

            var x1 = vB.x - vA.x;
            var x2 = vC.x - vA.x;

            var y1 = vB.y - vA.y;
            var y2 = vC.y - vA.y;

            var z1 = vB.z - vA.z;
            var z2 = vC.z - vA.z;

            var s1 = uvB.x - uvA.x;
            var s2 = uvC.x - uvA.x;

            var t1 = uvB.y - uvA.y;
            var t2 = uvC.y - uvA.y;

            var r = 1.0 / (s1 * t2 - s2 * t1);

            sdir.set(
                (t2 * x1 - t1 * x2) * r,
                (t2 * y1 - t1 * y2) * r,
                (t2 * z1 - t1 * z2) * r
            );

            tdir.set(
                (s1 * x2 - s2 * x1) * r,
                (s1 * y2 - s2 * y1) * r,
                (s1 * z2 - s2 * z1) * r
            );

            tan1[a].add(sdir);
            tan1[b].add(sdir);
            tan1[c].add(sdir);

            tan2[a].add(tdir);
            tan2[b].add(tdir);
            tan2[c].add(tdir);

        }
开发者ID:jkstrawn,项目名称:lighthouse,代码行数:48,代码来源:bufferGeometryUtils.ts

示例2: calculateDirectionArray

export function getFixedCountDashData<T extends CylinderBufferData|WideLineBufferData> (data: T, segmentCount: number = 9) {

  const s = Math.floor(segmentCount / 2)
  const n = data.position1.length / 3
  const sn = s * n
  const sn3 = sn * 3
  const step = 1 / segmentCount

  const direction = calculateDirectionArray(data.position1, data.position2)
  const position1 = new Float32Array(sn3)
  const position2 = new Float32Array(sn3)

  const v = new Vector3()

  for (let i = 0; i < n; ++i) {
    const i3 = i * 3
    v.set(direction[ i3 ], direction[ i3 + 1 ], direction[ i3 + 2 ])

    const x = data.position1[ i3 ]
    const y = data.position1[ i3 + 1 ]
    const z = data.position1[ i3 + 2 ]

    for (let j = 0; j < s; ++j) {
      const j3 = s * i3 + j * 3

      const f1 = step * (j * 2 + 1)
      const f2 = step * (j * 2 + 2)

      position1[ j3 ] = x + v.x * f1
      position1[ j3 + 1 ] = y + v.y * f1
      position1[ j3 + 2 ] = z + v.z * f1

      position2[ j3 ] = x + v.x * f2
      position2[ j3 + 1 ] = y + v.y * f2
      position2[ j3 + 2 ] = z + v.z * f2
    }
  }

  const position = calculateCenterArray(position1, position2) as Float32Array
  const color = replicateArray3Entries(data.color!, s)  // TODO
  const color2 = color

  const d: any = { position, position1, position2, color, color2 }

  if ((data as any).radius) {  // TODO
    d.radius = replicateArrayEntries((data as any).radius, s)  // TODO
  }

  if (data.picking && data.picking.array) {
    data.picking.array = replicateArrayEntries(data.picking.array, s)
    d.picking = data.picking
  }
  if (data.primitiveId) {
    d.primitiveId = replicateArrayEntries(data.primitiveId, s)
  }

  return d as T
}
开发者ID:arose,项目名称:ngl,代码行数:58,代码来源:dash.ts

示例3: rotateComponent

  rotateComponent (x: number, y: number) {
    if (!this.component) return

    const [ dx, dy ] = this._getRotateXY(x, y)

    tmpRotateMatrix.extractRotation(this.component.transform)
    tmpRotateMatrix.premultiply(this.viewer.rotationGroup.matrix)
    tmpRotateMatrix.getInverse(tmpRotateMatrix)
    tmpRotateVector.set(1, 0, 0)
    tmpRotateVector.applyMatrix4(tmpRotateMatrix)
    tmpRotateXMatrix.makeRotationAxis(tmpRotateVector, dy)
    tmpRotateVector.set(0, 1, 0)
    tmpRotateVector.applyMatrix4(tmpRotateMatrix)
    tmpRotateYMatrix.makeRotationAxis(tmpRotateVector, dx)
    tmpRotateXMatrix.multiply(tmpRotateYMatrix)
    tmpRotateQuaternion.setFromRotationMatrix(tmpRotateXMatrix)
    this.component.quaternion.premultiply(tmpRotateQuaternion)
    this.component.updateMatrix()
  }
开发者ID:arose,项目名称:ngl,代码行数:19,代码来源:trackball-controls.ts

示例4: applyPositionTransform

 applyPositionTransform (matrix: Matrix4, i: number) {
   const r = this._radius[ i ]
   scale.set(r, r, r)
   matrix.scale(scale)
 }
开发者ID:arose,项目名称:ngl,代码行数:5,代码来源:spheregeometry-buffer.ts

示例5: buildUnitcellAssembly

export function buildUnitcellAssembly (structure: Structure) {
  if (!structure.unitcell) return

  if (Debug) Log.time('buildUnitcellAssembly')

  const uc = structure.unitcell

  const structureCenterFrac = structure.center.clone().applyMatrix4(uc.cartToFrac)
  const centerFrac = structureCenterFrac.clone().floor()
  const symopDict: { [K: string]: Matrix4 } = getSymmetryOperations(uc.spacegroup)

  const centerFracSymop = new Vector3()
  const positionFracSymop = new Vector3()

  function getMatrixList (shift?: Vector3) {
    const matrixList: Matrix4[] = []

    Object.keys(symopDict).forEach(function (name) {
      const m = symopDict[ name ].clone()

      centerFracSymop.copy(structureCenterFrac).applyMatrix4(m).floor()
      positionFracSymop.setFromMatrixPosition(m)
      positionFracSymop.sub(centerFracSymop)
      positionFracSymop.add(centerFrac)

      if (shift) positionFracSymop.add(shift)

      m.setPosition(positionFracSymop)
      m.multiplyMatrices(uc.fracToCart, m)
      m.multiply(uc.cartToFrac)

      matrixList.push(m)
    })

    return matrixList
  }

  const unitcellAssembly = new Assembly('UNITCELL')
  const unitcellMatrixList = getMatrixList()
  const ncsMatrixList: Matrix4[] = []
  if (structure.biomolDict.NCS) {
    ncsMatrixList.push(
      new Matrix4(), ...structure.biomolDict.NCS.partList[ 0 ].matrixList
    )
    const ncsUnitcellMatrixList: Matrix4[] = []
    unitcellMatrixList.forEach(sm => {
      ncsMatrixList.forEach(nm => {
        ncsUnitcellMatrixList.push(sm.clone().multiply(nm))
      })
    })
    unitcellAssembly.addPart(ncsUnitcellMatrixList)
  } else {
    unitcellAssembly.addPart(unitcellMatrixList)
  }

  const vec = new Vector3()
  const supercellAssembly = new Assembly('SUPERCELL')
  const supercellMatrixList = Array.prototype.concat.call(
    getMatrixList(vec.set(1, 0, 0)),  // 655
    getMatrixList(vec.set(0, 1, 0)),  // 565
    getMatrixList(vec.set(0, 0, 1)),  // 556

    getMatrixList(vec.set(-1, 0, 0)),  // 455
    getMatrixList(vec.set(0, -1, 0)),  // 545
    getMatrixList(vec.set(0, 0, -1)),  // 554

    getMatrixList(vec.set(1, 1, 0)),  // 665
    getMatrixList(vec.set(1, 0, 1)),  // 656
    getMatrixList(vec.set(0, 1, 1)),  // 566

    getMatrixList(vec.set(-1, -1, 0)),  // 445
    getMatrixList(vec.set(-1, 0, -1)),  // 454
    getMatrixList(vec.set(0, -1, -1)),  // 544

    getMatrixList(vec.set(1, -1, -1)),  // 644
    getMatrixList(vec.set(1, 1, -1)),  // 664
    getMatrixList(vec.set(1, -1, 1)),  // 646
    getMatrixList(vec.set(-1, 1, 1)),  // 466
    getMatrixList(vec.set(-1, -1, 1)),  // 446
    getMatrixList(vec.set(-1, 1, -1)),  // 464

    getMatrixList(vec.set(0, 1, -1)),  // 564
    getMatrixList(vec.set(0, -1, 1)),  // 546
    getMatrixList(vec.set(1, 0, -1)),  // 654
    getMatrixList(vec.set(-1, 0, 1)),  // 456
    getMatrixList(vec.set(1, -1, 0)),  // 645
    getMatrixList(vec.set(-1, 1, 0)),  // 465

    getMatrixList(),  // 555
    getMatrixList(vec.set(1, 1, 1)),  // 666
    getMatrixList(vec.set(-1, -1, -1))   // 444
  )
  if (structure.biomolDict.NCS) {
    const ncsSupercellMatrixList: Matrix4[] = []
    supercellMatrixList.forEach(function (sm: Matrix4) {
      ncsMatrixList.forEach(function (nm) {
        ncsSupercellMatrixList.push(sm.clone().multiply(nm))
      })
    })
    supercellAssembly.addPart(ncsSupercellMatrixList)
//.........这里部分代码省略.........
开发者ID:arose,项目名称:ngl,代码行数:101,代码来源:structure-utils.ts

示例6: _setPanVector

 private _setPanVector (x: number, y: number, z = 0) {
   const scaleFactor = this.controls.getCanvasScaleFactor(z)
   tmpPanVector.set(x, y, 0)
   tmpPanVector.multiplyScalar(this.panSpeed * scaleFactor)
 }
开发者ID:arose,项目名称:ngl,代码行数:5,代码来源:trackball-controls.ts

示例7: refresh

  /**
   * Updates atomSet, bondSet, atomSetCache, atomCount, bondCount, boundingBox, center.
   * @emits {Structure.signals.refreshed} when refreshed
   * @return {undefined}
   */
  refresh () {
    if (Debug) Log.time('StructureView.refresh')

    this.atomSetCache = {}
    const structure = this.structure

    if (this.selection.isAllSelection() &&
        structure !== this && structure.atomSet && structure.bondSet
    ) {
      this.atomSet = structure.atomSet.clone()
      this.bondSet = structure.bondSet.clone()

      for (let name in this.atomSetDict) {
        const atomSet = this.atomSetDict[ name ]
        this.atomSetCache[ '__' + name ] = atomSet.clone()
      }

      this.atomCount = structure.atomCount
      this.bondCount = structure.bondCount

      this.boundingBox.copy(structure.boundingBox)
      this.center.copy(structure.center)
    } else if (this.selection.isNoneSelection() &&
        structure !== this && structure.atomSet && structure.bondSet
    ) {
      this.atomSet = new BitArray(structure.atomCount)
      this.bondSet = new BitArray(structure.bondCount)

      for (let name in this.atomSetDict) {
        this.atomSetCache[ '__' + name ] = new BitArray(structure.atomCount)
      }

      this.atomCount = 0
      this.bondCount = 0

      this.boundingBox.makeEmpty()
      this.center.set(0, 0, 0)
    } else {
      this.atomSet = this.getAtomSet(this.selection, true)
      if (structure.atomSet) {
        this.atomSet = this.atomSet.intersection(structure.atomSet)
      }

      this.bondSet = this.getBondSet()

      for (let name in this.atomSetDict) {
        const atomSet = this.atomSetDict[ name ]
        this.atomSetCache[ '__' + name ] = atomSet.makeIntersection(this.atomSet)
      }

      this.atomCount = this.atomSet.getSize()
      this.bondCount = this.bondSet.getSize()

      this.boundingBox = this.getBoundingBox()
      this.center = this.boundingBox.getCenter(new Vector3())
    }

    if (Debug) Log.timeEnd('StructureView.refresh')

    this.signals.refreshed.dispatch()
  }
开发者ID:arose,项目名称:ngl,代码行数:66,代码来源:structure-view.ts

示例8: setAttributes

  setAttributes (data: Partial<TubeMeshBufferData> = {}) {
    const aspectRatio = this.parameters.aspectRatio

    const n = this.size2
    const n1 = n - 1
    const radialSegments = this.parameters.radialSegments

    const attributes = this.geometry.attributes as any

    let position, normal, binormal, tangent, color, size, primitiveId
    let meshPosition, meshColor, meshNormal, meshPrimitiveId

    if (data.position) {
      position = data.position
      normal = data.normal
      binormal = data.binormal
      tangent = data.tangent
      size = data.size

      meshPosition = attributes.position.array
      meshNormal = attributes.normal.array

      attributes.position.needsUpdate = true
      attributes.normal.needsUpdate = true
    }

    if (data.color) {
      color = data.color
      meshColor = attributes.color.array
      attributes.color.needsUpdate = true
    }

    if (data.primitiveId) {
      primitiveId = data.primitiveId
      meshPrimitiveId = attributes.primitiveId.array
      attributes.primitiveId.needsUpdate = true
    }

    let k, l
    let radius = 0

    let normX = 0
    let normY = 0
    let normZ = 0
    let biX = 0
    let biY = 0
    let biZ = 0
    let posX = 0
    let posY = 0
    let posZ = 0

    const cxArr = []
    const cyArr = []
    const cx1Arr = []
    const cy1Arr = []
    const cx2Arr = []
    const cy2Arr = []

    if (position) {
      for (let j = 0; j < radialSegments; ++j) {
        const v = (j / radialSegments) * 2 * Math.PI

        cxArr[ j ] = aspectRatio * Math.cos(v)
        cyArr[ j ] = Math.sin(v)

        cx1Arr[ j ] = aspectRatio * Math.cos(v - 0.01)
        cy1Arr[ j ] = Math.sin(v - 0.01)
        cx2Arr[ j ] = aspectRatio * Math.cos(v + 0.01)
        cy2Arr[ j ] = Math.sin(v + 0.01)
      }
    }

    for (let i = 0; i < n; ++i) {
      k = i * 3
      l = k * radialSegments

      if (position && tangent && normal && binormal && size) {
        vTangent.set(
          tangent[ k ], tangent[ k + 1 ], tangent[ k + 2 ]
        )

        normX = normal[ k ]
        normY = normal[ k + 1 ]
        normZ = normal[ k + 2 ]

        biX = binormal[ k ]
        biY = binormal[ k + 1 ]
        biZ = binormal[ k + 2 ]

        posX = position[ k ]
        posY = position[ k + 1 ]
        posZ = position[ k + 2 ]

        radius = size[ i ]
      }

      for (let j = 0; j < radialSegments; ++j) {
        const s = l + j * 3

        if (position) {
//.........这里部分代码省略.........
开发者ID:arose,项目名称:ngl,代码行数:101,代码来源:tubemesh-buffer.ts


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