@realsee/five 5.0.0-alpha.19 → 5.0.0-alpha.191

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/README.md +18 -8
  2. package/docs/.nojekyll +1 -0
  3. package/docs/assets/highlight.css +134 -0
  4. package/docs/assets/icons.css +1043 -0
  5. package/docs/assets/main.js +52 -0
  6. package/docs/assets/search.js +1 -0
  7. package/docs/assets/style.css +1414 -0
  8. package/docs/classes/five.AnimationFrameLoop.html +15 -0
  9. package/docs/classes/five.BVH.html +10 -0
  10. package/docs/classes/five.BVHIntersect.html +1 -0
  11. package/docs/classes/five.BVHNode.html +7 -0
  12. package/docs/classes/five.BVHVector3.html +1 -0
  13. package/docs/classes/five.Camera.html +11 -0
  14. package/docs/classes/five.Clipper.html +1 -0
  15. package/docs/classes/five.Five.html +328 -0
  16. package/docs/classes/five.InternalWebGLRenderer.html +1 -0
  17. package/docs/classes/five.IntersectMesh.html +1 -0
  18. package/docs/classes/five.Model.html +91 -0
  19. package/docs/classes/five.NetworkSubscribe.html +50 -0
  20. package/docs/classes/five.PBMContainer.html +17 -0
  21. package/docs/classes/five.PBMGroup.html +19 -0
  22. package/docs/classes/five.PBMMaterial.html +29 -0
  23. package/docs/classes/five.PBMMesh.html +7 -0
  24. package/docs/classes/five.PanoCircleMesh.html +7 -0
  25. package/docs/classes/five.PanoCircleMeshCustom.html +7 -0
  26. package/docs/classes/five.PanoCircleMeshSolid.html +7 -0
  27. package/docs/classes/five.Scene.html +3 -0
  28. package/docs/classes/five.Subscribe.html +56 -0
  29. package/docs/classes/five.TextureLoader.html +1 -0
  30. package/docs/classes/five.Tile3D.html +34 -0
  31. package/docs/classes/five.Tile3DModel.html +15 -0
  32. package/docs/classes/five.TileBoundingSphere.html +1 -0
  33. package/docs/classes/five.TileCacheNode.html +1 -0
  34. package/docs/classes/five.TileCubeTextureTarget.html +1 -0
  35. package/docs/classes/five.TileCullingVolume.html +1 -0
  36. package/docs/classes/five.TileOrientedBoundingBox.html +1 -0
  37. package/docs/classes/five.TileRequestScheduler.html +16 -0
  38. package/docs/classes/five.Tileset3D.html +11 -0
  39. package/docs/classes/five.Tileset3DTraverser.html +1 -0
  40. package/docs/classes/five.TilesetCache.html +1 -0
  41. package/docs/classes/five.Work.html +32 -0
  42. package/docs/classes/five.XRButton.html +1 -0
  43. package/docs/classes/gltf_loader.DDSLoader.html +1 -0
  44. package/docs/classes/gltf_loader.DRACOLoader.html +1 -0
  45. package/docs/classes/gltf_loader.GLTFLoader.html +17 -0
  46. package/docs/classes/gltf_loader.GLTFObject.html +7 -0
  47. package/docs/classes/gltf_loader.GLTFParser.html +1 -0
  48. package/docs/classes/gltf_loader.THREEGLTFLoader.html +1 -0
  49. package/docs/classes/line.Line.html +1 -0
  50. package/docs/classes/line.LineGeometry.html +1 -0
  51. package/docs/classes/line.LineMaterial.html +1 -0
  52. package/docs/classes/line.LineSegmentsGeometry.html +1 -0
  53. package/docs/classes/line.THREE_Line2.html +1 -0
  54. package/docs/classes/line.THREE_LineSegments2.html +1 -0
  55. package/docs/classes/react.Store.html +29 -0
  56. package/docs/classes/server.BVH.html +10 -0
  57. package/docs/classes/server.BVHIntersect.html +1 -0
  58. package/docs/classes/server.BVHNode.html +7 -0
  59. package/docs/classes/server.BVHVector3.html +1 -0
  60. package/docs/classes/server.Model.html +70 -0
  61. package/docs/classes/server.PBMContainer.html +7 -0
  62. package/docs/classes/server.PBMGroup.html +9 -0
  63. package/docs/classes/server.PBMMesh.html +7 -0
  64. package/docs/classes/sticker.Sticker.html +32 -0
  65. package/docs/classes/vfx.Airflow.html +1 -0
  66. package/docs/classes/vfx.Flame.html +1 -0
  67. package/docs/classes/vfx.Particle.html +89 -0
  68. package/docs/classes/vfx.SpotLight.html +1 -0
  69. package/docs/index.html +166 -434
  70. package/docs/interfaces/five.AddableObject.html +9 -0
  71. package/docs/interfaces/five.AnimationFrame.html +1 -0
  72. package/docs/interfaces/five.CameraPose.html +1 -0
  73. package/docs/interfaces/five.ClipperParameter.html +1 -0
  74. package/docs/interfaces/five.DepthPanoramaControllerCustomInitArgs.html +28 -0
  75. package/docs/interfaces/five.EventCallback.html +400 -0
  76. package/docs/interfaces/five.FiveInitArgs.html +109 -0
  77. package/docs/interfaces/five.FloorplanControllerCustomInitArgs.html +17 -0
  78. package/docs/interfaces/five.ImageOptions.html +18 -0
  79. package/docs/interfaces/five.ImageURLMappings.html +1 -0
  80. package/docs/interfaces/five.ImageURLOptions.html +15 -0
  81. package/docs/interfaces/five.IntersectMeshInterface.html +3 -0
  82. package/docs/interfaces/five.Intersection.html +7 -0
  83. package/docs/interfaces/five.MapviewControllerCustomInitArgs.html +15 -0
  84. package/docs/interfaces/five.ModelControllerCustomInitArgs.html +20 -0
  85. package/docs/interfaces/five.ModelEventCallback.html +22 -0
  86. package/docs/interfaces/five.MotionKeyframe.html +1 -0
  87. package/docs/interfaces/five.MovePanoOptions.html +42 -0
  88. package/docs/interfaces/five.NetworkOptions.html +9 -0
  89. package/docs/interfaces/five.PBMPanoPicture.html +7 -0
  90. package/docs/interfaces/five.PBMParameters.html +29 -0
  91. package/docs/interfaces/five.PanoCircleMeshCustomOptions.html +1 -0
  92. package/docs/interfaces/five.PanoCircleMeshInterface.html +19 -0
  93. package/docs/interfaces/five.PanoCircleMeshOptions.html +1 -0
  94. package/docs/interfaces/five.PanoCircleMeshSolidOptions.html +1 -0
  95. package/docs/interfaces/five.PanoramaControllerCustomInitArgs.html +35 -0
  96. package/docs/interfaces/five.PanoramaLikeControllerCustomInitArgs.html +20 -0
  97. package/docs/interfaces/five.Pose.html +37 -0
  98. package/docs/interfaces/five.Scissor.html +14 -0
  99. package/docs/interfaces/five.State.html +21 -0
  100. package/docs/interfaces/five.SubscribeMixinType.emit.html +1 -0
  101. package/docs/interfaces/five.SubscribeMixinType.hasListener.html +1 -0
  102. package/docs/interfaces/five.SubscribeMixinType.off.html +1 -0
  103. package/docs/interfaces/five.SubscribeMixinType.on.html +1 -0
  104. package/docs/interfaces/five.SubscribeMixinType.once.html +1 -0
  105. package/docs/interfaces/five.TextureOptions.html +20 -0
  106. package/docs/interfaces/five.Tile3DModelLoaderOptions.html +3 -0
  107. package/docs/interfaces/five.TileBoundingVolume.html +19 -0
  108. package/docs/interfaces/five.TileContent.html +1 -0
  109. package/docs/interfaces/five.TileCubeNode.html +1 -0
  110. package/docs/interfaces/five.TileCubeTree.html +1 -0
  111. package/docs/interfaces/five.Tileset3dOptions.html +1 -0
  112. package/docs/interfaces/five.TilesetJSON.html +1 -0
  113. package/docs/interfaces/five.TilesetJSONNode.html +1 -0
  114. package/docs/interfaces/five.TopviewControllerCustomInitArgs.html +9 -0
  115. package/docs/interfaces/five.VRPanoramaControllerCustomInitArgs.html +31 -0
  116. package/docs/interfaces/five.WebXRSelectParams.html +1 -0
  117. package/docs/interfaces/five.WorkCubeImage.html +13 -0
  118. package/docs/interfaces/five.WorkImage.html +21 -0
  119. package/docs/interfaces/five.WorkInitial.html +13 -0
  120. package/docs/interfaces/five.WorkModel.html +11 -0
  121. package/docs/interfaces/five.WorkModelTiles.html +3 -0
  122. package/docs/interfaces/five.WorkObserver.html +27 -0
  123. package/docs/interfaces/five.WorkTile.html +1 -0
  124. package/docs/interfaces/five.WorkVideo.html +9 -0
  125. package/docs/interfaces/five.XRPanoramaControllerCustomInitArgs.html +31 -0
  126. package/docs/interfaces/gltf_loader.DDS.html +1 -0
  127. package/docs/interfaces/gltf_loader.GLTF.html +7 -0
  128. package/docs/interfaces/gltf_loader.GLTFReference.html +1 -0
  129. package/docs/interfaces/gltf_loader.THREEGLTF.html +1 -0
  130. package/docs/interfaces/react.FiveActionReactCallbacks.html +52 -0
  131. package/docs/interfaces/react.FiveInjectionTypes.html +181 -0
  132. package/docs/interfaces/react.PropTypeOfFiveFeatures.html +1 -0
  133. package/docs/interfaces/server.Intersection.html +7 -0
  134. package/docs/interfaces/server.ModelEventCallback.html +18 -0
  135. package/docs/interfaces/sticker.IntersectionLike.html +8 -0
  136. package/docs/interfaces/vfx.ParticleArgs.html +75 -0
  137. package/docs/interfaces/vfx.ParticleTweenKeyframe.html +1 -0
  138. package/docs/interfaces/vue.FiveActionVueCallbacks.html +60 -0
  139. package/docs/modules/five.SubscribeMixinType.html +1 -0
  140. package/docs/modules/five.html +479 -3002
  141. package/docs/modules/gltf_loader.html +1 -155
  142. package/docs/modules/line.html +1 -202
  143. package/docs/modules/react.html +130 -1507
  144. package/docs/modules/server.html +18 -526
  145. package/docs/modules/sticker.html +1 -151
  146. package/docs/modules/vfx.html +1 -0
  147. package/docs/modules/vue.html +115 -0
  148. package/docs/modules.html +1 -136
  149. package/exporters/staticify.js +210 -0
  150. package/five/index.d.ts +1425 -285
  151. package/five/index.js +362 -1
  152. package/gltf-loader/index.d.ts +90 -5
  153. package/gltf-loader/index.js +260 -1
  154. package/line/index.d.ts +15 -2
  155. package/line/index.js +260 -1
  156. package/package.json +12 -12
  157. package/react/index.d.ts +73 -72
  158. package/react/index.js +260 -1
  159. package/scripts/five-staticify.js +26 -0
  160. package/server/index.d.ts +221 -27
  161. package/server/index.js +357 -1
  162. package/sticker/index.d.ts +2 -1
  163. package/sticker/index.js +260 -1
  164. package/templates/quick-start/package.json +1 -1
  165. package/umd/five-gltf-loader.js +1 -2
  166. package/umd/five-line.js +1 -2
  167. package/umd/five-react.js +1 -2
  168. package/umd/five-sticker.js +1 -2
  169. package/umd/five-vfx.js +1 -0
  170. package/umd/five-vue.js +1 -0
  171. package/umd/five.js +1 -1
  172. package/umd/five.js.LICENSE.txt +58 -118
  173. package/vfx/index.d.ts +264 -0
  174. package/vfx/index.js +260 -0
  175. package/vue/index.d.ts +441 -0
  176. package/vue/index.js +260 -0
  177. package/docs/assets/css/main.css +0 -2660
  178. package/docs/assets/js/main.js +0 -248
  179. package/docs/assets/js/search.js +0 -1
  180. package/docs/classes/five.camera.html +0 -323
  181. package/docs/classes/five.five-1.html +0 -2670
  182. package/docs/classes/five.hashcubetexture.html +0 -252
  183. package/docs/classes/five.internalwebglrenderer.html +0 -212
  184. package/docs/classes/five.model.html +0 -982
  185. package/docs/classes/five.pbmgroup.html +0 -427
  186. package/docs/classes/five.pbmmaterial.html +0 -533
  187. package/docs/classes/five.pbmmesh.html +0 -254
  188. package/docs/classes/five.scene.html +0 -263
  189. package/docs/classes/five.subscribe.html +0 -569
  190. package/docs/classes/gltf_loader.gltfloader.html +0 -412
  191. package/docs/classes/gltf_loader.gltfobject.html +0 -287
  192. package/docs/classes/line.line-1.html +0 -381
  193. package/docs/classes/line.linegeometry.html +0 -524
  194. package/docs/classes/line.linematerial.html +0 -300
  195. package/docs/classes/line.linesegmentsgeometry.html +0 -471
  196. package/docs/classes/react.store.html +0 -605
  197. package/docs/classes/server.model.html +0 -823
  198. package/docs/classes/server.pbmgroup.html +0 -366
  199. package/docs/classes/server.pbmmesh.html +0 -335
  200. package/docs/classes/sticker.sticker-1.html +0 -465
  201. package/docs/interfaces/five.addableobject.html +0 -234
  202. package/docs/interfaces/five.depthpanoramacontrollercustominitargs.html +0 -420
  203. package/docs/interfaces/five.eventcallback.html +0 -2548
  204. package/docs/interfaces/five.fiveinitargs.html +0 -707
  205. package/docs/interfaces/five.floorplancontrollercustominitargs.html +0 -295
  206. package/docs/interfaces/five.imageoptions.html +0 -332
  207. package/docs/interfaces/five.intersection.html +0 -227
  208. package/docs/interfaces/five.intersectmeshinterface.html +0 -188
  209. package/docs/interfaces/five.modelcontrollercustominitargs.html +0 -366
  210. package/docs/interfaces/five.modeleventcallback.html +0 -367
  211. package/docs/interfaces/five.movepanooptions.html +0 -469
  212. package/docs/interfaces/five.panocirclemeshinterface.html +0 -361
  213. package/docs/interfaces/five.panoramacontrollercustominitargs.html +0 -464
  214. package/docs/interfaces/five.panoramalikecontrollercustominitargs.html +0 -364
  215. package/docs/interfaces/five.pbmparameters.html +0 -474
  216. package/docs/interfaces/five.pose.html +0 -270
  217. package/docs/interfaces/five.scissor.html +0 -252
  218. package/docs/interfaces/five.state.html +0 -300
  219. package/docs/interfaces/five.subscribemixintype.emit.html +0 -180
  220. package/docs/interfaces/five.subscribemixintype.haslistener.html +0 -171
  221. package/docs/interfaces/five.subscribemixintype.off.html +0 -198
  222. package/docs/interfaces/five.subscribemixintype.on.html +0 -213
  223. package/docs/interfaces/five.subscribemixintype.once.html +0 -210
  224. package/docs/interfaces/five.topviewcontrollercustominitargs.html +0 -226
  225. package/docs/interfaces/five.vrpanoramacontrollercustominitargs.html +0 -452
  226. package/docs/interfaces/gltf_loader.gltf.html +0 -304
  227. package/docs/interfaces/react.fiveactionreactcallbacks.html +0 -580
  228. package/docs/interfaces/react.fiveinjectiontypes.html +0 -1625
  229. package/docs/interfaces/react.injectfivetoprops.html +0 -280
  230. package/docs/interfaces/server.intersection.html +0 -308
  231. package/docs/interfaces/server.modeleventcallback.html +0 -409
  232. package/docs/interfaces/sticker.intersectionlike.html +0 -223
  233. package/docs/modules/five.subscribemixintype.html +0 -143
  234. package/scripts/export-five-resource/chfs.exe +0 -0
  235. package/scripts/export-five-resource/fileify.js +0 -192
  236. package/scripts/export-five-resource/format-work.js +0 -71
  237. package/scripts/export-five-resource/staticify.js +0 -327
  238. package/scripts/transcode-model/BufferGeometryUtils.js +0 -832
  239. package/scripts/transcode-model/LoaderSupport.js +0 -1545
  240. package/scripts/transcode-model/MTLLoader.js +0 -602
  241. package/scripts/transcode-model/OBJLoader2.js +0 -1470
  242. package/scripts/transcode-model/obj2pbm.js +0 -65
  243. /package/docs/assets/{images/icons.png → icons.png} +0 -0
  244. /package/docs/assets/{images/icons@2x.png → icons@2x.png} +0 -0
  245. /package/docs/assets/{images/widgets.png → widgets.png} +0 -0
  246. /package/docs/assets/{images/widgets@2x.png → widgets@2x.png} +0 -0
  247. /package/resource/{basis_transcoder.js → basis/basis_transcoder.js} +0 -0
  248. /package/resource/{basis_transcoder.wasm → basis/basis_transcoder.wasm} +0 -0
  249. /package/resource/{draco_decoder.js → gltf/draco_decoder.js} +0 -0
  250. /package/resource/{draco_decoder.wasm → gltf/draco_decoder.wasm} +0 -0
  251. /package/resource/{draco_wasm_wrapper.js → gltf/draco_wasm_wrapper.js} +0 -0
