Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //修改 js/Viwer.js
- onMouseClicked(event) {
- // ... Other code snippets
- this.selection.push(mesh.expressID);
- // ... Other code snippets
- const propResult = mesh.parent.loader.getIfcItemInformation(mesh.expressID);
- if(!propResult) return;
- const data = propResult.arguments;
- const ifcGUID = data[0];
- const objectName = data[2];
- const propsData = {
- dbId: data.ID,
- externalId: ifcGUID,
- name: objectName,
- properties: {}
- };
- propsData.properties['Name'] = data[2];
- propsData.properties['Type'] = data[4];
- propsData.properties['Material'] = null;
- propsData.properties['Layer'] = null;
- propsData.properties['IFC Element'] = null;
- propsData.properties['Tag'] = data[7];
- this.propertyPanel.setTitle(propsData.name);
- this.propertyPanel.setProperties(propsData.properties);
- // ... Other code snippets
- }
- // ... Other code snippets
- // 整個取代
- loadModel(url) {
- if (typeof url != 'string')
- throw new Error('Invalid model url');
- const ext = url.split('.').pop();
- if (ext.toLowerCase() === 'ifc') {
- const ifcLoader = new IfcLoader();
- ifcLoader.load(url, (geometry) => {
- geometry.isIFC = true;
- geometry.loader = ifcLoader;
- this.scene.add(geometry);
- this.models.push(geometry);
- this.render();
- this.fitToView();
- })
- } else {
- const objectLoader = new THREE.ObjectLoader();
- objectLoader.load(url, (obj) => {
- obj.loader = objectLoader;
- this.scene.add(obj);
- this.models.push(obj);
- this.render();
- this.fitToView();
- });
- }
- }
- // ... Other code snippets
- // 整個取代
- hitTestViewport(vpVec) {
- const raycaster = new THREE.Raycaster();
- raycaster.setFromCamera(vpVec, this.camera);
- const ifcObjects = [];
- this.models.forEach(md => {
- if (md.isIFC && md.children) {
- ifcObjects.push(...md.children);
- }
- });
- const intersects = raycaster.intersectObjects(ifcObjects, true);
- console.log(intersects);
- return intersects[0];
- }
- // ... Other code snippets
- buildContextMenu() {
- // ... Other code snippets
- const callBack = (key) => {
- let objects, dbId;
- switch (key) {
- case 'hide-selected':
- // ... Other code snippets
- objects = this.models.map(m => m.getObjectByProperty('expressID', dbId));
- // ... Other code snippets
- break;
- case 'isolate-selected':
- // ... Other code snippets
- this.models.forEach(m => {
- m.traverse(child => {
- if (child.type !== 'Mesh') return;
- if (child.expressID === dbId) {
- child.visible = true;
- return;
- }
- child.visible = false;
- });
- });
- break;
- // ... Other code snippets
- }
- };
- // ... Other code snippets
- }
- // ... Other code snippets
- // 整個取代
- getFitBounds(dbIds) {
- let targets = [];
- if (Array.isArray(dbIds) && dbIds.length > 0) {
- this.models.forEach(m => {
- m.traverse(child => {
- if (child.type !== 'Mesh' || !dbIds.includes(child.expressID)) return;
- targets.push(child);
- });
- });
- } else {
- targets = this.models.concat();
- }
- // get bounding box of object - this will be used to setup navigation and camera
- const bounds = new THREE.Box3();
- targets.forEach((object) => {
- bounds.expandByObject(object);
- });
- return bounds;
- }
- // Put your three.js codes below
- (async function () {
- const SimpleContextMenu = await require('simple-context-menu');
- window.SimpleContextMenu = SimpleContextMenu.default;
- document.addEventListener(
- 'DOMContentLoaded',
- () => {
- const container = document.getElementById('viewer');
- const viewer = new Viewer(container);
- viewer.init();
- viewer.loadModel('../Models/Technical_school-current_m_rooms.ifc');
- window.NOP_VIEWER = viewer;
- });
- })();
- // 修改 index.html
- <script type="module" src="js/IfcLoader.js"></script>
Add Comment
Please, Sign In to add comment