Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit d4e401e

Browse files
authored
Merge pull request #235 from vimaec/sroberge/2_0_2a
Sroberge/2 0 2a
2 parents 28cef00 + 6ec6592 commit d4e401e

27 files changed

+700
-298
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vim-webgl-viewer",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "A high-performance 3D viewer and VIM file loader built on top of Three.JS.",
55
"files": [
66
"dist"

src/images.ts

Lines changed: 0 additions & 4 deletions
Large diffs are not rendered by default.

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ export * from './vim-loader/legacy/vimRequest'
1010
export * from './vim-loader/geometry'
1111
export type { PointerMode, InputScheme } from './vim-webgl-viewer/inputs/input'
1212
export { DefaultInputScheme, KEYS } from './vim-webgl-viewer/inputs/input'
13-
export * from './vim-webgl-viewer/viewerSettings'
13+
14+
export * from './vim-webgl-viewer/settings/viewerSettings'
15+
export * from './vim-webgl-viewer/settings/viewerSettingsParsing'
16+
export * from './vim-webgl-viewer/settings/defaultViewerSettings'
17+
1418
export {
1519
RaycastResult as HitTestResult,
1620
InputAction

src/main.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import {Viewer, open, THREE} from '.'
2-
1+
import {Viewer, open, THREE, getViewerSettingsFromUrl} from '.'
32

43
// Parse URL for source file
54
const params = new URLSearchParams(window.location.search)
@@ -8,10 +7,14 @@ const url = params.has('vim')
87
: null
98

109
let time: number
11-
const viewer = new Viewer()
10+
11+
const viewer = new Viewer(getViewerSettingsFromUrl(window.location.search))
1212

1313
load(url ?? "https://vim02.azureedge.net/samples/residence.v1.2.75.vim")
14-
// load(url ?? "https://vim02.azureedge.net/samples/residence.v1.2.75.vimx")
14+
//load(url ?? "https://vimdevelopment01storage.blob.core.windows.net/samples/TowerS-ARCHITECTURE-ALL.v1.2.50.vimx")
15+
//load(url ?? "https://vimdevelopment01storage.blob.core.windows.net/samples/BIM1-AUTOP_ARC_2023.vimx")
16+
17+
1518
addLoadButton()
1619

1720

@@ -21,21 +24,20 @@ async function load (url: string | ArrayBuffer) {
2124

2225
const vim = await open(url,
2326
{
24-
legacy : true,
2527
rotation: new THREE.Vector3(270, 0, 0)
2628
}, (p) => console.log(`Downloading Vim (${(p.loaded / 1000).toFixed(0)} kb)`)
2729
)
2830
viewer.add(vim)
2931

30-
3132
vim.loadAll().then(() =>{
3233
viewer.gizmos.loading.visible = false
3334
console.log(`loaded in ${(Date.now() - time) / 1000} seconds`)
3435
})
35-
36+
3637
viewer.camera.snap(true).frame(vim)
3738

3839
// Useful for debuging in console.
40+
globalThis.THREE = THREE
3941
globalThis.vim = vim
4042
globalThis.viewer = viewer
4143
}

src/vim-loader/colorAttributes.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ import * as THREE from 'three'
66
import { MergedSubmesh, Submesh } from './mesh'
77
import { Vim } from './vim'
88
import { InsertableSubmesh } from './progressive/insertableSubmesh'
9+
import { AttributeTarget } from './objectAttributes'
910

1011
export class ColorAttribute {
1112
readonly vim: Vim
12-
private _meshes: Submesh[] | undefined
13+
private _meshes: AttributeTarget[] | undefined
1314
private _value: THREE.Color | undefined
1415

1516
constructor (
16-
meshes: Submesh[] | undefined,
17+
meshes: AttributeTarget[] | undefined,
1718
value: THREE.Color | undefined,
18-
vim: Vim
19+
vim: Vim | undefined
1920
) {
2021
this._meshes = meshes
2122
this._value = value
2223
this.vim = vim
2324
}
2425

25-
updateMeshes (meshes: Submesh[] | undefined) {
26+
updateMeshes (meshes: AttributeTarget[] | undefined) {
2627
this._meshes = meshes
2728
if (this._value !== undefined) {
2829
this.apply(this._value)
@@ -154,7 +155,7 @@ export class ColorAttribute {
154155
* @param index index of the instanced instance
155156
* @param color rgb representation of the color to apply
156157
*/
157-
private applyInstancedColor (sub: Submesh, color: THREE.Color | undefined) {
158+
private applyInstancedColor (sub: AttributeTarget, color: THREE.Color | undefined) {
158159
const colors = this.getOrAddInstanceColorAttribute(
159160
sub.three as THREE.InstancedMesh
160161
)
@@ -169,7 +170,13 @@ export class ColorAttribute {
169170
}
170171

171172
private getOrAddInstanceColorAttribute (mesh: THREE.InstancedMesh) {
172-
if (mesh.instanceColor) return mesh.instanceColor
173+
if (mesh.instanceColor &&
174+
mesh.instanceColor.count <= mesh.instanceMatrix.count
175+
){
176+
return mesh.instanceColor
177+
}
178+
179+
// mesh.count is not always === to capacity so we use instanceMatrix.count
173180
const count = mesh.instanceMatrix.count
174181
// Add color instance attribute
175182
const colors = new Float32Array(count * 3)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* @module vim-loader/materials
3+
*/
4+
5+
import * as THREE from 'three'
6+
7+
/**
8+
* Material for isolation mode
9+
* Non visible item appear as transparent.
10+
* Visible items are flat shaded with a basic pseudo lighting.
11+
* Supports object coloring for visible objects.
12+
* Non-visible objects use fillColor.
13+
*/
14+
export function createSimpleMaterial () {
15+
return new THREE.ShaderMaterial({
16+
uniforms: {
17+
opacity: { value: 0.1 },
18+
fillColor: { value: new THREE.Vector3(0, 0, 0) }
19+
},
20+
vertexColors: true,
21+
//transparent: true,
22+
clipping: true,
23+
vertexShader: /* glsl */ `
24+
25+
#include <common>
26+
#include <logdepthbuf_pars_vertex>
27+
#include <clipping_planes_pars_vertex>
28+
29+
// VISIBILITY
30+
// Instance or vertex attribute to hide objects
31+
// Used as instance attribute for instanced mesh and as vertex attribute for merged meshes.
32+
attribute float ignore;
33+
34+
// Passed to fragment to discard them
35+
varying float vIgnore;
36+
varying vec3 vPosition;
37+
38+
39+
// COLORING
40+
varying vec3 vColor;
41+
42+
// attribute for color override
43+
// merged meshes use it as vertex attribute
44+
// instanced meshes use it as an instance attribute
45+
attribute float colored;
46+
47+
// There seems to be an issue where setting mehs.instanceColor
48+
// doesn't properly set USE_INSTANCING_COLOR
49+
// so we always use it as a fix
50+
#ifndef USE_INSTANCING_COLOR
51+
attribute vec3 instanceColor;
52+
#endif
53+
54+
void main() {
55+
#include <begin_vertex>
56+
#include <project_vertex>
57+
#include <clipping_planes_vertex>
58+
#include <logdepthbuf_vertex>
59+
60+
// VISIBILITY
61+
// Set frag ignore from instance or vertex attribute
62+
vIgnore = ignore;
63+
64+
// COLORING
65+
vColor = color.xyz;
66+
67+
// colored == 1 -> instance color
68+
// colored == 0 -> vertex color
69+
#ifdef USE_INSTANCING
70+
vColor.xyz = colored * instanceColor.xyz + (1.0f - colored) * color.xyz;
71+
#endif
72+
73+
gl_Position.z = -10.0f;
74+
75+
// LIGHTING
76+
vPosition = vec3(mvPosition ) / mvPosition .w;
77+
}
78+
`,
79+
fragmentShader: /* glsl */ `
80+
#include <clipping_planes_pars_fragment>
81+
varying float vIgnore;
82+
varying vec3 vPosition;
83+
varying vec3 vColor;
84+
85+
void main() {
86+
#include <clipping_planes_fragment>
87+
88+
if (vIgnore > 0.0f){
89+
discard;
90+
}
91+
else{
92+
gl_FragColor = vec4(vColor.x, vColor.y, vColor.z, 1.0f);
93+
94+
// LIGHTING
95+
vec3 normal = normalize( cross(dFdx(vPosition), dFdy(vPosition)) );
96+
float light = dot(normal, normalize(vec3(1.4142f, 1.732f, 2.2360f)));
97+
light = 0.5 + (light *0.5);
98+
gl_FragColor.xyz *= light;
99+
}
100+
}
101+
`
102+
})
103+
}

src/vim-loader/materials/standardMaterial.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,39 @@ import * as THREE from 'three'
99
*/
1010
export type ShaderUniforms = { [uniform: string]: THREE.IUniform<any> }
1111

12+
export function createOpaque(){
13+
return new StandardMaterial(createBasicOpaque())
14+
}
15+
16+
export function createTransparent(){
17+
return new StandardMaterial(createBasicTransparent())
18+
}
19+
20+
/**
21+
* Creates a new instance of the default loader opaque material.
22+
* @returns {THREE.MeshPhongMaterial} A new instance of MeshPhongMaterial with transparency.
23+
*/
24+
export function createBasicOpaque () {
25+
return new THREE.MeshPhongMaterial({
26+
color: 0x999999,
27+
vertexColors: true,
28+
flatShading: true,
29+
side: THREE.DoubleSide,
30+
shininess: 5
31+
})
32+
}
33+
34+
/**
35+
* Creates a new instance of the default loader transparent material.
36+
* @returns {THREE.MeshPhongMaterial} A new instance of MeshPhongMaterial with transparency.
37+
*/
38+
export function createBasicTransparent () {
39+
const mat = createBasicOpaque()
40+
mat.transparent = true
41+
mat.shininess = 70
42+
return mat
43+
}
44+
1245
/**
1346
* Material used for both opaque and tranparent surfaces of a VIM model.
1447
*/

src/vim-loader/materials/viewerMaterials.ts

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
*/
44

55
import * as THREE from 'three'
6-
import { StandardMaterial } from './standardMaterial'
6+
import { StandardMaterial, createOpaque, createTransparent } from './standardMaterial'
77
import { createMaskMaterial } from './maskMaterial'
88
import { createIsolationMaterial } from './isolationMaterial'
99
import { OutlineMaterial } from './outlineMaterial'
10-
import { Settings } from '../../vim-webgl-viewer/viewerSettings'
10+
import { ViewerSettings } from '../../vim-webgl-viewer/settings/viewerSettings'
1111
import { MergeMaterial } from './mergeMaterial'
12+
import { createSimpleMaterial } from './simpleMaterial'
1213
import { SignalDispatcher } from 'ste-signals'
1314

1415
/**
@@ -29,19 +30,23 @@ export class ViewerMaterials {
2930
}
3031

3132
/**
32-
* Material used for opaque model geometry
33+
* Material used for opaque model geometry.
3334
*/
3435
opaque: StandardMaterial
3536
/**
36-
* Material used for transparent model geometry
37+
* Material used for transparent model geometry.
3738
*/
3839
transparent: StandardMaterial
3940
/**
40-
* Material used when creating wireframe geometry of the model
41+
* Material used for maximum performance.
42+
*/
43+
simple: THREE.Material
44+
/**
45+
* Material used when creating wireframe geometry of the model.
4146
*/
4247
wireframe: THREE.LineBasicMaterial
4348
/**
44-
* Material used to show traces of hidden objects
49+
* Material used to show traces of hidden objects.
4550
*/
4651
isolation: THREE.Material
4752
/**
@@ -69,15 +74,16 @@ export class ViewerMaterials {
6974
constructor (
7075
opaque?: StandardMaterial,
7176
transparent?: StandardMaterial,
77+
simple?: THREE.Material,
7278
wireframe?: THREE.LineBasicMaterial,
7379
isolation?: THREE.Material,
7480
mask?: THREE.ShaderMaterial,
7581
outline?: OutlineMaterial,
76-
merge?: MergeMaterial,
77-
grid?: THREE.ShaderMaterial
82+
merge?: MergeMaterial
7883
) {
79-
this.opaque = opaque ?? new StandardMaterial(createOpaque())
80-
this.transparent = transparent ?? new StandardMaterial(createTransparent())
84+
this.opaque = opaque ?? createOpaque()
85+
this.transparent = transparent ?? createTransparent()
86+
this.simple = simple ?? createSimpleMaterial()
8187
this.wireframe = wireframe ?? createWireframe()
8288
this.isolation = isolation ?? createIsolationMaterial()
8389
this.mask = mask ?? createMaskMaterial()
@@ -87,9 +93,9 @@ export class ViewerMaterials {
8793

8894
/**
8995
* Updates material settings based on the provided configuration.
90-
* @param {Settings} settings - The settings to apply to the materials.
96+
* @param {ViewerSettings} settings - The settings to apply to the materials.
9197
*/
92-
applySettings (settings: Settings) {
98+
applySettings (settings: ViewerSettings) {
9399
this.isolationOpacity = settings.materials.isolation.opacity
94100
this.isolationColor = settings.materials.isolation.color
95101

@@ -325,31 +331,6 @@ export class ViewerMaterials {
325331
}
326332
}
327333

328-
/**
329-
* Creates a new instance of the default loader opaque material.
330-
* @returns {THREE.MeshPhongMaterial} A new instance of MeshPhongMaterial with transparency.
331-
*/
332-
export function createOpaque () {
333-
return new THREE.MeshPhongMaterial({
334-
color: 0x999999,
335-
vertexColors: true,
336-
flatShading: true,
337-
side: THREE.DoubleSide,
338-
shininess: 5
339-
})
340-
}
341-
342-
/**
343-
* Creates a new instance of the default loader transparent material.
344-
* @returns {THREE.MeshPhongMaterial} A new instance of MeshPhongMaterial with transparency.
345-
*/
346-
export function createTransparent () {
347-
const mat = createOpaque()
348-
mat.transparent = true
349-
mat.shininess = 70
350-
return mat
351-
}
352-
353334
/**
354335
* Creates a new instance of the default wireframe material.
355336
* @returns {THREE.LineBasicMaterial} A new instance of LineBasicMaterial.

src/vim-loader/mesh.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,20 @@ export class Mesh {
164164
}
165165

166166
export type MergedSubmesh = StandardSubmesh | InsertableSubmesh
167-
export type Submesh = MergedSubmesh | InstancedSubmesh
167+
export type Submesh = MergedSubmesh | InstancedSubmesh
168+
169+
export class SimpleInstanceSubmesh
170+
{
171+
mesh: THREE.InstancedMesh
172+
get three() {return this.mesh}
173+
index : number
174+
readonly merged = false
175+
176+
constructor(mesh: THREE.InstancedMesh, index : number){
177+
this.mesh = mesh
178+
this.index = index
179+
}
180+
}
168181

169182
export class StandardSubmesh {
170183
mesh: Mesh

0 commit comments

Comments
 (0)