@@ -1,327 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const http = require("http");
4
- const mkdirp = require("mkdirp");
5
- const crypto = require("crypto");
6
- const formatWork = require("./format-work");
7
-
8
- const [
9
- __command__,
10
- __scriptPath__,
11
- workPath,
12
- exportPath,
13
- ] = process.argv;
14
-
15
- const work = JSON.parse(fs.readFileSync(workPath));
16
-
17
- if (!fs.existsSync(exportPath)) fs.mkdirSync(exportPath);
18
-
19
- function md5(contents) {
20
- const md5 = crypto.createHash("md5");
21
- md5.update(contents);
22
- return md5.digest("hex");
23
- }
24
-
25
- function shortPath(path) {
26
- const array = path.split("/");
27
- if (array.length < 3) return path;
28
- const start = array.shift();
29
- const end = array.pop();
30
- return [start, md5(array.join("/")), end].join("/");
31
- }
32
-
33
-
34
- function imageURL(url, options = {}) {
35
- if (typeof options.transform === "function") {
36
- return options.transform(url, options)
37
- }
38
- if (url.indexOf("//vrlab-public.ljcdn.com") >= 0) {
39
- if (/\.basis(\?|$)/.test(url) && options.basisLoaderInitialized !== true) {
40
- url = url.replace(/\.basis(\?|$)/, ".jpg$1");
41
- }
42
- if (/\.jpg$/.test(url)) {
43
- const { size, quality, format } = options;
44
- if (size || quality || format) {
45
- let suffix = "?imageMogr2";
46
- if (quality) suffix += "/quality/" + quality;
47
- if (size) suffix += "/thumbnail/" + size + "x";
48
- if (format) suffix += "/format/" + format;
49
- url = url.replace("//vrlab-public.ljcdn.com", "//vrlab-image4.ljcdn.com") + suffix;
50
- }
51
- }
52
- }
53
- return url;
54
- }
55
-
56
- function download(url, filename) {
57
- filename = path.resolve(filename);
58
- mkdirp.sync(path.dirname(filename));
59
- return new Promise(resolve => {
60
- http.get(url.replace(/^https\:/, "http:"), res => {
61
- const writeStream = fs.createWriteStream(filename);
62
- res.pipe(writeStream);
63
- res.on("end", resolve);
64
- })
65
- })
66
- }
67
-
68
- function traverse(json, callback, keyPath = "") {
69
- json = callback(json, keyPath);
70
- if (json) {
71
- if (typeof json === "array") {
72
- for (let i = 0; i < json.length; i++) {
73
- json[i] = traverse(json[i], callback, keyPath + "." + i);
74
- }
75
- } else if (typeof json === "object") {
76
- for (let i = 0, keys = Object.keys(json); i < keys.length; i++) {
77
- const key = keys[i];
78
- json[key] = traverse(json[key], callback, keyPath + "." + key);
79
- }
80
- }
81
- }
82
- return json;
83
- }
84
-
85
- const urlRegExp = /^https?:\/\/(?:[\w-]+\.)*[\w-]{1,63}(?:\.(?:\w+))(?:$|\/)/i;
86
- const fileRegExp = /\.[a-z0-9]{1,6}$/i;
87
-
88
- const htmlExample = `
89
- <!DOCTYPE html>
90
- <html lang="en">
91
- <head>
92
- <meta charset="UTF-8">
93
- <title>如视 VR SDK 调用实例</title>
94
- <meta name="viewport" content="width=device-width, initial-scale=1">
95
- <style>
96
- html, body { height: 100%; width: 100%; overflow: hidden; }
97
- * { margin: 0; padding: 0 }
98
- #app { position: fixed; top: 0; left: 0; right: 0; bottom: 0; overflow: hidden; }
99
- .buttons { position: fixed; top: 10px; left: 10px; }
100
- .buttons button { display: block; margin-top: 10px; }
101
- </style>
102
- </head>
103
- <body>
104
- <script>
105
- if (location.href.indexOf("file:") === 0) {
106
- alert("Please follow the README.md file to run the project.\n请根据README.md文件来启动项目。")
107
- }
108
- </script>
109
- <!-- 试图渲染容器 -->
110
- <div id="app"></div>
111
-
112
- <!-- 简易空间按钮 -->
113
- <div class="buttons">
114
- <!-- 点击进入相机全景模式 -->
115
- <button onclick="five.changeMode(Five.Mode.Panorama)">全景模式(Panorama)</button>
116
- <!-- 点击进入相机模型自由模式 -->
117
- <button onclick="five.changeMode(Five.Mode.Floorplan, {latitude: Math.PI / 4, longitude: Math.PI / 4})">模型自由模式(Floorplan)</button>
118
- <!-- 点击进入相机模型垂直模式 -->
119
- <button onclick="five.changeMode(Five.Mode.Topview)">模型垂直模式(Topview)</button>
120
- <!-- 点击进入相机VR眼睛模式 -->
121
- <button onclick="five.changeMode(Five.Mode.VRPanorama)">眼睛模式(VRPanorama)</button>
122
- <!-- 点击进入相机模型漫游模式 -->
123
- <button onclick="five.changeMode(Five.Mode.Model)">模型漫游模式(Model)</button>
124
- </div>
125
-
126
- <script src="./five.js"></script>
127
- <script>
128
- // Five 是 如视 VR 视图渲染库的构造函数,通过 new 关键字产生实例。
129
- // 构造函数的具体参数见文档,这边仅配置常用的几项
130
- var five = new Five({
131
- // 初始化为全景观测状态状态
132
- mode: Five.Mode.Panorama,
133
- // 初始化为摄像机位于第 0 个观测点的位置
134
- panoIndex: 0,
135
- // 初始化为摄像机水平角度为 0
136
- longitude: 0,
137
- // 初始化为摄像机俯仰角度为 0
138
- latitude: 0,
139
- // 取消初始化镜头过度动画
140
- initWithTransition: false,
141
- // 按需渲染
142
- onlyRenderIfNeeds: true,
143
- })
144
-
145
- // 将渲染视图的 canvas 添加到 DOM 中
146
- five.appendTo(document.getElementById("app"))
147
-
148
- // 如果显示区域需要变动,在变动时请调用 refresh 重置显示参数
149
- window.addEventListener("resize", function () {
150
- five.refresh()
151
- })
152
-
153
- // 获取当前 VR 的房间数据,加载进来
154
- ajax("./work.json?__random=" + Date.now(), function (error, json) {
155
- if (error) throw error
156
- // 房间数据在 work.json 中,具体数据定义请在文档中查询
157
- five.load(JSON.parse(json))
158
- })
159
-
160
- // five 可以通过 on 方法来监听生命周期及交互事件
161
- // 具体的事件类型和描述详见文档
162
- // 这里肩痛 模型加载完成的事件
163
- // 在这个事件之后,模型加载完成
164
- five.on("modelLoaded", function() {
165
- var buttons = document.getElementsByClassName("buttons")[0]
166
- // 通过 five.model.hasFloors() 方法可以获取当前房间的模型有多少楼层
167
- // 该方法请在 modelLoaded 之前之后执行
168
- var floors = five.model.hasFloors()
169
- function createButton (title, value) {
170
- var button = document.createElement("button")
171
- button.innerHTML = title
172
- button.value = value
173
- button.onclick = function buttonClick (event) {
174
- var floor = JSON.parse(this.value)
175
- // 通过 five.model.show 方法可以只显示某一层的模型
176
- if (floor === null) five.model.show()
177
- else five.model.show(floor)
178
- }
179
- return button
180
- }
181
- buttons.appendChild(createButton("全部楼层", "null"))
182
- for (var index = 0; index < floors; index++) {
183
- buttons.appendChild(createButton("第" + index + "层", String(index)))
184
- }
185
- })
186
-
187
- // === 帮助函数 ===
188
-
189
- /**
190
- * 通过 xhr 异步获取数据
191
- * @param {String} url 请求数据的地址
192
- * @param {Function} callback 数据返回的回掉函数
193
- *
194
- * callback (error, responseText)
195
- * @param {Error|Null} error 如果请求失败返回 error, 如果成功则为 null
196
- * @param {String|Undefined} responseText 如果成功, 返回异步获取的数据的字符串
197
- */
198
- function ajax (url, callback) {
199
- var xhr = new XMLHttpRequest()
200
- xhr.onreadystatechange = function () {
201
- if (xhr.readyState !== 4) return
202
- if (xhr.status === 200 || xhr.status === 0) {
203
- if (callback) callback(null, xhr.response)
204
- } else {
205
- if (callback) callback(new Error("status:" + xhr.status))
206
- }
207
- }
208
- xhr.open("GET", url, true)
209
- xhr.send(null)
210
- }
211
- </script>
212
- </body>
213
- </html>
214
- `;
215
-
216
- const pyServer = `
217
- import webbrowser
218
- import posixpath
219
- import urllib
220
- import os
221
- from datetime import datetime
222
- from SimpleHTTPServer import SimpleHTTPRequestHandler
223
- from BaseHTTPServer import HTTPServer
224
-
225
- class RootedHTTPServer(HTTPServer):
226
- def __init__(self, base_path, *args, **kwargs):
227
- HTTPServer.__init__(self, *args, **kwargs)
228
- self.RequestHandlerClass.base_path = base_path
229
-
230
- class RootedHTTPRequestHandler(SimpleHTTPRequestHandler):
231
- def translate_path(self, path):
232
- path = posixpath.normpath(urllib.unquote(path)).split("?")[0]
233
- words = path.split("/")
234
- words = filter(None, words)
235
- path = self.base_path
236
- for word in words:
237
- drive, word = os.path.splitdrive(word)
238
- head, word = os.path.split(word)
239
- if word in (os.curdir, os.pardir):
240
- continue
241
- path = os.path.join(path, word)
242
- return path
243
-
244
- def server(HandlerClass=RootedHTTPRequestHandler, ServerClass=RootedHTTPServer):
245
- server_address = ("127.0.0.1", 8080)
246
- print os.path.dirname(os.path.abspath(__file__))
247
- httpd = ServerClass(os.path.dirname(os.path.abspath(__file__)), server_address, HandlerClass)
248
- sa = httpd.socket.getsockname()
249
- print "Serving HTTP on http://127.0.0.1:8080 ..."
250
- webbrowser.open("http://127.0.0.1:8080/?__random=" + datetime.now().strftime("%s"), new=2)
251
- httpd.serve_forever()
252
-
253
- if __name__ == "__main__":
254
- server()
255
- `;
256
-
257
- const readme = `
258
- # How to run a project
259
-
260
- Windows:
261
- 1. run chfs.exe
262
- 2. open \`http://127.0.0.1\`.
263
-
264
- MacOS & Linux:
265
- 1. make sure you have *Python* on your computer already.
266
- 2. run \`python server.py\`.
267
- 3. if broswer is not open automatically, open \`http://127.0.0.1:8080\`.
268
-
269
- # 如何使用
270
-
271
- Windows:
272
- 1. 运行 chfs.exe
273
- 2. 打开浏览器访问 \`http://127.0.0.1\`.
274
-
275
- MacOS & Linux:
276
- 1. 确保你已经安装了 *Python*;
277
- 2. 运行 \`python server.py\`;
278
- 3. 如果你的浏览器没有自动打开,那么请自行访问 \`http://127.0.0.1:8080\`。
279
- `
280
-
281
- let downloadQueue = Promise.resolve()
282
-
283
- function main(work, exportPath) {
284
-
285
- // 生成输出目录
286
- mkdirp(path.resolve(exportPath));
287
-
288
- // 修改work
289
- traverse(work, (value, keyPath) => {
290
- if (typeof value === "string" && urlRegExp.test(value) && fileRegExp.test(value)) {
291
- const relativeValue = value.replace(urlRegExp, match => "downloads/" + md5(match) + "/");
292
- const filename = shortPath(path.resolve(exportPath, relativeValue));
293
- downloadQueue = downloadQueue.then(() => {
294
- if (keyPath.indexOf("model.material_textures") >= 0) {
295
- value = imageURL(value, { size: 512 });
296
- }
297
- return download(value, filename)
298
- .then(() => console.log(`success ${value} => ${filename}`))
299
- .catch(() => console.log(`error ${value} => ${filename}`));
300
- })
301
- return relativeValue;
302
- }
303
- return value;
304
- })
305
-
306
- work.base_url = "./";
307
-
308
- // 输出 work.json
309
- fs.writeFileSync(path.resolve(exportPath, "work.json"), JSON.stringify(work, "", " "), "utf-8");
310
-
311
- // 输出 html
312
- fs.writeFileSync(path.resolve(exportPath, "index.html"), htmlExample, "utf-8");
313
-
314
- // 输出 readme
315
- fs.writeFileSync(path.resolve(exportPath, "README.md"), readme, "utf-8");
316
-
317
- // copy five.js
318
- fs.copyFileSync(path.join(__dirname, "../bundles/five.js"), path.resolve(exportPath, "five.js"));
319
-
320
- // copy five.js
321
- fs.copyFileSync(path.join(__dirname, "chfs.exe"), path.resolve(exportPath, "chfs.exe"));
322
-
323
- // 输出 server.py
324
- fs.writeFileSync(path.resolve(exportPath, "server.py"), pyServer, "utf-8");
325
- }
326
-
327
- main(formatWork(work), exportPath);