Skip to content

Commit

Permalink
fix: solve serializer parser selection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Jul 2, 2024
1 parent ffaa424 commit 2d55755
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/fragments/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@thatopen/fragments",
"description": "Simple geometric system built on top of Three.js to display 3D BIM data efficiently.",
"version": "2.0.8",
"version": "2.0.9",
"author": "That Open Company",
"contributors": [
"Antonio Gonzalez Viegas (https://github.com/agviegas)",
Expand Down
67 changes: 67 additions & 0 deletions packages/fragments/src/serializer/example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="icon" type="image/x-icon" href="https://thatopen.github.io/engine_components/resources/favicon.ico">
<title>Serializer</title>
<style>
body {
margin: 0;
padding: 0;
font-family: "Plus Jakarta Sans", sans-serif;
overflow: hidden;
}

.full-screen {
width: 100vw;
height: 100vh;
position: relative;
overflow: hidden;
}

.options-menu {
position: fixed;
min-width: unset;
top: 5px;
right: 5px;
max-height: calc(100vh - 10px);
}

.phone-menu-toggler {
visibility: hidden;
}

@media (max-width: 480px) {
.options-menu {
visibility: hidden;
bottom: 5px;
left: 5px;
}

.options-menu-visible {
visibility: visible;
}

.phone-menu-toggler {
visibility: visible;
position: fixed;
top: 5px;
right: 5px;
}
}

</style>
</head>

<body>
<div class="full-screen" id="container"></div>
<script type="module" src="./example.ts"></script>
</body>

</html>
16 changes: 16 additions & 0 deletions packages/fragments/src/serializer/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as FRAGS from "..";

const serializer = new FRAGS.Serializer();

const group = new FRAGS.FragmentsGroup();
group.globalToExpressIDs.set("a", 11);
group.globalToExpressIDs.set("b", 12);
group.globalToExpressIDs.set("c", 13);
group.data.set(11, [[], []]);
group.data.set(12, [[], []]);
group.data.set(13, [[], []]);

// const exported = serializer.export(group);

const result = serializer.import("../../../../resources/small_v2.frag");
console.log(result);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FragmentsGroup } from "./fragments-group";
import { FragmentParser, ParserV1, ParserV2 } from "./parsers";
import { FragmentsGroup } from "../fragments-group";
import { FragmentParser, ParserV1, ParserV2 } from "../parsers";

/**
* Serializer class for handling the serialization and deserialization of 3D model data. It uses the [flatbuffers library](https://flatbuffers.dev/) for efficient data serialization and deserialization.
Expand All @@ -16,7 +16,7 @@ export class Serializer implements FragmentParser {

/** {@link FragmentParser.import} */
import(bytes: Uint8Array): FragmentsGroup {
const latestVersion = this.parsers.length - 1;
const latestVersion = this.parsers.length;

if (this.version === "auto") {
for (let i = 0; i < this.parsers.length; i++) {
Expand All @@ -34,7 +34,7 @@ export class Serializer implements FragmentParser {
throw new Error("No valid parser found for this file");
}

this.checkCurrentVersionValid(latestVersion);
this.checkCurrentVersionValid(this.version);

const index = this.parsers.length - this.version;
const parser = this.parsers[index];
Expand All @@ -51,14 +51,12 @@ export class Serializer implements FragmentParser {

/** {@link FragmentParser.export} */
export(group: FragmentsGroup) {
const latestVersion = this.parsers.length - 1;

if (this.version === "auto") {
const latestParser = this.parsers[this.parsers.length - 1];
const latestParser = this.parsers[0];
return latestParser.export(group);
}

this.checkCurrentVersionValid(latestVersion);
this.checkCurrentVersionValid(this.version);

const index = this.parsers.length - this.version;
const parser = this.parsers[index];
Expand Down
Binary file added resources/small_v1.frag
Binary file not shown.

0 comments on commit 2d55755

Please sign in to comment.