[GITAEC] add viewer
This commit is contained in:
parent
00ff39f5df
commit
b3743e1f9d
3 changed files with 141 additions and 0 deletions
|
|
@ -40,6 +40,7 @@ var (
|
||||||
svgComment = regexp.MustCompile(`(?s)<!--.*?-->`)
|
svgComment = regexp.MustCompile(`(?s)<!--.*?-->`)
|
||||||
svgTagRegex = regexp.MustCompile(`(?si)\A\s*(?:(<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg\b`)
|
svgTagRegex = regexp.MustCompile(`(?si)\A\s*(?:(<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg\b`)
|
||||||
svgTagInXMLRegex = regexp.MustCompile(`(?si)\A<\?xml\b.*?\?>\s*(?:(<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg\b`)
|
svgTagInXMLRegex = regexp.MustCompile(`(?si)\A<\?xml\b.*?\?>\s*(?:(<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg\b`)
|
||||||
|
ifcRegex = regexp.MustCompile(`(?si)ISO\-10303\-21\;`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// SniffedType contains information about a blobs type.
|
// SniffedType contains information about a blobs type.
|
||||||
|
|
@ -67,6 +68,11 @@ func (ct SniffedType) IsPDF() bool {
|
||||||
return strings.Contains(ct.contentType, "application/pdf")
|
return strings.Contains(ct.contentType, "application/pdf")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsIFC detects if data is a IFC format
|
||||||
|
func (ct SniffedType) IsIFC() bool {
|
||||||
|
return strings.Contains(ct.contentType, "ifc/")
|
||||||
|
}
|
||||||
|
|
||||||
// IsVideo detects if data is an video format
|
// IsVideo detects if data is an video format
|
||||||
func (ct SniffedType) IsVideo() bool {
|
func (ct SniffedType) IsVideo() bool {
|
||||||
return strings.Contains(ct.contentType, "video/")
|
return strings.Contains(ct.contentType, "video/")
|
||||||
|
|
@ -123,6 +129,14 @@ func (ct SniffedType) GetMimeType() string {
|
||||||
return strings.SplitN(ct.contentType, ";", 2)[0]
|
return strings.SplitN(ct.contentType, ";", 2)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DetectContentFromData(ct string, data []byte) string {
|
||||||
|
if ifcRegex.Match(data) {
|
||||||
|
return "ifc/"
|
||||||
|
} else {
|
||||||
|
return ct
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DetectContentType extends http.DetectContentType with more content types. Defaults to text/unknown if input is empty.
|
// DetectContentType extends http.DetectContentType with more content types. Defaults to text/unknown if input is empty.
|
||||||
func DetectContentType(data []byte, filename string) SniffedType {
|
func DetectContentType(data []byte, filename string) SniffedType {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
|
|
@ -189,6 +203,8 @@ func DetectContentType(data []byte, filename string) SniffedType {
|
||||||
ct = GLBMimeType
|
ct = GLBMimeType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ct = DetectContentFromData(ct, data)
|
||||||
|
|
||||||
return SniffedType{ct}
|
return SniffedType{ct}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -620,6 +620,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) {
|
||||||
|
|
||||||
case fInfo.st.IsPDF():
|
case fInfo.st.IsPDF():
|
||||||
ctx.Data["IsPDFFile"] = true
|
ctx.Data["IsPDFFile"] = true
|
||||||
|
case fInfo.st.IsIFC():
|
||||||
|
ctx.Data["IsIFC"] = true
|
||||||
case fInfo.st.IsVideo():
|
case fInfo.st.IsVideo():
|
||||||
ctx.Data["IsVideoFile"] = true
|
ctx.Data["IsVideoFile"] = true
|
||||||
case fInfo.st.IsAudio():
|
case fInfo.st.IsAudio():
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,129 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
<a href="{{$.RawFileLink}}" rel="nofollow">{{ctx.Locale.Tr "repo.file_view_raw"}}</a>
|
<a href="{{$.RawFileLink}}" rel="nofollow">{{ctx.Locale.Tr "repo.file_view_raw"}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
<div class="pdf-content is-loading" data-src="{{$.RawFileLink}}" data-fallback-button-text="{{ctx.Locale.Tr "repo.diff.view_file"}}"></div>
|
||||||
|
{{else if .IsIFC}}
|
||||||
|
|
||||||
|
|
||||||
|
<div class="full-screen" id="container" style="width: 100%;height:500px;"></div>
|
||||||
|
<script type="module">
|
||||||
|
|
||||||
|
import * as THREE from "https://unpkg.com/three@0.152.2/build/three.module.js";
|
||||||
|
import * as OBC from "/assets/js/openbim-components.js";
|
||||||
|
import * as WEBIFC from "https://unpkg.com/web-ifc@0.0.50/web-ifc-api.js";
|
||||||
|
import Stats from "https://unpkg.com/stats-js@1.0.1/src/Stats.js";
|
||||||
|
import * as dat from "https://unpkg.com/three@0.152.2/examples/jsm/libs/lil-gui.module.min.js";
|
||||||
|
import {downloadZip} from "https://unpkg.com/client-zip@2.3.0/index.js";
|
||||||
|
|
||||||
|
const container = document.getElementById('container');
|
||||||
|
const components = new OBC.Components();
|
||||||
|
|
||||||
|
components.scene = new OBC.SimpleScene(components);
|
||||||
|
components.renderer = new OBC.PostproductionRenderer(components, container);
|
||||||
|
components.camera = new OBC.SimpleCamera(components);
|
||||||
|
components.raycaster = new OBC.SimpleRaycaster(components);
|
||||||
|
|
||||||
|
components.init();
|
||||||
|
|
||||||
|
components.renderer.postproduction.enabled = true;
|
||||||
|
const scene = components.scene.get();
|
||||||
|
components.camera.controls.setLookAt(12, 6, 8, 0, 0, -10);
|
||||||
|
components.scene.setup();
|
||||||
|
|
||||||
|
const grid = new OBC.SimpleGrid(components, new THREE.Color(0x666666));
|
||||||
|
const customEffects = components.renderer.postproduction.customEffects;
|
||||||
|
customEffects.excludedMeshes.push(grid.get());
|
||||||
|
|
||||||
|
let fragments = new OBC.FragmentManager(components);
|
||||||
|
let fragmentIfcLoader = new OBC.FragmentIfcLoader(components);
|
||||||
|
|
||||||
|
const mainToolbar = new OBC.Toolbar(components, { name: 'Main Toolbar', position: 'bottom' });
|
||||||
|
components.ui.addToolbar(mainToolbar);
|
||||||
|
const ifcButton = fragmentIfcLoader.uiElement.get("main");
|
||||||
|
mainToolbar.addChild(ifcButton);
|
||||||
|
|
||||||
|
await fragmentIfcLoader.setup()
|
||||||
|
|
||||||
|
const excludedCats = [
|
||||||
|
WEBIFC.IFCTENDONANCHOR,
|
||||||
|
WEBIFC.IFCREINFORCINGBAR,
|
||||||
|
WEBIFC.IFCREINFORCINGELEMENT,
|
||||||
|
];
|
||||||
|
|
||||||
|
for(const cat of excludedCats) {
|
||||||
|
fragmentIfcLoader.settings.excludedCategories.add(cat);
|
||||||
|
}
|
||||||
|
|
||||||
|
fragmentIfcLoader.settings.webIfc.COORDINATE_TO_ORIGIN = true;
|
||||||
|
fragmentIfcLoader.settings.webIfc.OPTIMIZE_PROFILES = true;
|
||||||
|
|
||||||
|
async function loadIfcAsFragments() {
|
||||||
|
//const testpath="http://localhost:3014/rvba/test/src/branch/main/1019-column.ifc"
|
||||||
|
//const testpath="/rvba/test/src/branch/main/1019-column.ifc"
|
||||||
|
//const testpath="http://localhost:3014/rvba/test/raw/branch/main/1019-column.ifc"
|
||||||
|
const testpath="{{$.RawFileLink}}"
|
||||||
|
//const testpath="http://localhost:3014/rvba/test/src/branch/main/example.ifc"
|
||||||
|
//const file = await fetch('./small.ifc');
|
||||||
|
const file = await fetch(testpath);
|
||||||
|
const data = await file.arrayBuffer();
|
||||||
|
const buffer = new Uint8Array(data);
|
||||||
|
const model = await fragmentIfcLoader.load(buffer, "example");
|
||||||
|
scene.add(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function exportFragments() {
|
||||||
|
if (!fragments.groups.length) return;
|
||||||
|
const group = fragments.groups[0];
|
||||||
|
const data = fragments.export(group);
|
||||||
|
const blob = new Blob([data]);
|
||||||
|
const fragmentFile = new File([blob], 'small.frag');
|
||||||
|
|
||||||
|
const files = [];
|
||||||
|
files.push(fragmentFile);
|
||||||
|
files.push(new File([JSON.stringify(group.properties)], 'small.json'));
|
||||||
|
const result = await downloadZip(files).blob();
|
||||||
|
result.name = 'example';
|
||||||
|
download(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
function download(file) {
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = URL.createObjectURL(file);
|
||||||
|
link.download = file.name;
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
link.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
function disposeFragments() {
|
||||||
|
fragments.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
const stats = new Stats();
|
||||||
|
stats.showPanel(2);
|
||||||
|
document.body.append(stats.dom);
|
||||||
|
stats.dom.style.left = '0px';
|
||||||
|
const renderer = components.renderer;
|
||||||
|
renderer.onBeforeUpdate.add(() => stats.begin());
|
||||||
|
renderer.onAfterUpdate.add(() => stats.end());
|
||||||
|
|
||||||
|
window.dispatchEvent(new Event('resize'));
|
||||||
|
|
||||||
|
const settings = {
|
||||||
|
loadFragments: () => loadIfcAsFragments(),
|
||||||
|
exportFragments: () => exportFragments(),
|
||||||
|
disposeFragments: () => disposeFragments(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const gui = new dat.GUI();
|
||||||
|
|
||||||
|
//gui.add(settings, 'loadFragments').name('Import fragments');
|
||||||
|
//gui.add(settings, 'exportFragments').name('Export fragments');
|
||||||
|
//gui.add(settings, 'disposeFragments').name('Dispose fragments');
|
||||||
|
|
||||||
|
loadIfcAsFragments();
|
||||||
|
|
||||||
|
</script>
|
||||||
{{else}}
|
{{else}}
|
||||||
<a href="{{$.RawFileLink}}" rel="nofollow">{{ctx.Locale.Tr "repo.file_view_raw"}}</a>
|
<a href="{{$.RawFileLink}}" rel="nofollow">{{ctx.Locale.Tr "repo.file_view_raw"}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue