Skip to content

Commit

Permalink
Add option to disable simplification of robot assets (closes #231)
Browse files Browse the repository at this point in the history
Also document method of disabling simplification for individual meshes
  • Loading branch information
jwbonner committed Oct 18, 2024
1 parent 377e24a commit bd3dc7c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docsSite/docs/more-features/custom-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ A model must be included in the folder with the name "model.glb". CAD files must
{
"name": string // Unique name, required for all asset types
"sourceUrl": string // Link to the original file, optional
"disableSimplification": boolean // Whether to disable model simplification, optional
"rotations": { "axis": "x" | "y" | "z", "degrees": number }[] // Sequence of rotations along the x, y, and z axes
"position": [number, number, number] // Position offset in meters, applied after rotation
"cameras": [ // Fixed camera positions, can be empty
Expand All @@ -59,6 +60,14 @@ A model must be included in the folder with the name "model.glb". CAD files must

The simplest way to determine appropriate position and rotation values is by trial and error. We recommend adjusting rotation before position as the transforms are applied in this order.

:::info
AdvantageScope simplifies model geometry automatically to improve performance, where the level of detail depends on the selected [rendering mode](../tab-reference/3d-field.md#rendering-modes). In cases where model simplification produces undesired effects with custom assets, two solutions can be used:

- To disable automatic removal of a particular mesh, include the string `NOSIMPLIFY` in the mesh name.
- To disable model simplification for an entire robot model, set the `disableSimplification` option in the configuration to `true`.

:::

### Articulated Components

:::warning
Expand Down
9 changes: 8 additions & 1 deletion src/main/assetsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,21 @@ export function loadAssets(): AdvantageScopeAssets {
rotations: [],
position: [0, 0, 0],
cameras: [],
components: []
components: [],
disableSimplification: false
};
if ("name" in configRaw && typeof configRaw.name === "string") {
config.name = configRaw.name;
}
if ("sourceUrl" in configRaw && typeof configRaw.sourceUrl === "string") {
config.sourceUrl = configRaw.sourceUrl;
}
if (config.name === "Preseto") {
console.log(configRaw);
}
if ("disableSimplification" in configRaw && typeof configRaw.disableSimplification === "boolean") {
config.disableSimplification = configRaw.disableSimplification;
}
if (
"rotations" in configRaw &&
Array.isArray(configRaw.rotations) &&
Expand Down
1 change: 1 addition & 0 deletions src/shared/AdvantageScopeAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface Config3dRobot {
path: string;

sourceUrl?: string;
disableSimplification: boolean;
rotations: Config3d_Rotation[];
position: [number, number, number];
cameras: Config3dRobot_Camera[];
Expand Down
8 changes: 7 additions & 1 deletion src/shared/renderers/threeDimension/workers/loadRobot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ self.onmessage = (event) => {
scene.position.set(...robotConfig!.position);
}

let optimized = await optimizeGeometries(scene, mode, materialSpecular, materialShininess);
let optimized = await optimizeGeometries(
scene,
mode,
materialSpecular,
materialShininess,
!robotConfig.disableSimplification
);
let sceneMeshes: THREE.Mesh[] = [];
if (optimized.normal.length > 0) sceneMeshes.push(optimized.normal[0]);
if (optimized.transparent.length > 0) sceneMeshes.push(optimized.transparent[0]);
Expand Down

0 comments on commit bd3dc7c

Please sign in to comment.