Catalog npm
Back to packageRELEASE DETAILS

1.0.24

npm

3dtiles-tool

高效易用的3DTiles工具库,各种功能持续更新中

3dtileslodthree.js
Published7 Mar 2022
Direct dependencies5
Transitive dependenciesNot calculated

README

Current package documentation

3dtiles-tool

3DTiles Generate Tool

3DTiles规范包括了诸如GLTF、B3DM、PNTS、JSON等多种类型的文件,本工具库主要是为生成、组装及处理这些文件提供便利。当前,仅支持从Three.js对象导出GLB及生成B3DM文件两大功能,后续还将不断完善。

Usage

1.首先,根据Three.js对象生成GLB文件,其中batchId数组需要依据业务需求填充相应值,具体请参考3DTiles规范文档。

import { GLTransmissionFormat } from "3dtiles-tool"
import * as THREE from "three"

const blockFaceAttribute = {
  batchId: new Uint16Array(visibleTriangleFaceCount * 3),
  position: new Float64Array(visibleTriangleFaceCount * 9),
  normal: new Float64Array(visibleTriangleFaceCount * 9),
  color: new Float32Array(visibleTriangleFaceCount * 12),
}

const blockFaceGeometry = new THREE.BufferGeometry()
blockFaceGeometry.setAttribute('position', new THREE.Float32BufferAttribute(blockFaceAttribute.position, 3))
blockFaceGeometry.setAttribute('color', new THREE.Float32BufferAttribute(blockFaceAttribute.color, 4))
blockFaceGeometry.setAttribute('normal', new THREE.Float32BufferAttribute(blockFaceAttribute.normal, 3))
blockFaceGeometry.setAttribute('batchId', new THREE.Uint16BufferAttribute(blockFaceAttribute.batchId, 1))

const blockFaceMesh = new THREE.Mesh(blockFaceGeometry, new THREE.MeshPhongMaterial({
  vertexColors: THREE.FaceColors,
  flatShading: true,
}))

const gltf = new GLTransmissionFormat().fromTHREE(blockFaceMesh)

2.接着,根据业务需求制作batchTable和featureTable对象。若业务上对此无需求,也可不构造相应的table对象,并在下一步中省略为b3dm对象赋该值。当为batchTable对象添加属性时,它将根据batchLength值和传入的typedArray类型及长度自动生成对应的JSON Header。当为featureTable对象添加属性时,属性的key值必须为3DTiles规范内合法的key值,这将由常量B3DM_GLOBAL_PROPERTY所记载,超出该常量范围的key值将导致报错。另外,BATCH_LENGTH这种特殊的featureTable属性可由Batched3DModel对象根据GLB推导得出,可省略设置。

import { BatchTableMap, FeatureTableMap, B3DM_GLOBAL_PROPERTY } from "3dtiles-tool"

const batchLength = 100
const batchTableMap = new BatchTableMap()
batchTableMap.set("verticeIndex", new Uint16Array(batchLength))
batchTableMap.set("cellIndex", new Uint16Array(3 * batchLength))

const featureTableMap = new FeatureTableMap()
featureTableMap.set(B3DM_GLOBAL_PROPERTY.RTC_CENTER, new Float32Array([1, 2, 3]))

3.最后,构造Batched3DModel对象并设置相应属性后,调用export()方法即可将以上三者拼接成B3DM文件。该方法返回值为ArrayBuffer对象,可直接作为二进制数据流存入数据库或写入文件。

import { Batched3DModel } from "3dtiles-tool"

const b3dm = new Batched3DModel()
b3dm.gltf = gltf
b3dm.batchTableMap = batchTableMap
b3dm.featureTableMap = featureTableMap

const b3dmBuffer = await b3dm.export()

3.1如果需要单独导出glTF或binary glTF文件,也可通过调用gltf的export()方法实现,可以向该方法中传入options对象,其参数设置请参考three.js的GLTFExporter对象的使用说明。

