Skip to content

Commit 8632c22

Browse files
author
Pablo
committed
2 parents b1c4a5b + 05abed9 commit 8632c22

File tree

4 files changed

+68
-51
lines changed

4 files changed

+68
-51
lines changed

examples/assets/postproductionRenderer.js

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import{a as f,u as x,M as w,B as O,j as k,V as h,f as g}from"./index-BVinSk0X.js";import{C as M,W as S,S as L,O as y,d as C,F as E}from"./graphic-vertex-picker-DIM7gQA5.js";import{P as I,a as u}from"./index-BLwIRjEQ.js";import{O as D}from"./index-CW0y8L7f.js";import"./index-DTBV6yJD.js";import"./index-uVKS97J8.js";const s=new M,R=s.get(S),a=R.create();a.scene=new L(s);a.scene.setup();a.scene.three.background=null;const G=document.getElementById("container");a.renderer=new I(s,G);a.camera=new y(s);await a.camera.controls.setLookAt(68,23,-8.5,21.5,-5.5,23);s.init();const A=s.get(C),F=A.create(a);F.config.color.set(6710886);a.scene.three.background=null;const W="/node_modules/@thatopen/fragments/dist/Worker/worker.mjs",l=s.get(E);l.init(W);a.camera.controls.addEventListener("rest",()=>l.core.update(!0));a.onCameraChanged.add(e=>{for(const[,r]of l.list)r.useCamera(e.three);l.core.update(!0)});l.list.onItemSet.add(({value:e})=>{e.useCamera(a.camera.three),a.scene.three.add(e.object),l.core.update(!0)});l.core.models.materials.list.onItemSet.add(({value:e})=>{"isLodMaterial"in e&&e.isLodMaterial||(e.polygonOffset=!0,e.polygonOffsetUnits=1,e.polygonOffsetFactor=Math.random())});const _=["https://thatopen.github.io/engine_components/resources/frags/school_arq.frag"];await Promise.all(_.map(async e=>{var p;const r=(p=e.split("/").pop())==null?void 0:p.split(".").shift();if(!r)return null;const P=await(await fetch(e)).arrayBuffer();return l.core.load(P,{modelId:r})}));a.renderer.postproduction.enabled=!0;a.dynamicAnchor=!1;l.core.models.materials.list.onItemSet.add(({value:e})=>{"isLodMaterial"in e&&e.isLodMaterial&&a.renderer.postproduction.basePass.isolatedMaterials.push(e)});const v=l.list.values().next().value,$=s.get(D);$.world=a;const j=await v.getItemsOfCategories([/IFCWALL/]),B=j.IFCWALL,[H,N]=B;$.addItems({[v.modelId]:new Set([H,N])});const d=new f;d.showPanel(2);document.body.append(d.dom);d.dom.style.left="0px";d.dom.style.zIndex="unset";a.renderer.onBeforeUpdate.add(()=>d.begin());a.renderer.onAfterUpdate.add(()=>d.end());x.init();const{aoPass:i,outlinePass:o,edgesPass:b}=a.renderer.postproduction,n={radius:.25,distanceExponent:1,thickness:1,scale:1,samples:16,distanceFallOff:1,screenSpaceRadius:!0},t={lumaPhi:10,depthPhi:2,normalPhi:3,radius:4,radiusExponent:1,rings:2,samples:16};i.updateGtaoMaterial(n);i.updatePdMaterial(t);const m=new w(new O(1,1,1),new k({color:65280}));m.position.set(10,0,0);a.scene.three.add(m);a.renderer.postproduction.excludedObjectsPass.addExcludedMaterial(m.material);const c=h.create(()=>g`
1+
import{a as f,u as x,M as w,B as k,j as O,V as h,f as g}from"./index-BVinSk0X.js";import{C as M,W as S,S as L,O as y,d as C,F as E}from"./graphic-vertex-picker-DIM7gQA5.js";import{P as R,a as u}from"./index-BLwIRjEQ.js";import{O as I}from"./index-CW0y8L7f.js";import"./index-DTBV6yJD.js";import"./index-uVKS97J8.js";const s=new M,D=s.get(S),t=D.create();t.scene=new L(s);t.scene.setup();t.scene.three.background=null;const F=document.getElementById("container");t.renderer=new R(s,F);t.camera=new y(s);await t.camera.controls.setLookAt(68,23,-8.5,21.5,-5.5,23);s.init();const G=s.get(C),j=G.create(t);j.config.color.set(6710886);t.scene.three.background=null;const A="https://thatopen.github.io/engine_fragment/resources/worker.mjs",B=await fetch(A),U=await B.blob(),W=new File([U],"worker.mjs",{type:"text/javascript"}),_=URL.createObjectURL(W),l=s.get(E);l.init(_);t.camera.controls.addEventListener("rest",()=>l.core.update(!0));t.onCameraChanged.add(e=>{for(const[,r]of l.list)r.useCamera(e.three);l.core.update(!0)});l.list.onItemSet.add(({value:e})=>{e.useCamera(t.camera.three),t.scene.three.add(e.object),l.core.update(!0)});l.core.models.materials.list.onItemSet.add(({value:e})=>{"isLodMaterial"in e&&e.isLodMaterial||(e.polygonOffset=!0,e.polygonOffsetUnits=1,e.polygonOffsetFactor=Math.random())});const H=["https://thatopen.github.io/engine_components/resources/frags/school_arq.frag"];await Promise.all(H.map(async e=>{var p;const r=(p=e.split("/").pop())==null?void 0:p.split(".").shift();if(!r)return null;const P=await(await fetch(e)).arrayBuffer();return l.core.load(P,{modelId:r})}));t.renderer.postproduction.enabled=!0;t.dynamicAnchor=!1;l.core.models.materials.list.onItemSet.add(({value:e})=>{"isLodMaterial"in e&&e.isLodMaterial&&t.renderer.postproduction.basePass.isolatedMaterials.push(e)});const v=l.list.values().next().value,$=s.get(I);$.world=t;const N=await v.getItemsOfCategories([/IFCWALL/]),q=N.IFCWALL,[T,V]=q;$.addItems({[v.modelId]:new Set([T,V])});const c=new f;c.showPanel(2);document.body.append(c.dom);c.dom.style.left="0px";c.dom.style.zIndex="unset";t.renderer.onBeforeUpdate.add(()=>c.begin());t.renderer.onAfterUpdate.add(()=>c.end());x.init();const{aoPass:i,outlinePass:o,edgesPass:b}=t.renderer.postproduction,a={radius:.25,distanceExponent:1,thickness:1,scale:1,samples:16,distanceFallOff:1,screenSpaceRadius:!0},n={lumaPhi:10,depthPhi:2,normalPhi:3,radius:4,radiusExponent:1,rings:2,samples:16};i.updateGtaoMaterial(a);i.updatePdMaterial(n);const m=new w(new k(1,1,1),new O({color:65280}));m.position.set(10,0,0);t.scene.three.add(m);t.renderer.postproduction.excludedObjectsPass.addExcludedMaterial(m.material);const d=h.create(()=>g`
22
<bim-panel active label="Postproduction Tutorial" class="options-menu">
33
44
<bim-panel-section label="General">
55
66
<bim-checkbox checked label="Postproduction enabled"
7-
@change="${({target:e})=>{a.renderer.postproduction.enabled=e.value}}">
7+
@change="${({target:e})=>{t.renderer.postproduction.enabled=e.value}}">
88
</bim-checkbox>
99
1010
<bim-checkbox checked label="Outlines enabled"
11-
?checked=${a.renderer.postproduction.outlinesEnabled}
12-
@change="${({target:e})=>{a.renderer.postproduction.outlinesEnabled=e.value}}">
11+
?checked=${t.renderer.postproduction.outlinesEnabled}
12+
@change="${({target:e})=>{t.renderer.postproduction.outlinesEnabled=e.value}}">
1313
</bim-checkbox>
1414
1515
<bim-checkbox checked label="Excluded objects enabled"
16-
?checked=${a.renderer.postproduction.excludedObjectsEnabled}
17-
@change="${({target:e})=>{a.renderer.postproduction.excludedObjectsEnabled=e.value}}">
16+
?checked=${t.renderer.postproduction.excludedObjectsEnabled}
17+
@change="${({target:e})=>{t.renderer.postproduction.excludedObjectsEnabled=e.value}}">
1818
</bim-checkbox>
1919
2020
<bim-dropdown required label="Postproduction style"
21-
@change="${({target:e})=>{const r=e.value[0];a.renderer.postproduction.style=r}}">
21+
@change="${({target:e})=>{const r=e.value[0];t.renderer.postproduction.style=r}}">
2222
2323
<bim-option checked label="Basic" value="${u.COLOR}"></bim-option>
2424
<bim-option label="Pen" value="${u.PEN}"></bim-option>
@@ -34,8 +34,8 @@ import{a as f,u as x,M as w,B as O,j as k,V as h,f as g}from"./index-BVinSk0X.js
3434
3535
<bim-number-input
3636
slider step="0.1" label="Width"
37-
value="${a.renderer.postproduction.edgesPass.width}" min="1" max="3"
38-
@change="${({target:e})=>{a.renderer.postproduction.edgesPass.width=e.value}}">
37+
value="${t.renderer.postproduction.edgesPass.width}" min="1" max="3"
38+
@change="${({target:e})=>{t.renderer.postproduction.edgesPass.width=e.value}}">
3939
</bim-number-input>
4040
4141
<bim-color-input label="Edges color"
@@ -74,8 +74,8 @@ import{a as f,u as x,M as w,B as O,j as k,V as h,f as g}from"./index-BVinSk0X.js
7474
<bim-panel-section label="Ambient Occlusion">
7575
7676
<bim-checkbox checked label="Screen Space Radius"
77-
?checked=${n.screenSpaceRadius}
78-
@change="${({target:e})=>{n.screenSpaceRadius=e.value,i.updateGtaoMaterial(n)}}">
77+
?checked=${a.screenSpaceRadius}
78+
@change="${({target:e})=>{a.screenSpaceRadius=e.value,i.updateGtaoMaterial(a)}}">
7979
</bim-checkbox>
8080
8181
<bim-number-input
@@ -86,87 +86,87 @@ import{a as f,u as x,M as w,B as O,j as k,V as h,f as g}from"./index-BVinSk0X.js
8686
8787
<bim-number-input
8888
slider step="0.01" label="Radius"
89-
value="${n.radius}" min="0.01" max="1"
90-
@change="${({target:e})=>{n.radius=e.value,i.updateGtaoMaterial(n)}}">
89+
value="${a.radius}" min="0.01" max="1"
90+
@change="${({target:e})=>{a.radius=e.value,i.updateGtaoMaterial(a)}}">
9191
</bim-number-input>
9292
9393
<bim-number-input
9494
slider step="0.01" label="Distance exponent"
95-
value="${n.distanceExponent}" min="1" max="4"
96-
@change="${({target:e})=>{n.distanceExponent=e.value,i.updateGtaoMaterial(n)}}">
95+
value="${a.distanceExponent}" min="1" max="4"
96+
@change="${({target:e})=>{a.distanceExponent=e.value,i.updateGtaoMaterial(a)}}">
9797
</bim-number-input>
9898
9999
<bim-number-input
100100
slider step="0.01" label="Thickness"
101-
value="${n.thickness}" min="0.01" max="10"
102-
@change="${({target:e})=>{n.thickness=e.value,i.updateGtaoMaterial(n)}}">
101+
value="${a.thickness}" min="0.01" max="10"
102+
@change="${({target:e})=>{a.thickness=e.value,i.updateGtaoMaterial(a)}}">
103103
</bim-number-input>
104104
105105
<bim-number-input
106106
slider step="0.01" label="Distance falloff"
107-
value="${n.distanceFallOff}" min="0" max="1"
108-
@change="${({target:e})=>{n.distanceFallOff=e.value,i.updateGtaoMaterial(n)}}">
107+
value="${a.distanceFallOff}" min="0" max="1"
108+
@change="${({target:e})=>{a.distanceFallOff=e.value,i.updateGtaoMaterial(a)}}">
109109
</bim-number-input>
110110
111111
<bim-number-input
112112
slider step="0.01" label="Scale"
113-
value="${n.scale}" min="0.01" max="2"
114-
@change="${({target:e})=>{n.scale=e.value,i.updateGtaoMaterial(n)}}">
113+
value="${a.scale}" min="0.01" max="2"
114+
@change="${({target:e})=>{a.scale=e.value,i.updateGtaoMaterial(a)}}">
115115
</bim-number-input>
116116
117117
<bim-number-input
118118
slider step="1" label="Samples"
119-
value="${n.samples}" min="2" max="32"
120-
@change="${({target:e})=>{n.samples=e.value,i.updateGtaoMaterial(n)}}">
119+
value="${a.samples}" min="2" max="32"
120+
@change="${({target:e})=>{a.samples=e.value,i.updateGtaoMaterial(a)}}">
121121
</bim-number-input>
122122
123123
<bim-number-input
124124
slider step="0.1" label="PD Luma Phi"
125-
value="${t.lumaPhi}" min="0" max="20"
126-
@change="${({target:e})=>{t.lumaPhi=e.value,i.updatePdMaterial(t)}}">
125+
value="${n.lumaPhi}" min="0" max="20"
126+
@change="${({target:e})=>{n.lumaPhi=e.value,i.updatePdMaterial(n)}}">
127127
</bim-number-input>
128128
129129
<bim-number-input
130130
slider step="0.1" label="PD Depth Phi"
131-
value="${t.depthPhi}" min="0.01" max="20"
132-
@change="${({target:e})=>{t.depthPhi=e.value,i.updatePdMaterial(t)}}">
131+
value="${n.depthPhi}" min="0.01" max="20"
132+
@change="${({target:e})=>{n.depthPhi=e.value,i.updatePdMaterial(n)}}">
133133
</bim-number-input>
134134
135135
<bim-number-input
136136
slider step="0.1" label="PD Normal Phi"
137-
value="${t.normalPhi}" min="0.01" max="20"
138-
@change="${({target:e})=>{t.normalPhi=e.value,i.updatePdMaterial(t)}}">
137+
value="${n.normalPhi}" min="0.01" max="20"
138+
@change="${({target:e})=>{n.normalPhi=e.value,i.updatePdMaterial(n)}}">
139139
</bim-number-input>
140140
141141
<bim-number-input
142142
slider step="1" label="PD Radius"
143-
value="${t.radius}" min="0" max="32"
144-
@change="${({target:e})=>{t.radius=e.value,i.updatePdMaterial(t)}}">
143+
value="${n.radius}" min="0" max="32"
144+
@change="${({target:e})=>{n.radius=e.value,i.updatePdMaterial(n)}}">
145145
</bim-number-input>
146146
147147
<bim-number-input
148148
slider step="0.1" label="PD Radius Exponent"
149-
value="${t.radiusExponent}" min="0.1" max="4"
150-
@change="${({target:e})=>{t.radiusExponent=e.value,i.updatePdMaterial(t)}}">
149+
value="${n.radiusExponent}" min="0.1" max="4"
150+
@change="${({target:e})=>{n.radiusExponent=e.value,i.updatePdMaterial(n)}}">
151151
</bim-number-input>
152152
153153
<bim-number-input
154154
slider step="0.125" label="PD Rings"
155-
value="${t.rings}" min="1" max="16"
156-
@change="${({target:e})=>{t.rings=e.value,i.updatePdMaterial(t)}}">
155+
value="${n.rings}" min="1" max="16"
156+
@change="${({target:e})=>{n.rings=e.value,i.updatePdMaterial(n)}}">
157157
</bim-number-input>
158158
159159
<bim-number-input
160160
slider step="1" label="PD Samples"
161-
value="${t.samples}" min="2" max="32"
162-
@change="${({target:e})=>{t.samples=e.value,i.updatePdMaterial(t)}}">
161+
value="${n.samples}" min="2" max="32"
162+
@change="${({target:e})=>{n.samples=e.value,i.updatePdMaterial(n)}}">
163163
</bim-number-input>
164164
165165
</bim-panel-section>
166166
167167
</bim-panel>
168-
`);document.body.append(c);const U=h.create(()=>g`
168+
`);document.body.append(d);const z=h.create(()=>g`
169169
<bim-button class="phone-menu-toggler" icon="solar:settings-bold"
170-
@click="${()=>{c.classList.contains("options-menu-visible")?c.classList.remove("options-menu-visible"):c.classList.add("options-menu-visible")}}">
170+
@click="${()=>{d.classList.contains("options-menu-visible")?d.classList.remove("options-menu-visible"):d.classList.add("options-menu-visible")}}">
171171
</bim-button>
172-
`);document.body.append(U);
172+
`);document.body.append(z);

