UNPKG

@inweb/viewer-three

Version:

JavaScript library for rendering CAD and BIM files in a browser using Three.js

55 lines (48 loc) 2.66 kB
/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a // license agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// // Model units for the user to choose from. export const DisplayUnits = { Meters: { name: "Meters", symbol: "m", scale: 1.0 }, Centimeters: { name: "Centimeters", symbol: "cm", scale: 0.01 }, Millimeters: { name: "Millimeters", symbol: "mm", scale: 0.001 }, Feet: { name: "Feet", symbol: "ft", scale: 0.3048 }, Inches: { name: "Inches", symbol: "in", scale: 0.0254 }, Yards: { name: "Yards", symbol: "yd", scale: 0.9144 }, Kilometers: { name: "Kilometers", symbol: "km", scale: 1000.0 }, Miles: { name: "Miles", symbol: "mi", scale: 1609.344 }, Micrometers: { name: "Micrometers", symbol: "µm", scale: 0.000001 }, Mils: { name: "Mils", symbol: "mil", scale: 0.0000254 }, MicroInches: { name: "Micro-inches", symbol: "µin", scale: 0.0000000254 }, Default: { name: "File units", symbol: "", scale: 1.0 }, }; export const ModelUnits = { Default: { name: "", symbol: "", scale: 1.0 }, }; Object.keys(DisplayUnits).forEach((key) => (ModelUnits[key] = DisplayUnits[key])); Object.keys(DisplayUnits).forEach((key) => (ModelUnits[DisplayUnits[key].symbol] = DisplayUnits[key])); // Convert distance from unit to unit. export function convertUnits(fromUnits: string, toUnits: string, distance: number) { const fromFactor = 1 / (ModelUnits[fromUnits] || ModelUnits.Default).scale; const toFactor = (ModelUnits[toUnits] || ModelUnits.Default).scale || 1; return distance * fromFactor * toFactor; }