const options = {
  binary: true, // 导出glb
  animations: animations,  // 导出动画
}
const glbBuffer = await gltf.export(options)

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 5

Native requirements
5 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
three
Environment
{
  "local_name": "three",
  "alias": false,
  "peer_metadata": null
}
^0.128.0runtime
@babel/core
Environment
{
  "local_name": "@babel/core",
  "alias": false,
  "peer_metadata": null
}
^7.14.3development
@babel/plugin-proposal-class-properties
Environment
{
  "local_name": "@babel/plugin-proposal-class-properties",
  "alias": false,
  "peer_metadata": null
}
^7.13.0development
@babel/preset-env
Environment
{
  "local_name": "@babel/preset-env",
  "alias": false,
  "peer_metadata": null
}
^7.14.2development
@rollup/plugin-babel
Environment
{
  "local_name": "@rollup/plugin-babel",
  "alias": false,
  "peer_metadata": null
}
^5.3.0development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-VYeBSYeQPMoFG41J/ONCVDfEEC6PK/cKvWOjj8eQd4nuFAfvoSkya0hIFZ/yVz+txtQ6XkHLDRAE9aTZUI0kPQ==",
  "shasum": "9063e98ef3cb1b8772599d9466636968bf7cb6f4",
  "tarball": "https://registry.npmjs.org/3dtiles-tool/-/3dtiles-tool-1.0.24.tgz",
  "fileCount": 15,
  "unpackedSize": 149845,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiJezkACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrrpQ//RvLvsCG7j0pyot+CcoRcTavmYg/WnjG9tXPugMNrDp7h1LBY\r\nrbe7jpQP+ZIQPYnyJqYW7xZixMkYWJ33IjqfDtSPZdNKR1MHfrs7DxTb0h7q\r\nOpw5sBW0H1HaDC1uMhyRsen5ht5z0r+gohB7Zk6PIh1yICQwh+iXgkU8DadG\r\neBL7vpEYJt2PcRehycm+SDVGrcmVYhALr1OIfCceY15Af9Ceu4ZhX4gD+6fc\r\njYPGIckG0FWUbLTGb7Qx9cVaRW5YxJatAArrlXN5xZJgP5nA4yACSH151Cvl\r\ncI7/3DmCbrRt+uczcgfhUnAmlsXqTQw9vt9xCFvAzjm6roSy4E7FtWduGcsi\r\nhGqukGJsPSo7lZDw80xyXfOCYTZJgcQUgwFKirDZSCH6pa8rMzjtZ6m1U57D\r\nzTQS8eAxqQlj0BO5xjb2zpe8YO/V3N50AkeAiPPzEsq8YYjLUKzOxPXp/15Y\r\n3LoGm+z+ZgfbmUsaf2KojVPIlcYtcjNZqxqsXvols9J+noaMIwSp/rus7qQV\r\nGol/pruatjVflPDOIHMNHF6WsNS9YWtslErQKn4/zG+o6vbnSX5rFgb+8T31\r\n6KFSR4LvnpNeUBMZqHpXBKUig54xiBmjFrkaUFgH0F/TndcnRaX8Qcj7LpGu\r\nLt3toB8co29u6mdnD4dRVrGffwcg5r6O+mA=\r\n=YmpJ\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEQCIDOYjvcmn5wOfKLnf2ZDkf1b+1KyktFIe/9F6Or4BxH5AiArkr+yFT7qxcJ1khPvYwqefpMJPcmFyMynXBtyb+tiLQ=="
    }
  ]
}

Repository

PENDING
tnmoon/3dtiles-tool

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:41 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:f2b4b213cfe2832c4748ca7ed6daf7c8352eda816a976ecb4d1ca7aa08e4e06e

Other collected versions

1.0.2314 Feb1.0.227 Jan1.0.2126 Oct1.0.2024 Aug1.0.1920 Aug1.0.1820 AugView all collected versions →