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

Commit c80c554

Browse files
authored
Merge pull request #5 from Autodesk-Forge/release-0.3.0
Release 0.3.0
2 parents c4ac2d4 + 4d5443d commit c80c554

File tree

13 files changed

+99
-800
lines changed

13 files changed

+99
-800
lines changed

client/loader/STLLoader.js

Lines changed: 0 additions & 435 deletions
This file was deleted.

client/pages/AnimatedSprites.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ function AnimatedSprites(props) {
297297
env={env}
298298
docUrn={docUrn}
299299
onModelLoaded={onModelLoaded}
300-
extensions={{ "Autodesk.DataVisualization": { useInternal: true } }}
300+
extensions={{ "Autodesk.DataVisualization": {} }}
301301
getToken={async () =>
302302
await fetch("/api/token")
303303
.then((res) => res.json())

client/pages/App.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import AnimatedSprites from "./AnimatedSprites.jsx";
1212
import StructureInfo from "./StructureInfo.jsx";
1313
import Navisworks from "./Navisworks.jsx";
1414
import CustomPage from "./CustomPage.jsx";
15-
import MeshHeatmap from "./MeshHeatmap.jsx";
1615

1716
/**
1817
*
@@ -59,9 +58,6 @@ function App(props) {
5958
<Route path="/app">
6059
<CustomPage {...props} />
6160
</Route>
62-
<Route exact={true} path="/meshheatmap">
63-
<MeshHeatmap {...props} />
64-
</Route>
6561
<Route path="/">
6662
<ReferenceApp {...props} />
6763
</Route>

client/pages/DataHelper.js

Lines changed: 78 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ export default class DataHelper {
55
* Checks if the "Autodesk.DataVisualization" extension has already been loaded and loads it otherwise.
66
*
77
* @param {Autodesk.Viewing.GuiViewer3D} viewer Instance of Forge Viewer
8-
* @returns {Object} Reference to Autodesk.DataVisualization.Core
8+
* @returns {Object} Reference to Autodesk.DataVisualization extension.
99
*/
10-
async checkExtension(viewer) {
10+
async getExtension(viewer) {
1111
if (Autodesk && Autodesk.DataVisualization.Core && Autodesk.DataVisualization.Core.SurfaceShadingData) {
12-
return Autodesk.DataVisualization.Core;
12+
return await viewer.getExtension("Autodesk.DataVisualization");
1313
} else {
14-
await viewer.loadExtension("Autodesk.DataVisualization", { useInternal: true });
15-
return Autodesk.DataVisualization.Core;
14+
return await viewer.loadExtension("Autodesk.DataVisualization");
1615
}
1716
}
1817

@@ -60,89 +59,111 @@ export default class DataHelper {
6059
@returns {SurfaceShadingData}
6160
*/
6261
async createShadingData(viewer, model, rawData) {
63-
let ns = await this.checkExtension(viewer);
64-
62+
let dataVizExt = await this.getExtension(viewer);
63+
const ns = Autodesk.DataVisualization.Core;
6564
const {
6665
SurfaceShadingData,
6766
SurfaceShadingPoint,
6867
SurfaceShadingNode,
6968
SurfaceShadingGroup,
7069
} = ns;
7170

72-
let shadingData = new SurfaceShadingData();
71+
const create = async () => {
72+
let shadingData = new SurfaceShadingData();
7373

74-
/**
75-
* Creates a {@link SurfaceShadingNode} corresponding to item.
76-
*
77-
* @param {Object} item
78-
*/
79-
function createNode(item) {
80-
let node = new SurfaceShadingNode(item.id, item.dbIds);
74+
/**
75+
* Creates a {@link SurfaceShadingNode} corresponding to item.
76+
*
77+
* @param {Object} item
78+
*/
79+
function createNode(item) {
80+
let node = new SurfaceShadingNode(item.id, item.dbIds);
8181

82-
item.sensors.forEach((sensor) => {
83-
let shadingPoint = new SurfaceShadingPoint(sensor.id, sensor.position, sensor.sensorTypes, sensor.name, { styleId: sensor.styleId || sensor.type });
82+
item.sensors.forEach((sensor) => {
83+
let shadingPoint = new SurfaceShadingPoint(sensor.id, sensor.position, sensor.sensorTypes, sensor.name, { styleId: sensor.styleId || sensor.type });
8484

85-
// If the position is not specified, derive it from the center of Geometry
86-
if (sensor.dbId != undefined && sensor.position == null) {
87-
shadingPoint.positionFromDBId(model, sensor.dbId);
88-
}
89-
node.addPoint(shadingPoint);
90-
});
85+
// If the position is not specified, derive it from the center of Geometry
86+
if (sensor.dbId != undefined && sensor.position == null) {
87+
shadingPoint.positionFromDBId(model, sensor.dbId);
88+
}
89+
node.addPoint(shadingPoint);
90+
});
9191

92-
return node;
93-
}
92+
return node;
93+
}
9494

95-
/**
96-
* Creates a {@link SurfaceShadingGroup} corresponding to item.
97-
*
98-
* @param {Object} item
99-
*/
100-
function createGroup(item) {
101-
let group = new SurfaceShadingGroup(item.id);
102-
103-
item.children.forEach((child) => {
104-
if (child.children) {
105-
group.addChild(createGroup(child));
95+
/**
96+
* Creates a {@link SurfaceShadingGroup} corresponding to item.
97+
*
98+
* @param {Object} item
99+
*/
100+
function createGroup(item) {
101+
let group = new SurfaceShadingGroup(item.id);
102+
103+
item.children.forEach((child) => {
104+
if (child.children) {
105+
group.addChild(createGroup(child));
106+
} else {
107+
group.addChild(createNode(child));
108+
}
109+
});
110+
return group;
111+
}
112+
113+
rawData.forEach((item) => {
114+
if (item.children) {
115+
shadingData.addChild(createGroup(item));
106116
} else {
107-
group.addChild(createNode(child));
117+
shadingData.addChild(createNode(item));
108118
}
109119
});
110-
return group;
111-
}
112120

113-
rawData.forEach((item) => {
114-
if (item.children) {
115-
shadingData.addChild(createGroup(item));
116-
} else {
117-
shadingData.addChild(createNode(item));
118-
}
119-
});
121+
return shadingData;
122+
}
120123

121-
return shadingData;
124+
// Ensure that instance tree has loaded.
125+
await this.waitForInstanceTree(dataVizExt, model);
126+
return create();
122127
}
123128

124-
125129
/**
126130
* Uses the {@link ModelStructureInfo} to construct {@link SurfaceShadingData}
127131
*
132+
* @param {GuiViewer3D} Viewer instance used to retrieve dataViz extension.
128133
* @param {Model} model Model loaded in viewer
129134
* @param {Device[]} deviceList List of devices to be mapped to loaded rooms.
130135
*/
131-
async createShadingGroupByFloor(model, deviceList) {
132-
const structureInfo = new Autodesk.DataVisualization.Core.ModelStructureInfo(model);
133-
/**
134-
* We have a custom type here for the UI in {@link constructDeviceTree}
135-
*/
136-
let shadingData = await structureInfo.generateSurfaceShadingData(deviceList);
137-
138-
return shadingData;
136+
async createShadingGroupByFloor(viewer, model, deviceList) {
137+
let dataVizExt = await this.getExtension(viewer);
138+
139+
const getShadingData = async () => {
140+
const structureInfo = new Autodesk.DataVisualization.Core.ModelStructureInfo(model);
141+
/**
142+
* We have a custom type here for the UI in {@link constructDeviceTree}
143+
*/
144+
145+
let shadingData = await structureInfo.generateSurfaceShadingData(deviceList);
146+
return shadingData;
147+
}
148+
149+
// Ensure that instance tree has loaded.
150+
await this.waitForInstanceTree(dataVizExt, model);
151+
return getShadingData();
152+
}
153+
154+
155+
async waitForInstanceTree(dataVizExt, model) {
156+
if (dataVizExt.waitForInstanceTree) {
157+
await dataVizExt.waitForInstanceTree(model);
158+
}
139159
}
140160

141161

142162
/**
143163
* Constructs a device tree used to load the device UI.
144164
*
145-
* @param {LevelRoomsMap} shadingData The level-to-room map.
165+
* @param {SurfaceShadingData} shadingData The SurfaceShadingData, generally the output of {@link createShadingGroupByFloor} or
166+
* &nbsp; {@link createShadingData}.
146167
* @param {boolean} usingFullTree When true, constructs a deviceTree that contains all non-empty SurfaceShadingGroups,
147168
* &nbsp;intermediate SurfaceShadingNodes, and SurfaceShading Points. When false, skips intermediate SurfaceShadingNodes.
148169
*
@@ -199,13 +220,8 @@ export default class DataHelper {
199220
}
200221
return shadingData.children.map(item => ({ id: item.id, name: item.name, propIds: [], children: traverse(item).filter(i => i).flat() }));
201222
}
202-
203-
204-
205223
}
206224

207-
208-
209225
}
210226

211227

client/pages/Dot.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function Dot(props) {
119119
env={env}
120120
docUrn={docUrn}
121121
onModelLoaded={onModelLoaded}
122-
extensions={{ "Autodesk.DataVisualization": { useInternal: true } }}
122+
extensions={{ "Autodesk.DataVisualization": { } }}
123123
getToken={async () => await fetch("/api/token").then(res => res.json()).then(data => data.access_token)}
124124
/>
125125
</React.Fragment>

client/pages/Heatmap.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function Heatmap(props) {
143143
env={env}
144144
docUrn={docUrn}
145145
onModelLoaded={onModelLoaded}
146-
extensions={{ "Autodesk.DataVisualization": { useInternal: true } }}
146+
extensions={{ "Autodesk.DataVisualization": { } }}
147147
getToken={async () => await fetch("/api/token").then(res => res.json()).then(data => data.access_token)}
148148
/>
149149
</React.Fragment>

0 commit comments

Comments
 (0)