packages/front/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@thatopen/components-front",
33
"description": "Collection of frontend tools to author BIM apps.",
4-
"version": "3.2.0",
4+
"version": "3.2.1",
55
"author": "That Open Company",
66
"contributors": [
77
"Antonio Gonzalez Viegas (https://github.com/agviegas)",
@@ -50,4 +50,4 @@
5050
"dependencies": {
5151
"@thatopen/components": "~3.2.0"
5252
}
53-
}
53+
}

packages/front/src/core/ClipStyler/src/clip-edges.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class ClipEdges implements OBC.Disposable {
8080
});
8181
}
8282

83-
private getStyleMeshes(modelId: string, styleName: string) {
83+
private async getStyleMeshes(modelId: string, styleName: string) {
8484
const clipStyler = this._components.get(ClipStyler);
8585
const style = clipStyler.styles.get(styleName);
8686
if (!style) {
@@ -107,14 +107,18 @@ export class ClipEdges implements OBC.Disposable {
107107
if (linesMaterial) {
108108
edges = new LineSegments2(new LineSegmentsGeometry(), linesMaterial);
109109
edges.frustumCulled = false;
110-
if (model) edges.applyMatrix4(model.object.matrixWorld);
110+
if (model) {
111+
fragments.applyBaseCoordinateSystem(edges, await model.getCoordinationMatrix())
112+
}
111113
this.three.add(edges);
112114
}
113-
115+
114116
let fills: THREE.Mesh | undefined;
115117
if (fillsMaterial) {
116118
fills = new THREE.Mesh(new THREE.BufferGeometry(), fillsMaterial);
117-
if (model) fills.applyMatrix4(model.object.matrixWorld);
119+
if (model) {
120+
fragments.applyBaseCoordinateSystem(fills, await model.getCoordinationMatrix())
121+
}
118122
this.three.add(fills);
119123
}
120124

@@ -137,12 +141,19 @@ export class ClipEdges implements OBC.Disposable {
137141
const disposer = this._components.get(OBC.Disposer);
138142

139143
const plane = this.plane.clone();
140-
plane.constant -= 0.01;
144+
145+
const planeTransform = (await model.getCoordinationMatrix())
146+
.clone()
147+
.multiply(fragments.baseCoordinationMatrix.clone().invert());
148+
149+
plane.applyMatrix4(planeTransform)
150+
151+
plane.constant -= 0.01; // little offset to avoid z-fighting
141152

142153
const section = await model.getSection(plane, localIds);
143154
const { buffer, index, fillsIndices } = section;
144155

145-
const meshes = this.getStyleMeshes(modelId, styleName);
156+
const meshes = await this.getStyleMeshes(modelId, styleName);
146157
const { edges, fills } = meshes;
147158

148159
const posAttr = new THREE.BufferAttribute(buffer, 3, false);
@@ -157,7 +168,7 @@ export class ClipEdges implements OBC.Disposable {
157168
edges.geometry.fromLineSegments(temp);
158169
disposer.destroy(temp);
159170
}
160-
171+
161172
// Update fills
162173
if (fills) {
163174
fills.geometry.attributes.position = posAttr;

packages/front/src/core/PostproductionRenderer/example.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,14 @@ world.scene.three.background = null;
7575
Now, let's configure the FragmentsManager. This will allow us to load models effortlessly and start manipulating them with ease:
7676
*/
7777

78-
const workerUrl =
79-
"/node_modules/@thatopen/fragments/dist/Worker/worker.mjs";
78+
const githubUrl =
79+
"https://thatopen.github.io/engine_fragment/resources/worker.mjs";
80+
const fetchedUrl = await fetch(githubUrl);
81+
const workerBlob = await fetchedUrl.blob();
82+
const workerFile = new File([workerBlob], "worker.mjs", {
83+
type: "text/javascript",
84+
});
85+
const workerUrl = URL.createObjectURL(workerFile);
8086
const fragments = components.get(OBC.FragmentsManager);
8187
fragments.init(workerUrl);
8288

0 commit comments

Comments
 (0)