123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /*
- * @Author: Rindy
- * @Date: 2021-05-13 17:27:29
- * @LastEditors: Rindy
- * @LastEditTime: 2021-05-27 16:30:31
- * @Description: Process
- */
- import * as THREE from 'three'
- import logger from './logger.js'
- import settings from './settings.js'
- import Chunk from './Chunk.js'
- import Panorama from './Panorama.js'
- export default {
- convertProtobufToSceneObject: function ( loaddata , sceneNum ) {
- function getMesh(chunk) {
- var geometry = new THREE.BufferGeometry()
- geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(chunk.vertices.xyz, 0, 3), 3))
- chunk.vertices.uv.length > 0 && geometry.setAttribute('uv', new THREE.BufferAttribute(new Float32Array(chunk.vertices.uv, 0, 2), 2))
- geometry.setIndex(new THREE.BufferAttribute(new Uint32Array(chunk.faces.faces, 0, 1), 1))
- geometry.applyMatrix4(matrix)
- geometry.computeBoundingBox()
- var meshUrl = settings.job + settings.format
-
- return new Chunk({
- geometry: geometry,
- textureName: chunk.material_name,
- name: chunk.chunk_name,
- //meshUrl: app.resource.getViewImagesURL(meshUrl),
- meshUrl: `https://4dkk.4dage.com/scene_view_data/${sceneNum}/images/${meshUrl}?_=1`
- })
- }
- if (0 == loaddata.chunk.length) {
- logger.warn('No chunks in damfile...')
- return null
- }
- var matrix = new THREE.Matrix4()
- matrix.set(1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1)
- //var materails = {};
- return loaddata.chunk.map(getMesh)
- },
- //vision.modeldata的数据不能直接用,需要转换,方法如下:
- visionModeldata: function (loaddata) {
- var modeldata = loaddata.sweepLocations
- .map(
- function (n, i) {
- return {
- uuid: n.uuid.toUTF8().replace(/-/g, ''),
- position: {
- x: n.pose.translation.x,
- y: n.pose.translation.y,
- z: n.pose.translation.z,
- },
- quaternion: {
- x: n.pose.rotation.x,
- y: n.pose.rotation.y,
- z: n.pose.rotation.z,
- w: n.pose.rotation.w,
- },
- puck: {
- x: n.puck.x,
- y: n.puck.y,
- z: n.puck.z,
- },
- alignmentType: n.alignment_type,
- group: n.group,
- subgroup: n.subgroup,
- index: i, //add
- }
- }.bind(this)
- )
- .map(
- function (n) {
- n.position = this.convertVisionVector(n.position)
- n.quaternion = this.convertVisionQuaternion(n.quaternion)
- n.puck = this.convertVisionVector(n.puck)
- return n
- }.bind(this)
- )
- return modeldata
- },
- panos: function (modeldata, model ) {
- model.panos.extend(
- modeldata.map(
- function (modeldataitem) {
- return new Panorama(model, modeldataitem.uuid, modeldataitem )
- }.bind(this)
- ),
- 'id'
- )
- if (0 === model.panos.length) {
- logger.warn('Model has no panos, turning off inside mode')
- }
- return model.panos
- },
-
- //变换vision.modeldata里拍摄点的坐标
- convertVisionVector: function (position) {
- return new THREE.Vector3(position.x, position.z, -position.y)
- },
- //变换vision.modeldata里拍摄点的旋转角度quaternion
- convertVisionQuaternion: function (quaternion) {
- return new THREE.Quaternion(quaternion.x, quaternion.z, -quaternion.y, quaternion.w).multiply(new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), THREE.MathUtils.degToRad(90)))
- },
- //变换初始点的坐标
- convertWorkshopVector: function (position) {
- return new THREE.Vector3(-position.x, position.y, position.z)
- },
- //变换初始点的quaternion
- convertWorkshopQuaternion: function (quaternion) {
- return new THREE.Quaternion(-quaternion.x, quaternion.y, quaternion.z, -quaternion.w).multiply(new THREE.Quaternion(Math.sqrt(2) / 2, Math.sqrt(2) / 2, 0, 0))
- },
- }
|