@selvajs/compute 2.1.0-beta.7 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-6L56B3Q3.js +2 -0
- package/dist/chunk-6L56B3Q3.js.map +1 -0
- package/dist/{chunk-JZFH67ES.cjs → chunk-BTH6J34X.cjs} +3 -3
- package/dist/chunk-BTH6J34X.cjs.map +1 -0
- package/dist/{chunk-XFYFC2DH.js → chunk-H2FJSNMM.js} +3 -3
- package/dist/chunk-H2FJSNMM.js.map +1 -0
- package/dist/chunk-HG24GZ3A.cjs +2 -0
- package/dist/{chunk-HOOUDDZU.cjs.map → chunk-HG24GZ3A.cjs.map} +1 -1
- package/dist/{chunk-KKEKJWPH.cjs → chunk-NFPYFIYS.cjs} +3 -3
- package/dist/chunk-NFPYFIYS.cjs.map +1 -0
- package/dist/{chunk-QYVAMQ2V.js → chunk-UQ7TD57L.js} +3 -3
- package/dist/chunk-UQ7TD57L.js.map +1 -0
- package/dist/core.cjs +1 -1
- package/dist/core.js +1 -1
- package/dist/grasshopper.cjs +1 -1
- package/dist/grasshopper.d.cts +3 -3
- package/dist/grasshopper.d.ts +3 -3
- package/dist/grasshopper.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{visualization-CDBCX2VQ.js → visualization-42QQ22YF.js} +2 -2
- package/dist/visualization-6ZLI4ANV.cjs +2 -0
- package/dist/{visualization-L5ALSBPV.cjs.map → visualization-6ZLI4ANV.cjs.map} +1 -1
- package/dist/visualization.cjs +1 -1
- package/dist/visualization.d.cts +5 -1
- package/dist/visualization.d.ts +5 -1
- package/dist/visualization.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-5LQ5PMV6.js +0 -2
- package/dist/chunk-5LQ5PMV6.js.map +0 -1
- package/dist/chunk-HOOUDDZU.cjs +0 -2
- package/dist/chunk-JZFH67ES.cjs.map +0 -1
- package/dist/chunk-KKEKJWPH.cjs.map +0 -1
- package/dist/chunk-QYVAMQ2V.js.map +0 -1
- package/dist/chunk-XFYFC2DH.js.map +0 -1
- package/dist/visualization-L5ALSBPV.cjs +0 -2
- /package/dist/{visualization-CDBCX2VQ.js.map → visualization-42QQ22YF.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-HOOUDDZU.cjs","../src/core/utils/read-field.ts","../src/core/utils/warnings.ts","../src/features/grasshopper/solve.ts"],"names":["readField","obj","name","record","lower","key","hasField","warnIfClientSide","functionName","suppress","getLogger","DEFINITION_LOAD_FAILED","isDefinitionLoadMiss","error","RhinoComputeError","warnOnEmptyInnerTrees","response","debug","values","empty","param","innerTree","scope"],"mappings":"AAAA,2/BAA8G,SCyB9FA,CAAAA,CAAuBC,CAAAA,CAAcC,CAAAA,CAA6B,CACjF,EAAA,CAAI,CAACD,CAAAA,EAAO,OAAOA,CAAAA,EAAQ,QAAA,CAAU,MAAA,CAErC,IAAME,CAAAA,CAASF,CAAAA,CACf,EAAA,CAAIC,EAAAA,GAAQC,CAAAA,CAAQ,OAAOA,CAAAA,CAAOD,CAAI,CAAA,CAEtC,IAAME,CAAAA,CAAQF,CAAAA,CAAK,WAAA,CAAY,CAAA,CAC/B,GAAA,CAAA,IAAWG,EAAAA,GAAO,MAAA,CAAO,IAAA,CAAKF,CAAM,CAAA,CACnC,EAAA,CAAIE,CAAAA,CAAI,WAAA,CAAY,CAAA,GAAMD,CAAAA,CAAO,OAAOD,CAAAA,CAAOE,CAAG,CAGpD,CAOO,SAASC,CAAAA,CAASL,CAAAA,CAAcC,CAAAA,CAAuB,CAC7D,EAAA,CAAI,CAACD,CAAAA,EAAO,OAAOA,CAAAA,EAAQ,QAAA,CAAU,MAAO,CAAA,CAAA,CAC5C,IAAME,CAAAA,CAASF,CAAAA,CACf,EAAA,CAAIC,EAAAA,GAAQC,CAAAA,CAAQ,MAAO,CAAA,CAAA,CAC3B,IAAMC,CAAAA,CAAQF,CAAAA,CAAK,WAAA,CAAY,CAAA,CAC/B,OAAO,MAAA,CAAO,IAAA,CAAKC,CAAM,CAAA,CAAE,IAAA,CAAME,CAAAA,EAAQA,CAAAA,CAAI,WAAA,CAAY,CAAA,GAAMD,CAAK,CACrE,CC/CO,SAASG,CAAAA,CAAiBC,CAAAA,CAAsBC,CAAAA,CAA0B,CAC5EA,CAAAA,EAIA,OAAO,MAAA,CAAW,GAAA,EACrBC,iCAAAA,CAAU,CAAE,IAAA,CACX,CAAA,SAAA,EAAYF,CAAY,CAAA,8GAAA,CACzB,CAEF,CCSA,IAAMG,EAAAA,CAAyB,uCAAA,CAG/B,SAASC,EAAAA,CAAqBC,CAAAA,CAAyB,CACtD,OAAOA,EAAAA,WAAiBC,mBAAAA,EAAqBD,CAAAA,CAAM,OAAA,CAAQ,QAAA,CAASF,EAAsB,CAC3F,CAeO,SAASI,CAAAA,CAAsBC,CAAAA,CAAsCC,CAAAA,CAAuB,CAClG,EAAA,CAAI,CAACA,CAAAA,CAAO,MAAA,CAEZ,IAAMC,CAAAA,CAASlB,CAAAA,CAAqBgB,CAAAA,CAAU,QAAQ,CAAA,CACtD,EAAA,CAAI,CAAC,KAAA,CAAM,OAAA,CAAQE,CAAM,CAAA,EAAKA,CAAAA,CAAO,MAAA,GAAW,CAAA,CAAG,MAAA,CAEnD,IAAMC,CAAAA,CAAkB,CAAC,CAAA,CACzB,GAAA,CAAA,IAAWC,EAAAA,GAASF,CAAAA,CAAQ,CAC3B,IAAMG,CAAAA,CAAYrB,CAAAA,CAAmCoB,CAAAA,CAAO,WAAW,CAAA,CAAA,CAEnE,CAACC,CAAAA,EAAa,MAAA,CAAO,IAAA,CAAKA,CAAS,CAAA,CAAE,MAAA,GAAW,CAAA,CAAA,EACnDF,CAAAA,CAAM,IAAA,kBAAKnB,CAAAA,CAAkBoB,CAAAA,CAAO,WAAW,CAAA,SAAK,aAAW,CAEjE,CAEA,EAAA,CAAID,CAAAA,CAAM,MAAA,GAAW,CAAA,CAAG,MAAA,CAExB,IAAMG,CAAAA,CAAQH,CAAAA,CAAM,MAAA,GAAWD,CAAAA,CAAO,MAAA,CAAS,KAAA,CAAQ,CAAA,EAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-HOOUDDZU.cjs","sourcesContent":[null,"/**\n * Case-insensitive single-key reader for wire payloads.\n *\n * The Rhino Compute family serializes the same logical field with different\n * casing depending on the server branch:\n *\n * - mcneel 8.x / 9.x: the IO schema is PascalCase (`ParamType`, `Default`,\n * `InnerTree`, …) because those C# classes carry no `[JsonProperty]`.\n * - VektorNode Compute8: the IO schema is camelCase (`paramType`, `default`,\n * …) because the fork added `[JsonProperty(\"camelCase\")]`, BUT the nested\n * `default` DataTree wrapper stays PascalCase (`ParamName` / `InnerTree`)\n * since `Resthopper.IO.DataTree` is an external type the fork can't attribute.\n *\n * So a single response can mix casings, and which casing a given field uses\n * depends on the server branch. Rather than deep-camelCasing the whole payload\n * (the old `camelcaseKeys` approach — which corrupted user-authored value-list\n * label keys and item `data` JSON), read the specific fields we care about\n * case-insensitively and leave everything else verbatim.\n *\n * Prefers an exact-case match when present, then falls back to the first\n * case-insensitive match. Returns `undefined` when no key matches.\n *\n * @param obj - The source object (any non-object input yields `undefined`).\n * @param name - The logical field name, in any casing.\n */\nexport function readField<T = unknown>(obj: unknown, name: string): T | undefined {\n\tif (!obj || typeof obj !== 'object') return undefined;\n\n\tconst record = obj as Record<string, unknown>;\n\tif (name in record) return record[name] as T;\n\n\tconst lower = name.toLowerCase();\n\tfor (const key of Object.keys(record)) {\n\t\tif (key.toLowerCase() === lower) return record[key] as T;\n\t}\n\treturn undefined;\n}\n\n/**\n * True when `obj` has a key matching `name` (case-insensitively). Distinguishes\n * \"field present but value is null/undefined\" from \"field absent\" — needed where\n * presence itself carries meaning (e.g. an `innerTree` that exists but is empty).\n */\nexport function hasField(obj: unknown, name: string): boolean {\n\tif (!obj || typeof obj !== 'object') return false;\n\tconst record = obj as Record<string, unknown>;\n\tif (name in record) return true;\n\tconst lower = name.toLowerCase();\n\treturn Object.keys(record).some((key) => key.toLowerCase() === lower);\n}\n","import { getLogger } from './logger';\n\nexport function warnIfClientSide(functionName: string, suppress?: boolean): void {\n\tif (suppress) {\n\t\treturn;\n\t}\n\n\tif (typeof window !== 'undefined') {\n\t\tgetLogger().warn(\n\t\t\t`Warning: ${functionName} is running on the client side. For better performance and security, consider running this on the server side.`\n\t\t);\n\t}\n}\n","import { fetchRhinoCompute, RhinoComputeError } from '@/core';\nimport { base64ByteArray, encodeStringToBase64, isBase64 } from '@/core/utils/encoding';\nimport { getLogger } from '@/core/utils/logger';\nimport { readField } from '@/core/utils/read-field';\nimport { warnIfClientSide } from '@/core/utils/warnings';\n\nimport {\n\tGrasshopperRequestSchema,\n\tGrasshopperComputeConfig,\n\tGrasshopperComputeResponse,\n\tDataTree\n} from './types';\n\n/**\n * The exact message the server throws when it can neither resolve a `pointer`\n * nor a base64 `algo` to a definition (ResthopperEndpoints.cs). This is the\n * signal that a cache-key pointer missed the server's definition cache (GC'd, or\n * a different child in the pool), so the caller should retry with the full\n * definition. Matched as a substring because the server wraps it with a category\n * prefix in its exception handler.\n */\nconst DEFINITION_LOAD_FAILED = 'Unable to load grasshopper definition';\n\n/** Does this error look like a server-side definition-load miss? */\nfunction isDefinitionLoadMiss(error: unknown): boolean {\n\treturn error instanceof RhinoComputeError && error.message.includes(DEFINITION_LOAD_FAILED);\n}\n\n/**\n * Debug aid: a solve can return successfully yet hand back outputs whose\n * `InnerTree` is empty (`{}`), meaning that parameter produced nothing — often a\n * sign the definition didn't actually compute (wrong/missing inputs, a guarded\n * branch). The names tell you exactly which output was empty so you can trace it\n * back to the responsible branch.\n *\n * Only logs when `debug` is set: an empty output can be legitimate, so this is a\n * diagnostic, never a hard failure. Reads `ParamName` / `InnerTree`\n * case-insensitively to stay robust across server-branch casing.\n *\n * @internal Exported for testing.\n */\nexport function warnOnEmptyInnerTrees(response: GrasshopperComputeResponse, debug?: boolean): void {\n\tif (!debug) return;\n\n\tconst values = readField<unknown[]>(response, 'values');\n\tif (!Array.isArray(values) || values.length === 0) return;\n\n\tconst empty: string[] = [];\n\tfor (const param of values) {\n\t\tconst innerTree = readField<Record<string, unknown>>(param, 'innerTree');\n\t\t// Treat a missing or empty innerTree as \"produced nothing\".\n\t\tif (!innerTree || Object.keys(innerTree).length === 0) {\n\t\t\tempty.push(readField<string>(param, 'paramName') ?? '<unnamed>');\n\t\t}\n\t}\n\n\tif (empty.length === 0) return;\n\n\tconst scope = empty.length === values.length ? 'all' : `${empty.length}/${values.length}`;\n\tgetLogger().warn(\n\t\t`Solve returned empty output(s) (${scope}): ${empty.join(', ')}. ` +\n\t\t\t`These parameters produced no data — check the definition's inputs and the branch feeding each.`\n\t);\n}\n\n/**\n * Result of a solve that also reports the definition's server-side cache key.\n *\n * `cacheKey` is the `md5_…` identifier the server assigned to the (base64)\n * definition — stable for identical content. A caller that holds it can solve\n * the same definition again by reference (`pointer: cacheKey`) instead of\n * re-uploading the full base64, which matters a lot for large (multi-MB)\n * definitions on a live UI. `null` when the server didn't return one (e.g. a\n * URL-pointer solve).\n */\nexport interface SolveWithCacheKey {\n\tresponse: GrasshopperComputeResponse;\n\tcacheKey: string | null;\n}\n\n/**\n * Runs a Rhino Compute job using the provided tree prototypes and Grasshopper definition.\n *\n * @public Use this for direct compute control. For high-level API, use `GrasshopperClient.solve()`.\n *\n * @param dataTree - An array of `DataTree` objects representing the input data for the compute job.\n * @param definition - The Grasshopper definition, which can be:\n * - A URL string (e.g., 'https://example.com/definition.gh')\n * - A base64-encoded string of the .gh file\n * - A plain string (will be base64-encoded)\n * - A Uint8Array of the .gh file (will be base64-encoded)\n * @param config - Compute configuration (server URL, API key, etc. along with optional timeout, units, etc.)\n * @returns An object containing the compute result and extracted file data.\n *\n * @example\n * // Using a URL\n * await solveGrasshopperDefinition(trees, 'https://example.com/definition.gh', config);\n *\n * // Using a base64 string\n * await solveGrasshopperDefinition(trees, 'UEsDBBQAAAAIAL...', config);\n *\n * // Using binary data\n * const fileData = new Uint8Array([...]);\n * await solveGrasshopperDefinition(trees, fileData, config);\n */\nexport async function solveGrasshopperDefinition(\n\tdataTree: DataTree[],\n\tdefinition: string | Uint8Array,\n\tconfig: GrasshopperComputeConfig\n): Promise<GrasshopperComputeResponse> {\n\tif (config.debug) {\n\t\twarnIfClientSide(\n\t\t\t'solveGrasshopperDefinition',\n\t\t\tconfig.suppressBrowserWarning ?? config.suppressClientSideWarning\n\t\t);\n\t}\n\n\tconst { response } = await runSolve(prepareGrasshopperArgs(definition, dataTree), config);\n\treturn response;\n}\n\n/**\n * Solve while reporting the server's definition cache key.\n *\n * Behaves like {@link solveGrasshopperDefinition} but returns the `cacheKey` the\n * server assigned, so a caller (e.g. the scheduler) can later solve the same\n * definition by reference instead of re-uploading it. The cache key is only\n * meaningful for base64/binary definitions; a URL-pointer solve returns the URL.\n *\n * @internal\n */\nexport async function solveGrasshopperDefinitionWithCacheKey(\n\tdataTree: DataTree[],\n\tdefinition: string | Uint8Array,\n\tconfig: GrasshopperComputeConfig\n): Promise<SolveWithCacheKey> {\n\tif (config.debug) {\n\t\twarnIfClientSide(\n\t\t\t'solveGrasshopperDefinitionWithCacheKey',\n\t\t\tconfig.suppressBrowserWarning ?? config.suppressClientSideWarning\n\t\t);\n\t}\n\n\treturn runSolve(prepareGrasshopperArgs(definition, dataTree), config);\n}\n\n/**\n * Solve a definition by its server-side cache key (`pointer: cacheKey`),\n * skipping the (potentially multi-MB) base64 upload. If the key has been evicted\n * from the server's definition cache — `DEFINITION_LOAD_FAILED` — transparently\n * retry once with the full `definition` and report the fresh cache key so the\n * caller can update its mapping.\n *\n * @returns The solve result plus the (possibly refreshed) cache key, and whether\n * the fast path missed (so callers can record the new key / track hit rate).\n * @internal\n */\nexport async function solveByCacheKey(\n\tdataTree: DataTree[],\n\tcacheKey: string,\n\tdefinition: string | Uint8Array,\n\tconfig: GrasshopperComputeConfig\n): Promise<SolveWithCacheKey & { missed: boolean }> {\n\tif (config.debug) {\n\t\twarnIfClientSide(\n\t\t\t'solveByCacheKey',\n\t\t\tconfig.suppressBrowserWarning ?? config.suppressClientSideWarning\n\t\t);\n\t}\n\n\tconst pointerArgs: GrasshopperRequestSchema = { algo: null, pointer: cacheKey, values: dataTree };\n\n\ttry {\n\t\tconst fast = await runSolve(pointerArgs, config);\n\t\treturn { ...fast, missed: false };\n\t} catch (error) {\n\t\tif (!isDefinitionLoadMiss(error)) throw error;\n\t\t// Cache miss — fall back to the full upload and capture the fresh key.\n\t\tconst full = await runSolve(prepareGrasshopperArgs(definition, dataTree), config);\n\t\treturn { ...full, missed: true };\n\t}\n}\n\n/**\n * Shared solve body: apply optional settings, POST, and split the server's\n * `pointer` (its cache key) off the response. Stripping via shallow copy rather\n * than `delete` keeps any already-observed response object unmutated.\n */\nasync function runSolve(\n\targs: GrasshopperRequestSchema,\n\tconfig: GrasshopperComputeConfig\n): Promise<SolveWithCacheKey> {\n\tapplyOptionalComputeSettings(args, config);\n\n\tconst result = await fetchRhinoCompute<GrasshopperComputeResponse>('grasshopper', args, config);\n\n\tif ('pointer' in result) {\n\t\tconst { pointer, ...rest } = result as GrasshopperComputeResponse & { pointer?: unknown };\n\t\tconst response = rest as GrasshopperComputeResponse;\n\t\twarnOnEmptyInnerTrees(response, config.debug);\n\t\treturn {\n\t\t\tresponse,\n\t\t\tcacheKey: typeof pointer === 'string' ? pointer : null\n\t\t};\n\t}\n\n\twarnOnEmptyInnerTrees(result, config.debug);\n\treturn { response: result, cacheKey: null };\n}\n\n// ============================================================================\n// Grasshopper Arguments\n// ============================================================================\n\n/**\n * Prepares Grasshopper arguments from a definition and data tree.\n * Automatically detects the definition format and converts it appropriately.\n *\n * @param definition - Can be a URL, base64 string, plain string, or Uint8Array\n * @param dataTree - Array of DataTree objects for compute inputs\n * @internal\n */\nexport function prepareGrasshopperArgs(\n\tdefinition: string | Uint8Array,\n\tdataTree: DataTree[]\n): GrasshopperRequestSchema {\n\tconst args: GrasshopperRequestSchema = {\n\t\talgo: null,\n\t\tpointer: null,\n\t\tvalues: dataTree\n\t};\n\n\tif (definition instanceof Uint8Array) {\n\t\t// Binary data → convert to base64\n\t\targs.algo = base64ByteArray(definition);\n\t} else if (/^https?:\\/\\//i.test(definition)) {\n\t\t// URL → use as pointer reference\n\t\targs.pointer = definition;\n\t} else if (isBase64(definition)) {\n\t\t// Already base64 → use as-is\n\t\targs.algo = definition;\n\t} else {\n\t\t// Plain string → encode to base64\n\t\targs.algo = encodeStringToBase64(definition);\n\t}\n\n\treturn args;\n}\n\n/**\n * @internal\n */\nexport function applyOptionalComputeSettings(\n\targlist: GrasshopperRequestSchema,\n\toptions: GrasshopperComputeConfig\n): void {\n\tif (options.cachesolve != null) arglist.cachesolve = options.cachesolve;\n\tif (options.modelunits != null) arglist.modelunits = options.modelunits;\n\tif (options.angletolerance != null) arglist.angletolerance = options.angletolerance;\n\tif (options.absolutetolerance != null) arglist.absolutetolerance = options.absolutetolerance;\n\tif (options.dataversion != null) arglist.dataversion = options.dataversion;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-HG24GZ3A.cjs","../src/core/utils/read-field.ts","../src/core/utils/warnings.ts","../src/features/grasshopper/solve.ts"],"names":["readField","obj","name","record","lower","key","hasField","warnIfClientSide","functionName","suppress","getLogger","DEFINITION_LOAD_FAILED","isDefinitionLoadMiss","error","RhinoComputeError","warnOnEmptyInnerTrees","response","debug","values","empty","param","innerTree","scope"],"mappings":"AAAA,2/BAA8G,SCyB9FA,CAAAA,CAAuBC,CAAAA,CAAcC,CAAAA,CAA6B,CACjF,EAAA,CAAI,CAACD,CAAAA,EAAO,OAAOA,CAAAA,EAAQ,QAAA,CAAU,MAAA,CAErC,IAAME,CAAAA,CAASF,CAAAA,CACf,EAAA,CAAIC,EAAAA,GAAQC,CAAAA,CAAQ,OAAOA,CAAAA,CAAOD,CAAI,CAAA,CAEtC,IAAME,CAAAA,CAAQF,CAAAA,CAAK,WAAA,CAAY,CAAA,CAC/B,GAAA,CAAA,IAAWG,EAAAA,GAAO,MAAA,CAAO,IAAA,CAAKF,CAAM,CAAA,CACnC,EAAA,CAAIE,CAAAA,CAAI,WAAA,CAAY,CAAA,GAAMD,CAAAA,CAAO,OAAOD,CAAAA,CAAOE,CAAG,CAGpD,CAOO,SAASC,CAAAA,CAASL,CAAAA,CAAcC,CAAAA,CAAuB,CAC7D,EAAA,CAAI,CAACD,CAAAA,EAAO,OAAOA,CAAAA,EAAQ,QAAA,CAAU,MAAO,CAAA,CAAA,CAC5C,IAAME,CAAAA,CAASF,CAAAA,CACf,EAAA,CAAIC,EAAAA,GAAQC,CAAAA,CAAQ,MAAO,CAAA,CAAA,CAC3B,IAAMC,CAAAA,CAAQF,CAAAA,CAAK,WAAA,CAAY,CAAA,CAC/B,OAAO,MAAA,CAAO,IAAA,CAAKC,CAAM,CAAA,CAAE,IAAA,CAAME,CAAAA,EAAQA,CAAAA,CAAI,WAAA,CAAY,CAAA,GAAMD,CAAK,CACrE,CC/CO,SAASG,CAAAA,CAAiBC,CAAAA,CAAsBC,CAAAA,CAA0B,CAC5EA,CAAAA,EAIA,OAAO,MAAA,CAAW,GAAA,EACrBC,iCAAAA,CAAU,CAAE,IAAA,CACX,CAAA,SAAA,EAAYF,CAAY,CAAA,8GAAA,CACzB,CAEF,CCSA,IAAMG,EAAAA,CAAyB,uCAAA,CAG/B,SAASC,EAAAA,CAAqBC,CAAAA,CAAyB,CACtD,OAAOA,EAAAA,WAAiBC,mBAAAA,EAAqBD,CAAAA,CAAM,OAAA,CAAQ,QAAA,CAASF,EAAsB,CAC3F,CAeO,SAASI,CAAAA,CAAsBC,CAAAA,CAAsCC,CAAAA,CAAuB,CAClG,EAAA,CAAI,CAACA,CAAAA,CAAO,MAAA,CAEZ,IAAMC,CAAAA,CAASlB,CAAAA,CAAqBgB,CAAAA,CAAU,QAAQ,CAAA,CACtD,EAAA,CAAI,CAAC,KAAA,CAAM,OAAA,CAAQE,CAAM,CAAA,EAAKA,CAAAA,CAAO,MAAA,GAAW,CAAA,CAAG,MAAA,CAEnD,IAAMC,CAAAA,CAAkB,CAAC,CAAA,CACzB,GAAA,CAAA,IAAWC,EAAAA,GAASF,CAAAA,CAAQ,CAC3B,IAAMG,CAAAA,CAAYrB,CAAAA,CAAmCoB,CAAAA,CAAO,WAAW,CAAA,CAAA,CAEnE,CAACC,CAAAA,EAAa,MAAA,CAAO,IAAA,CAAKA,CAAS,CAAA,CAAE,MAAA,GAAW,CAAA,CAAA,EACnDF,CAAAA,CAAM,IAAA,kBAAKnB,CAAAA,CAAkBoB,CAAAA,CAAO,WAAW,CAAA,SAAK,aAAW,CAEjE,CAEA,EAAA,CAAID,CAAAA,CAAM,MAAA,GAAW,CAAA,CAAG,MAAA,CAExB,IAAMG,CAAAA,CAAQH,CAAAA,CAAM,MAAA,GAAWD,CAAAA,CAAO,MAAA,CAAS,KAAA,CAAQ,CAAA,EAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-HG24GZ3A.cjs","sourcesContent":[null,"/**\n * Case-insensitive single-key reader for wire payloads.\n *\n * The Rhino Compute family serializes the same logical field with different\n * casing depending on the server branch:\n *\n * - mcneel 8.x / 9.x: the IO schema is PascalCase (`ParamType`, `Default`,\n * `InnerTree`, …) because those C# classes carry no `[JsonProperty]`.\n * - VektorNode Compute8: the IO schema is camelCase (`paramType`, `default`,\n * …) because the fork added `[JsonProperty(\"camelCase\")]`, BUT the nested\n * `default` DataTree wrapper stays PascalCase (`ParamName` / `InnerTree`)\n * since `Resthopper.IO.DataTree` is an external type the fork can't attribute.\n *\n * So a single response can mix casings, and which casing a given field uses\n * depends on the server branch. Rather than deep-camelCasing the whole payload\n * (the old `camelcaseKeys` approach — which corrupted user-authored value-list\n * label keys and item `data` JSON), read the specific fields we care about\n * case-insensitively and leave everything else verbatim.\n *\n * Prefers an exact-case match when present, then falls back to the first\n * case-insensitive match. Returns `undefined` when no key matches.\n *\n * @param obj - The source object (any non-object input yields `undefined`).\n * @param name - The logical field name, in any casing.\n */\nexport function readField<T = unknown>(obj: unknown, name: string): T | undefined {\n\tif (!obj || typeof obj !== 'object') return undefined;\n\n\tconst record = obj as Record<string, unknown>;\n\tif (name in record) return record[name] as T;\n\n\tconst lower = name.toLowerCase();\n\tfor (const key of Object.keys(record)) {\n\t\tif (key.toLowerCase() === lower) return record[key] as T;\n\t}\n\treturn undefined;\n}\n\n/**\n * True when `obj` has a key matching `name` (case-insensitively). Distinguishes\n * \"field present but value is null/undefined\" from \"field absent\" — needed where\n * presence itself carries meaning (e.g. an `innerTree` that exists but is empty).\n */\nexport function hasField(obj: unknown, name: string): boolean {\n\tif (!obj || typeof obj !== 'object') return false;\n\tconst record = obj as Record<string, unknown>;\n\tif (name in record) return true;\n\tconst lower = name.toLowerCase();\n\treturn Object.keys(record).some((key) => key.toLowerCase() === lower);\n}\n","import { getLogger } from './logger';\n\nexport function warnIfClientSide(functionName: string, suppress?: boolean): void {\n\tif (suppress) {\n\t\treturn;\n\t}\n\n\tif (typeof window !== 'undefined') {\n\t\tgetLogger().warn(\n\t\t\t`Warning: ${functionName} is running on the client side. For better performance and security, consider running this on the server side.`\n\t\t);\n\t}\n}\n","import { fetchRhinoCompute, RhinoComputeError } from '@/core';\nimport { base64ByteArray, encodeStringToBase64, isBase64 } from '@/core/utils/encoding';\nimport { getLogger } from '@/core/utils/logger';\nimport { readField } from '@/core/utils/read-field';\nimport { warnIfClientSide } from '@/core/utils/warnings';\n\nimport {\n\tGrasshopperRequestSchema,\n\tGrasshopperComputeConfig,\n\tGrasshopperComputeResponse,\n\tDataTree\n} from './types';\n\n/**\n * The exact message the server throws when it can neither resolve a `pointer`\n * nor a base64 `algo` to a definition (ResthopperEndpoints.cs). This is the\n * signal that a cache-key pointer missed the server's definition cache (GC'd, or\n * a different child in the pool), so the caller should retry with the full\n * definition. Matched as a substring because the server wraps it with a category\n * prefix in its exception handler.\n */\nconst DEFINITION_LOAD_FAILED = 'Unable to load grasshopper definition';\n\n/** Does this error look like a server-side definition-load miss? */\nfunction isDefinitionLoadMiss(error: unknown): boolean {\n\treturn error instanceof RhinoComputeError && error.message.includes(DEFINITION_LOAD_FAILED);\n}\n\n/**\n * Debug aid: a solve can return successfully yet hand back outputs whose\n * `InnerTree` is empty (`{}`), meaning that parameter produced nothing — often a\n * sign the definition didn't actually compute (wrong/missing inputs, a guarded\n * branch). The names tell you exactly which output was empty so you can trace it\n * back to the responsible branch.\n *\n * Only logs when `debug` is set: an empty output can be legitimate, so this is a\n * diagnostic, never a hard failure. Reads `ParamName` / `InnerTree`\n * case-insensitively to stay robust across server-branch casing.\n *\n * @internal Exported for testing.\n */\nexport function warnOnEmptyInnerTrees(response: GrasshopperComputeResponse, debug?: boolean): void {\n\tif (!debug) return;\n\n\tconst values = readField<unknown[]>(response, 'values');\n\tif (!Array.isArray(values) || values.length === 0) return;\n\n\tconst empty: string[] = [];\n\tfor (const param of values) {\n\t\tconst innerTree = readField<Record<string, unknown>>(param, 'innerTree');\n\t\t// Treat a missing or empty innerTree as \"produced nothing\".\n\t\tif (!innerTree || Object.keys(innerTree).length === 0) {\n\t\t\tempty.push(readField<string>(param, 'paramName') ?? '<unnamed>');\n\t\t}\n\t}\n\n\tif (empty.length === 0) return;\n\n\tconst scope = empty.length === values.length ? 'all' : `${empty.length}/${values.length}`;\n\tgetLogger().warn(\n\t\t`Solve returned empty output(s) (${scope}): ${empty.join(', ')}. ` +\n\t\t\t`These parameters produced no data — check the definition's inputs and the branch feeding each.`\n\t);\n}\n\n/**\n * Result of a solve that also reports the definition's server-side cache key.\n *\n * `cacheKey` is the `md5_…` identifier the server assigned to the (base64)\n * definition — stable for identical content. A caller that holds it can solve\n * the same definition again by reference (`pointer: cacheKey`) instead of\n * re-uploading the full base64, which matters a lot for large (multi-MB)\n * definitions on a live UI. `null` when the server didn't return one (e.g. a\n * URL-pointer solve).\n */\nexport interface SolveWithCacheKey {\n\tresponse: GrasshopperComputeResponse;\n\tcacheKey: string | null;\n}\n\n/**\n * Runs a Rhino Compute job using the provided tree prototypes and Grasshopper definition.\n *\n * @public Use this for direct compute control. For high-level API, use `GrasshopperClient.solve()`.\n *\n * @param dataTree - An array of `DataTree` objects representing the input data for the compute job.\n * @param definition - The Grasshopper definition, which can be:\n * - A URL string (e.g., 'https://example.com/definition.gh')\n * - A base64-encoded string of the .gh file\n * - A plain string (will be base64-encoded)\n * - A Uint8Array of the .gh file (will be base64-encoded)\n * @param config - Compute configuration (server URL, API key, etc. along with optional timeout, units, etc.)\n * @returns An object containing the compute result and extracted file data.\n *\n * @example\n * // Using a URL\n * await solveGrasshopperDefinition(trees, 'https://example.com/definition.gh', config);\n *\n * // Using a base64 string\n * await solveGrasshopperDefinition(trees, 'UEsDBBQAAAAIAL...', config);\n *\n * // Using binary data\n * const fileData = new Uint8Array([...]);\n * await solveGrasshopperDefinition(trees, fileData, config);\n */\nexport async function solveGrasshopperDefinition(\n\tdataTree: DataTree[],\n\tdefinition: string | Uint8Array,\n\tconfig: GrasshopperComputeConfig\n): Promise<GrasshopperComputeResponse> {\n\tif (config.debug) {\n\t\twarnIfClientSide(\n\t\t\t'solveGrasshopperDefinition',\n\t\t\tconfig.suppressBrowserWarning ?? config.suppressClientSideWarning\n\t\t);\n\t}\n\n\tconst { response } = await runSolve(prepareGrasshopperArgs(definition, dataTree), config);\n\treturn response;\n}\n\n/**\n * Solve while reporting the server's definition cache key.\n *\n * Behaves like {@link solveGrasshopperDefinition} but returns the `cacheKey` the\n * server assigned, so a caller (e.g. the scheduler) can later solve the same\n * definition by reference instead of re-uploading it. The cache key is only\n * meaningful for base64/binary definitions; a URL-pointer solve returns the URL.\n *\n * @internal\n */\nexport async function solveGrasshopperDefinitionWithCacheKey(\n\tdataTree: DataTree[],\n\tdefinition: string | Uint8Array,\n\tconfig: GrasshopperComputeConfig\n): Promise<SolveWithCacheKey> {\n\tif (config.debug) {\n\t\twarnIfClientSide(\n\t\t\t'solveGrasshopperDefinitionWithCacheKey',\n\t\t\tconfig.suppressBrowserWarning ?? config.suppressClientSideWarning\n\t\t);\n\t}\n\n\treturn runSolve(prepareGrasshopperArgs(definition, dataTree), config);\n}\n\n/**\n * Solve a definition by its server-side cache key (`pointer: cacheKey`),\n * skipping the (potentially multi-MB) base64 upload. If the key has been evicted\n * from the server's definition cache — `DEFINITION_LOAD_FAILED` — transparently\n * retry once with the full `definition` and report the fresh cache key so the\n * caller can update its mapping.\n *\n * @returns The solve result plus the (possibly refreshed) cache key, and whether\n * the fast path missed (so callers can record the new key / track hit rate).\n * @internal\n */\nexport async function solveByCacheKey(\n\tdataTree: DataTree[],\n\tcacheKey: string,\n\tdefinition: string | Uint8Array,\n\tconfig: GrasshopperComputeConfig\n): Promise<SolveWithCacheKey & { missed: boolean }> {\n\tif (config.debug) {\n\t\twarnIfClientSide(\n\t\t\t'solveByCacheKey',\n\t\t\tconfig.suppressBrowserWarning ?? config.suppressClientSideWarning\n\t\t);\n\t}\n\n\tconst pointerArgs: GrasshopperRequestSchema = { algo: null, pointer: cacheKey, values: dataTree };\n\n\ttry {\n\t\tconst fast = await runSolve(pointerArgs, config);\n\t\treturn { ...fast, missed: false };\n\t} catch (error) {\n\t\tif (!isDefinitionLoadMiss(error)) throw error;\n\t\t// Cache miss — fall back to the full upload and capture the fresh key.\n\t\tconst full = await runSolve(prepareGrasshopperArgs(definition, dataTree), config);\n\t\treturn { ...full, missed: true };\n\t}\n}\n\n/**\n * Shared solve body: apply optional settings, POST, and split the server's\n * `pointer` (its cache key) off the response. Stripping via shallow copy rather\n * than `delete` keeps any already-observed response object unmutated.\n */\nasync function runSolve(\n\targs: GrasshopperRequestSchema,\n\tconfig: GrasshopperComputeConfig\n): Promise<SolveWithCacheKey> {\n\tapplyOptionalComputeSettings(args, config);\n\n\tconst result = await fetchRhinoCompute<GrasshopperComputeResponse>('grasshopper', args, config);\n\n\tif ('pointer' in result) {\n\t\tconst { pointer, ...rest } = result as GrasshopperComputeResponse & { pointer?: unknown };\n\t\tconst response = rest as GrasshopperComputeResponse;\n\t\twarnOnEmptyInnerTrees(response, config.debug);\n\t\treturn {\n\t\t\tresponse,\n\t\t\tcacheKey: typeof pointer === 'string' ? pointer : null\n\t\t};\n\t}\n\n\twarnOnEmptyInnerTrees(result, config.debug);\n\treturn { response: result, cacheKey: null };\n}\n\n// ============================================================================\n// Grasshopper Arguments\n// ============================================================================\n\n/**\n * Prepares Grasshopper arguments from a definition and data tree.\n * Automatically detects the definition format and converts it appropriately.\n *\n * @param definition - Can be a URL, base64 string, plain string, or Uint8Array\n * @param dataTree - Array of DataTree objects for compute inputs\n * @internal\n */\nexport function prepareGrasshopperArgs(\n\tdefinition: string | Uint8Array,\n\tdataTree: DataTree[]\n): GrasshopperRequestSchema {\n\tconst args: GrasshopperRequestSchema = {\n\t\talgo: null,\n\t\tpointer: null,\n\t\tvalues: dataTree\n\t};\n\n\tif (definition instanceof Uint8Array) {\n\t\t// Binary data → convert to base64\n\t\targs.algo = base64ByteArray(definition);\n\t} else if (/^https?:\\/\\//i.test(definition)) {\n\t\t// URL → use as pointer reference\n\t\targs.pointer = definition;\n\t} else if (isBase64(definition)) {\n\t\t// Already base64 → use as-is\n\t\targs.algo = definition;\n\t} else {\n\t\t// Plain string → encode to base64\n\t\targs.algo = encodeStringToBase64(definition);\n\t}\n\n\treturn args;\n}\n\n/**\n * @internal\n */\nexport function applyOptionalComputeSettings(\n\targlist: GrasshopperRequestSchema,\n\toptions: GrasshopperComputeConfig\n): void {\n\tif (options.cachesolve != null) arglist.cachesolve = options.cachesolve;\n\tif (options.modelunits != null) arglist.modelunits = options.modelunits;\n\tif (options.angletolerance != null) arglist.angletolerance = options.angletolerance;\n\tif (options.absolutetolerance != null) arglist.absolutetolerance = options.absolutetolerance;\n\tif (options.dataversion != null) arglist.dataversion = options.dataversion;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkBTH6J34Xcjs = require('./chunk-BTH6J34X.cjs');var _three = require('three'); var V = _interopRequireWildcard(_three); var z = _interopRequireWildcard(_three); var I = _interopRequireWildcard(_three); var F = _interopRequireWildcard(_three); var $ = _interopRequireWildcard(_three); var be = _interopRequireWildcard(_three); var A = _interopRequireWildcard(_three); var p = _interopRequireWildcard(_three); var L = _interopRequireWildcard(_three); var j = _interopRequireWildcard(_three); var B = _interopRequireWildcard(_three);var _={HUGE_THRESHOLD:1e4,LARGE_THRESHOLD:1e3,SCALE_RATIO_THRESHOLD:100,NEAR_PLANE_FACTOR:{TINY:1e-4,SMALL:.001,NORMAL:.01},FAR_PLANE_FACTOR:{HUGE:100,LARGE:50,NORMAL:20},INITIAL_DISTANCE_MULTIPLIER:4};function Hn(e,r,t,n,o){if(Pe(e),r.length===0)return;r.forEach(d=>{e.add(d)});let a=Y(r),i=a.getCenter(new V.Vector3),s=a.getSize(new V.Vector3),l=Math.max(s.x,s.y,s.z);if(l/Math.min(s.x||1,s.y||1,s.z||1)>_.SCALE_RATIO_THRESHOLD||l>_.HUGE_THRESHOLD?(t.near=l*_.NEAR_PLANE_FACTOR.TINY,t.far=l*_.FAR_PLANE_FACTOR.HUGE):l>_.LARGE_THRESHOLD?(t.near=l*_.NEAR_PLANE_FACTOR.SMALL,t.far=l*_.FAR_PLANE_FACTOR.LARGE):(t.near=Math.max(.01,l*_.NEAR_PLANE_FACTOR.NORMAL),t.far=Math.max(2e3,l*_.FAR_PLANE_FACTOR.NORMAL)),t.updateProjectionMatrix(),o)n.minDistance=t.near*2,n.maxDistance=t.far*.9;else{let d=l*_.INITIAL_DISTANCE_MULTIPLIER;t.position.set(i.x+d*.8,i.y+d,i.z+d*1.2),n.target.copy(i),n.minDistance=t.near*2,n.maxDistance=t.far*.9,n.update()}}function de(e){if(!e||typeof e!="string")return _chunkBTH6J34Xcjs.e.call(void 0, ).warn(`Invalid color input: ${e}, using white`),new V.Color(16777215);let r=e.trim();if(/^#?[0-9A-Fa-f]{6}$/.test(r))try{let t=r.startsWith("#")?r:`#${r}`;return new V.Color(t)}catch (e2){return _chunkBTH6J34Xcjs.e.call(void 0, ).warn(`Invalid hex color: ${e}, using white`),new V.Color(16777215)}if(r.includes(",")){let t=r.split(",").map(n=>parseInt(n.trim(),10));if(t.length===3&&t.every(n=>!isNaN(n)&&n>=0&&n<=255))return new V.Color(t[0]/255,t[1]/255,t[2]/255)}try{return new V.Color(r.toLowerCase())}catch (e3){return _chunkBTH6J34Xcjs.e.call(void 0, ).warn(`Invalid color string: ${e}, using white`),new V.Color(16777215)}}function ue(e,r,t="z"){e.forEach(n=>{n.position[t]-=r})}function Y(e){let r=new V.Box3;return e.length===0||e.forEach(t=>{t.updateMatrixWorld(!0);let n=new V.Box3().setFromObject(t);r.union(n)}),r}var Le=new Set(["floor","grid","label-layer"]);function Pe(e){[...e.children].forEach(t=>{Le.has(t.userData.id)||(t.traverse(n=>{let o=n;if(!o.geometry&&!o.material)return;_optionalChain([o, 'access', _2 => _2.geometry, 'optionalAccess', _3 => _3.dispose, 'call', _4 => _4()]);let a=o.material;if(!a)return;(Array.isArray(a)?a:[a]).forEach(s=>{for(let l of Object.values(s))l instanceof V.Texture&&l.dispose();s.dispose()})}),t.removeFromParent())})}function Oe(e){let r=e.clone().normalize(),t=new z.Vector3(0,0,1),n=new z.Vector3(0,1,0),o=Math.abs(r.dot(t))>.9?n:t,a=new z.Vector3().crossVectors(r,o).normalize(),i=new z.Vector3().crossVectors(a,r).normalize();return{top:r.clone(),bottom:r.clone().negate(),front:i.clone(),back:i.clone().negate(),right:a.clone(),left:a.clone().negate(),iso:i.clone().multiplyScalar(1.2).add(a.clone()).add(r.clone()).normalize()}}function me(e){let{scene:r,perspective:t,controls:n,onActiveCameraChange:o}=e,a=(_nullishCoalesce(e.up, () => (t.up))).clone().normalize(),i=Oe(a),s=new z.OrthographicCamera(-1,1,1,-1,t.near,t.far);s.up.copy(a);let l="perspective",c=t.aspect,d=()=>l==="perspective"?t:s,u=()=>{let g=t.position.distanceTo(n.target)*Math.tan(t.fov*Math.PI/360),R=g*c;s.left=-R,s.right=R,s.top=g,s.bottom=-g,s.near=t.near,s.far=t.far,s.updateProjectionMatrix()},m=b=>{b!==l&&(b==="orthographic"?(s.position.copy(t.position),s.up.copy(t.up),s.lookAt(n.target),u()):t.position.copy(s.position),l=b,n.object=d(),n.update(),o(d()))},E=(b,g=!0)=>{let R=Be(r),H=R.isEmpty()?n.target.clone():R.getCenter(new z.Vector3),P=R.isEmpty()?new z.Vector3(1,1,1):R.getSize(new z.Vector3),y=Math.max(P.x,P.y,P.z)||1,w=t.fov*(Math.PI/180),C=y/(2*Math.tan(w/2))*1.5,O=ze(b,a),h=H.clone().add(O.clone().multiplyScalar(C)),T=d();g?je(T,n,h,H,()=>{l==="orthographic"&&u()}):(T.position.copy(h),n.target.copy(H),l==="orthographic"&&u(),n.update())};return{getActiveCamera:d,getProjection:()=>l,setProjection:m,toggleProjection:()=>(m(l==="perspective"?"orthographic":"perspective"),l),setView:(b,g=!0)=>{E(i[b],g)},setViewDirection:E,setRotateEnabled:b=>{n.enableRotate=b},isRotateEnabled:()=>n.enableRotate,updateAspect:(b,g)=>{c=g===0?c:b/g,l==="orthographic"&&u()}}}var Ie=new Set(["grid","floor","label-layer","measure"]);function Ve(e){let r=e;for(;r;){if(typeof r.userData.id=="string"&&Ie.has(r.userData.id))return!0;r=r.parent}return!1}function Be(e){let r=[];return e.traverse(t=>{let n=t;t.visible&&!Ve(t)&&n.geometry&&r.push(t)}),Y(r)}function ze(e,r){let t=r.clone().normalize(),n=e.clone().normalize();if(Math.abs(n.dot(t))<.9999)return e;let o=Math.abs(t.dot(new z.Vector3(0,0,1)))>.9?new z.Vector3(0,1,0):new z.Vector3(0,0,1),a=new z.Vector3().crossVectors(t,o).normalize(),i=.5*Math.PI/180;return n.multiplyScalar(Math.cos(i)).add(a.multiplyScalar(Math.sin(i))).normalize()}var Fe=e=>1-Math.pow(1-e,3);function je(e,r,t,n,o,a=250){let i=e.position.clone(),s=r.target.clone(),l=performance.now(),c=()=>{let d=Fe(Math.min((performance.now()-l)/a,1));e.position.lerpVectors(i,t,d),r.target.lerpVectors(s,n,d),o(),r.update(),d<1&&requestAnimationFrame(c)};requestAnimationFrame(c)}var ke=`
|
|
2
2
|
varying vec3 vWorldPos;
|
|
3
3
|
void main() {
|
|
4
4
|
vec4 world = modelMatrix * vec4(position, 1.0);
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
gl_FragColor = vec4(color, alpha);
|
|
52
52
|
}
|
|
53
53
|
`;function Ee(e={}){let{cellSize:r=1,majorEvery:t=10,cellColor:n=8947848,majorColor:o=4473924,fadeDistance:a=100,plane:i="y"}=e,s=i==="y"?new I.Vector2(0,2):i==="z"?new I.Vector2(0,1):new I.Vector2(1,2),l=a*2.5,c=new I.PlaneGeometry(l,l);i==="y"?c.rotateX(-Math.PI/2):i==="x"&&c.rotateY(Math.PI/2);let d=new I.ShaderMaterial({vertexShader:ke,fragmentShader:_e,transparent:!0,depthWrite:!1,side:I.DoubleSide,uniforms:{uAxes:{value:s},uCell:{value:r},uMajor:{value:t},uCellColor:{value:new I.Color(n)},uMajorColor:{value:new I.Color(o)},uCenter:{value:new I.Vector3},uFade:{value:a}}}),u=new I.Mesh(c,d);u.name="grid",u.userData.id="grid",u.renderOrder=-1;let m=new I.Vector3;return{object:u,update:E=>{i==="y"?(u.position.set(E.x,0,E.z),m.set(E.x,0,E.z)):i==="z"?(u.position.set(E.x,E.y,0),m.set(E.x,E.y,0)):(u.position.set(0,E.y,E.z),m.set(0,E.y,E.z)),d.uniforms.uCenter.value.copy(m)},setVisible:E=>{u.visible=E},dispose:()=>{c.dispose(),d.dispose()}}}var _ViewHelperjs = require('three/addons/helpers/ViewHelper.js');function pe(e){let{camera:r,domElement:t,controller:n}=e,o=new (0, _ViewHelperjs.ViewHelper)(r,t);o.setLabels("X","Y","Z");let a=!0,i=128,s=new F.Raycaster,l=new F.OrthographicCamera(-2,2,2,-2,0,4);l.position.set(0,0,2);let c={posX:new F.Vector3(1,0,0),negX:new F.Vector3(-1,0,0),posY:new F.Vector3(0,1,0),negY:new F.Vector3(0,-1,0),posZ:new F.Vector3(0,0,1),negZ:new F.Vector3(0,0,-1)},d=m=>{let E=t.getBoundingClientRect(),f=E.left+t.offsetWidth-i-o.location.right,x=E.top+t.offsetHeight-i-o.location.bottom,S=new F.Vector2((m.clientX-f)/i*2-1,-((m.clientY-x)/i)*2+1);if(Math.abs(S.x)>1||Math.abs(S.y)>1)return null;o.quaternion.copy(r.quaternion).invert(),o.updateMatrixWorld(),s.setFromCamera(S,l);let b=s.intersectObjects(o.children,!1);for(let g of b){let R=_optionalChain([g, 'access', _5 => _5.object, 'access', _6 => _6.userData, 'optionalAccess', _7 => _7.type]);if(typeof R=="string"&&R in c)return R}return null};return{render:m=>{if(!a)return;let E=m.autoClear;m.autoClear=!1,o.render(m),m.autoClear=E},update:m=>{o.animating&&o.update(m)},handleClick:m=>{if(!a)return!1;let E=d(m);return E?(n.getProjection()==="orthographic"&&n.setProjection("perspective"),n.setViewDirection(c[E],!1),!0):!1},get isAnimating(){return o.animating},setVisible:m=>{a=m},isVisible:()=>a,dispose:()=>o.dispose()}}var _LineSegmentsGeometryjs = require('three/addons/lines/LineSegmentsGeometry.js');var _LineSegments2js = require('three/addons/lines/LineSegments2.js');var _LineMaterialjs = require('three/addons/lines/LineMaterial.js');var X="edge-overlay",We=2236962,$e=1.5,Ye=30;function he(e,r={}){let t=new $.Color(_nullishCoalesce(r.color, () => (We))),n=_nullishCoalesce(r.width, () => ($e)),o=_nullishCoalesce(r.thresholdAngle, () => (Ye)),a=[];return e.traverse(i=>{if(!(i instanceof $.Mesh)||i.userData.id==="floor"||i.userData.id==="grid"||i.userData.kind===X||i.children.some(l=>_optionalChain([l, 'access', _8 => _8.userData, 'optionalAccess', _9 => _9.kind])===X)||!i.geometry)return;let s=Xe(i.geometry,t,n,o);i.add(s),a.push(s)}),a}function Xe(e,r,t,n){let o=new $.EdgesGeometry(e,n),a=new _LineSegmentsGeometryjs.LineSegmentsGeometry;a.setPositions(Array.from(o.attributes.position.array)),o.dispose();let i=new (0, _LineMaterialjs.LineMaterial)({color:r});i.linewidth=t,i.polygonOffset=!0,i.polygonOffsetFactor=-1,i.polygonOffsetUnits=-1;let s=new (0, _LineSegments2js.LineSegments2)(a,i);return s.userData.kind=X,s.raycast=()=>{},s}function qe(e){return _optionalChain([e, 'access', _10 => _10.userData, 'optionalAccess', _11 => _11.kind])===X}function On(e){let r=[];e.traverse(t=>{t instanceof _LineSegments2js.LineSegments2&&qe(t)&&r.push(t)});for(let t of r)t.geometry.dispose(),t.material.dispose(),t.removeFromParent();return r.length}var _EffectComposerjs = require('three/addons/postprocessing/EffectComposer.js');var _RenderPassjs = require('three/addons/postprocessing/RenderPass.js');var _GTAOPassjs = require('three/addons/postprocessing/GTAOPass.js');var _OutputPassjs = require('three/addons/postprocessing/OutputPass.js');function ge(e,r,t,n,o,a){let i=new (0, _EffectComposerjs.EffectComposer)(e),s=new (0, _RenderPassjs.RenderPass)(r,t);i.addPass(s);let l=new (0, _GTAOPassjs.GTAOPass)(r,t,n,o);l.blendIntensity=_nullishCoalesce(a.aoIntensity, () => (1)),l.updateGtaoMaterial({screenSpaceRadius:!0}),i.addPass(l);let c=new _OutputPassjs.OutputPass;return i.addPass(c),e.toneMapping=a.toneMapping,e.toneMappingExposure=a.toneMappingExposure,i.setSize(n,o),{render:d=>i.render(d),setSize:(d,u,m)=>{i.setPixelRatio(m),i.setSize(d,u),l.setSize(d,u)},setCamera:d=>{s.camera=d,l.camera=d},dispose:()=>i.dispose()}}var _CSS2DRendererjs = require('three/addons/renderers/CSS2DRenderer.js');function ye(e,r){let t=new _CSS2DRendererjs.CSS2DRenderer,n=t.domElement;n.style.position="absolute",n.style.top="0",n.style.left="0",n.style.width="100%",n.style.height="100%",n.style.overflow="hidden",n.style.pointerEvents="none",n.style.zIndex="30",getComputedStyle(e).position==="static"&&(e.style.position="relative"),e.appendChild(n);let o={width:e.clientWidth||1,height:e.clientHeight||1};t.setSize(o.width,o.height);let a=new be.Group;a.name="label-layer",a.userData.id="label-layer",r.add(a);let i=new Set;return{addLabel:(l,c,d)=>{let u=document.createElement("div");u.textContent=l,d?u.className=d:Object.assign(u.style,{padding:"2px 6px",borderRadius:"4px",background:"rgba(20, 20, 20, 0.78)",color:"#fff",font:"12px/1.3 system-ui, sans-serif",whiteSpace:"pre",textAlign:"center",userSelect:"none"}),u.style.pointerEvents="none";let m=new (0, _CSS2DRendererjs.CSS2DObject)(u);return m.position.copy(c),a.add(m),i.add(m),{object:m,setPosition:E=>m.position.copy(E),setText:E=>{u.textContent=E},remove:()=>{m.removeFromParent(),u.remove(),i.delete(m)}}},render:(l,c)=>t.render(l,c),setSize:(l,c)=>t.setSize(l,c),dispose:()=>{i.forEach(l=>{l.removeFromParent(),l.element.remove()}),i.clear(),a.removeFromParent(),n.remove()}}}var _Line2js = require('three/addons/lines/Line2.js');var _LineGeometryjs = require('three/addons/lines/LineGeometry.js');var at=12,it=16763904,Re=.015,q=e=>`${e.toPrecision(3)} m`,st=(e,r)=>`${q(e)}
|
|
54
|
-
\u0394x ${q(r.x)} \u0394y ${q(r.y)} \u0394z ${q(r.z)}`;function lt(e){let r=e.object;return r instanceof A.Mesh?e.face?[e.face.a,e.face.b,e.face.c]:null:r instanceof A.Points?e.index!=null?[e.index]:null:r instanceof A.Line&&e.index!=null?[e.index,e.index+1]:null}function ct(e,r,t,n){let o=e.point.clone(),a=e.object,i=lt(e);if(!i||!a.geometry)return o;let s=a.geometry.attributes.position;if(!s)return o;let l=m=>{let E=m.clone().project(r);return new A.Vector2((E.x+1)/2*t.width,(1-E.y)/2*t.height)},c=l(o),d=o,u=n;for(let m of i){if(m>=s.count)continue;let f=new A.Vector3().fromBufferAttribute(s,m).applyMatrix4(a.matrixWorld),x=l(f).distanceTo(c);x<u&&(u=x,d=f)}return d}function Te(e){let{canvas:r,scene:t,getActiveCamera:n,labelLayer:o,options:a={}}=e,i=_nullishCoalesce(a.snapPixels, () => (at)),s=new A.Color(_nullishCoalesce(a.color, () => (it))),l=_nullishCoalesce(a.format, () => (st)),c=new A.Raycaster,d=new A.Vector2,u=!1,m=[],E=[],f=null,x=null,S=new A.PointsMaterial({color:s,size:8,sizeAttenuation:!1,depthTest:!1}),b=new A.PointsMaterial({color:s,size:11,sizeAttenuation:!1,depthTest:!1,transparent:!0,opacity:.5}),g=null,R=h=>{if(!h){g&&(g.visible=!1);return}if(!g){let T=new A.BufferGeometry;T.setAttribute("position",new A.Float32BufferAttribute([0,0,0],3)),g=new A.Points(T,b),g.renderOrder=1e3,g.userData.id="measure",g.raycast=()=>{},t.add(g)}g.position.copy(h),g.visible=!0},H=h=>{let T=new A.BufferGeometry;T.setAttribute("position",new A.Float32BufferAttribute([h.x,h.y,h.z],3));let M=new A.Points(T,S);return M.renderOrder=999,M.userData.id="measure",M.raycast=()=>{},t.add(M),M},P=()=>{m.length=0,E.forEach(h=>{h.geometry.dispose(),h.removeFromParent()}),E.length=0,f&&(f.geometry.dispose(),f.material.dispose(),f.removeFromParent(),f=null),_optionalChain([x, 'optionalAccess', _12 => _12.remove, 'call', _13 => _13()]),x=null},y=()=>{if(m.length!==2)return;let[h,T]=m,M=new _LineGeometryjs.LineGeometry;M.setPositions([h.x,h.y,h.z,T.x,T.y,T.z]);let k=new (0, _LineMaterialjs.LineMaterial)({color:s});k.linewidth=2,k.depthTest=!1,f=new (0, _Line2js.Line2)(M,k),f.renderOrder=998,f.userData.id="measure",f.raycast=()=>{},t.add(f);let U=h.clone().add(T).multiplyScalar(.5),W=new A.Vector3(Math.abs(T.x-h.x),Math.abs(T.y-h.y),Math.abs(T.z-h.z));x=o.addLabel(l(h.distanceTo(T),W),U,a.labelClassName)},w=h=>{let T=r.getBoundingClientRect();d.x=(h.clientX-T.left)/T.width*2-1,d.y=-((h.clientY-T.top)/T.height)*2+1;let M=n();c.setFromCamera(d,M);let k=M.position.length();c.params.Line={threshold:k*Re},c.params.Points={threshold:k*Re};let U=c.intersectObjects(t.children,!0).filter(W=>W.object.userData.id!=="measure"&&W.object.userData.id!=="grid");return U.length===0?null:ct(U[0],M,{width:T.width,height:T.height},i)};return{setEnabled:h=>{u=h,h||(P(),R(null))},isEnabled:()=>u,handleClick:h=>{if(!u)return!1;m.length===2&&P();let T=w(h);return T===null||(m.push(T),E.push(H(T)),m.length===2&&y()),!0},handleMove:h=>{u&&R(w(h))},clear:P,dispose:()=>{P(),g&&(g.geometry.dispose(),g.removeFromParent(),g=null),S.dispose(),b.dispose()}}}var _OrbitControlsjs = require('three/addons/controls/OrbitControls.js');var _HDRLoaderjs = require('three/addons/loaders/HDRLoader.js');var Z=new p.Vector3(0,0,1);function mt(e){let r=Math.abs(e.x),t=Math.abs(e.y),n=Math.abs(e.z);return n>=r&&n>=t?"z":t>=r&&t>=n?"y":"x"}var nr=function(e,r){let t=Et(r||{}),n=_optionalChain([t, 'access', _14 => _14.environment, 'optionalAccess', _15 => _15.sceneUp])||Z,o=gt(t),a=Ht(t,e);a.up.copy(n);let i=vt(e,t),s=Ct(a,e,t),l=me({scene:o,perspective:a,controls:s,onActiveCameraChange:()=>{},up:n}),c=()=>l.getActiveCamera();Rt(o,t);let d=Tt(o,t),u=()=>{d&&ht(d,ne(o))};_optionalChain([t, 'access', _16 => _16.floor, 'optionalAccess', _17 => _17.enabled])&&wt(o,t);let m=t.grid.enabled?Ee({cellSize:t.grid.cellSize,majorEvery:t.grid.majorEvery,cellColor:t.grid.cellColor,majorColor:t.grid.majorColor,fadeDistance:t.grid.fadeDistance,plane:t.grid.plane}):null;m&&o.add(m.object);let E=t.gizmo.enabled?pe({camera:a,domElement:e,controller:l}):null,f=_nullishCoalesce(e.parentElement, () => (e)),x=t.measure.enabled?ye(f,o):null,S=t.measure.enabled&&x?Te({canvas:e,scene:o,getActiveCamera:c,labelLayer:x,options:{snapPixels:t.measure.snapPixels,color:t.measure.color,labelClassName:t.measure.labelClassName,format:t.measure.format}}):null,b=t.events.enableEventHandlers!==!1?Mt(e,o,c,a,s,t):{dispose:()=>{},fitToView:()=>{},clearSelection:()=>{}},g=5,R=0,H=0,P=D=>{R=D.clientX,H=D.clientY},y=D=>Math.hypot(D.clientX-R,D.clientY-H)>g,w=D=>{if(!y(D)){if(_optionalChain([S, 'optionalAccess', _18 => _18.handleClick, 'call', _19 => _19(D)])){D.stopImmediatePropagation();return}_optionalChain([E, 'optionalAccess', _20 => _20.handleClick, 'call', _21 => _21(D)])&&D.stopImmediatePropagation()}};(E||S)&&(e.addEventListener("mousedown",P,{capture:!0}),e.addEventListener("click",w,{capture:!0}));let C=D=>_optionalChain([S, 'optionalAccess', _22 => _22.handleMove, 'call', _23 => _23(D)]);S&&e.addEventListener("mousemove",C,{passive:!0});let O=D=>{he(D,{color:t.edges.color,width:t.edges.width,thresholdAngle:t.edges.thresholdAngle})},h=e.parentElement,T=()=>h?{width:h.clientWidth,height:h.clientHeight}:{width:window.innerWidth,height:window.innerHeight},M=null,k=()=>{let{width:D,height:G}=T(),Q=Math.min(window.devicePixelRatio,2),le=ge(i,o,c(),Math.max(1,D),Math.max(1,G),{toneMapping:_nullishCoalesce(t.render.toneMapping, () => (p.NeutralToneMapping)),toneMappingExposure:_nullishCoalesce(t.render.toneMappingExposure, () => (1)),aoIntensity:t.render.aoIntensity});return le.setSize(Math.max(1,D),Math.max(1,G),Q),le},U=D=>{D&&!M?M=k():!D&&M&&(M.dispose(),M=null)};t.render.ambientOcclusion&&(M=k());let{animate:W,dispose:K}=yt(i,o,a,c,l,s,T,t.events.onFrame,m,E,()=>M,x);return W(),o.up.set(n.x,n.y,n.z),u(),{scene:o,camera:a,controls:s,renderer:i,cameraController:l,grid:m,gizmo:E,measureTool:S,applyEdges:O,setAmbientOcclusion:U,updateShadowBounds:u,dispose:()=>{K(),b.dispose(),(E||S)&&(e.removeEventListener("mousedown",P,{capture:!0}),e.removeEventListener("click",w,{capture:!0})),S&&e.removeEventListener("mousemove",C),_optionalChain([S, 'optionalAccess', _24 => _24.dispose, 'call', _25 => _25()]),_optionalChain([x, 'optionalAccess', _26 => _26.dispose, 'call', _27 => _27()]),_optionalChain([E, 'optionalAccess', _28 => _28.dispose, 'call', _29 => _29()]),_optionalChain([m, 'optionalAccess', _30 => _30.dispose, 'call', _31 => _31()]),_optionalChain([M, 'optionalAccess', _32 => _32.dispose, 'call', _33 => _33()]),s.dispose(),i.dispose(),o.traverse(D=>{let G=D;!G.geometry&&!G.material||(_optionalChain([G, 'access', _34 => _34.geometry, 'optionalAccess', _35 => _35.dispose, 'call', _36 => _36()]),Array.isArray(G.material)?G.material.forEach(Q=>Q.dispose()):_optionalChain([G, 'access', _37 => _37.material, 'optionalAccess', _38 => _38.dispose, 'call', _39 => _39()]))})},fitToView:b.fitToView,clearSelection:b.clearSelection}};function Et(e){let r=e.sceneScale||"m",n={mm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:10,lightHeight:20,minDistance:.1,shadowSize:100,scaleFactor:1e3},cm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:25,lightHeight:50,minDistance:.1,shadowSize:100,scaleFactor:100},m:{cameraDistance:10,near:.01,far:2e3,floorSize:50,lightDistance:25,lightHeight:50,minDistance:.001,shadowSize:100,scaleFactor:1},inches:{cameraDistance:15,near:.1,far:2e3,floorSize:80,lightDistance:20,lightHeight:40,minDistance:.1,shadowSize:80,scaleFactor:39.37},feet:{cameraDistance:8,near:.1,far:2e3,floorSize:40,lightDistance:15,lightHeight:30,minDistance:.1,shadowSize:60,scaleFactor:3.28084}}[r];return{sceneScale:r,camera:{position:_optionalChain([e, 'access', _40 => _40.camera, 'optionalAccess', _41 => _41.position])||new p.Vector3(-n.cameraDistance,-n.cameraDistance,n.cameraDistance),fov:_optionalChain([e, 'access', _42 => _42.camera, 'optionalAccess', _43 => _43.fov])||20,near:_optionalChain([e, 'access', _44 => _44.camera, 'optionalAccess', _45 => _45.near])||n.near,far:_optionalChain([e, 'access', _46 => _46.camera, 'optionalAccess', _47 => _47.far])||n.far,target:_optionalChain([e, 'access', _48 => _48.camera, 'optionalAccess', _49 => _49.target])||new p.Vector3(0,0,0)},lighting:{enableSunlight:_nullishCoalesce(_optionalChain([e, 'access', _50 => _50.lighting, 'optionalAccess', _51 => _51.enableSunlight]), () => (!0)),sunlightIntensity:_optionalChain([e, 'access', _52 => _52.lighting, 'optionalAccess', _53 => _53.sunlightIntensity])||1,sunlightPosition:_optionalChain([e, 'access', _54 => _54.lighting, 'optionalAccess', _55 => _55.sunlightPosition])||new p.Vector3(n.lightDistance,n.lightDistance,n.lightHeight),ambientLightColor:_optionalChain([e, 'access', _56 => _56.lighting, 'optionalAccess', _57 => _57.ambientLightColor])||new p.Color(4210752),ambientLightIntensity:_optionalChain([e, 'access', _58 => _58.lighting, 'optionalAccess', _59 => _59.ambientLightIntensity])||1,sunlightColor:_optionalChain([e, 'access', _60 => _60.lighting, 'optionalAccess', _61 => _61.sunlightColor])||16777215},environment:{hdrPath:_optionalChain([e, 'access', _62 => _62.environment, 'optionalAccess', _63 => _63.hdrPath])||"/baseHDR.hdr",backgroundColor:_optionalChain([e, 'access', _64 => _64.environment, 'optionalAccess', _65 => _65.backgroundColor])||new p.Color(15790320),enableEnvironmentLighting:_nullishCoalesce(_optionalChain([e, 'access', _66 => _66.environment, 'optionalAccess', _67 => _67.enableEnvironmentLighting]), () => (!0)),sceneUp:_optionalChain([e, 'access', _68 => _68.environment, 'optionalAccess', _69 => _69.sceneUp])||Z,showEnvironment:_nullishCoalesce(_optionalChain([e, 'access', _70 => _70.environment, 'optionalAccess', _71 => _71.showEnvironment]), () => (!1))},floor:{enabled:_nullishCoalesce(_optionalChain([e, 'access', _72 => _72.floor, 'optionalAccess', _73 => _73.enabled]), () => (!1)),size:_optionalChain([e, 'access', _74 => _74.floor, 'optionalAccess', _75 => _75.size])||n.floorSize,color:_optionalChain([e, 'access', _76 => _76.floor, 'optionalAccess', _77 => _77.color])||new p.Color(8421504),roughness:_optionalChain([e, 'access', _78 => _78.floor, 'optionalAccess', _79 => _79.roughness])||.7,metalness:_optionalChain([e, 'access', _80 => _80.floor, 'optionalAccess', _81 => _81.metalness])||0,receiveShadow:_nullishCoalesce(_optionalChain([e, 'access', _82 => _82.floor, 'optionalAccess', _83 => _83.receiveShadow]), () => (!0))},render:{enableShadows:_nullishCoalesce(_optionalChain([e, 'access', _84 => _84.render, 'optionalAccess', _85 => _85.enableShadows]), () => (!0)),shadowMapSize:_optionalChain([e, 'access', _86 => _86.render, 'optionalAccess', _87 => _87.shadowMapSize])||2048,antialias:_nullishCoalesce(_optionalChain([e, 'access', _88 => _88.render, 'optionalAccess', _89 => _89.antialias]), () => (!0)),pixelRatio:_optionalChain([e, 'access', _90 => _90.render, 'optionalAccess', _91 => _91.pixelRatio])||Math.min(window.devicePixelRatio,2),toneMapping:_optionalChain([e, 'access', _92 => _92.render, 'optionalAccess', _93 => _93.toneMapping])||p.NeutralToneMapping,toneMappingExposure:_optionalChain([e, 'access', _94 => _94.render, 'optionalAccess', _95 => _95.toneMappingExposure])||1,preserveDrawingBuffer:_nullishCoalesce(_optionalChain([e, 'access', _96 => _96.render, 'optionalAccess', _97 => _97.preserveDrawingBuffer]), () => (!1)),ambientOcclusion:_nullishCoalesce(_optionalChain([e, 'access', _98 => _98.render, 'optionalAccess', _99 => _99.ambientOcclusion]), () => (!1)),aoIntensity:_nullishCoalesce(_optionalChain([e, 'access', _100 => _100.render, 'optionalAccess', _101 => _101.aoIntensity]), () => (1))},controls:{enableDamping:_nullishCoalesce(_optionalChain([e, 'access', _102 => _102.controls, 'optionalAccess', _103 => _103.enableDamping]), () => (!1)),dampingFactor:_optionalChain([e, 'access', _104 => _104.controls, 'optionalAccess', _105 => _105.dampingFactor])||.05,autoRotate:_nullishCoalesce(_optionalChain([e, 'access', _106 => _106.controls, 'optionalAccess', _107 => _107.autoRotate]), () => (!1)),autoRotateSpeed:_optionalChain([e, 'access', _108 => _108.controls, 'optionalAccess', _109 => _109.autoRotateSpeed])||.5,enableZoom:_nullishCoalesce(_optionalChain([e, 'access', _110 => _110.controls, 'optionalAccess', _111 => _111.enableZoom]), () => (!0)),enablePan:_nullishCoalesce(_optionalChain([e, 'access', _112 => _112.controls, 'optionalAccess', _113 => _113.enablePan]), () => (!0)),minDistance:_optionalChain([e, 'access', _114 => _114.controls, 'optionalAccess', _115 => _115.minDistance])||n.minDistance,maxDistance:_optionalChain([e, 'access', _116 => _116.controls, 'optionalAccess', _117 => _117.maxDistance])||1/0},grid:{enabled:_nullishCoalesce(_optionalChain([e, 'access', _118 => _118.grid, 'optionalAccess', _119 => _119.enabled]), () => (!1)),cellSize:_nullishCoalesce(_optionalChain([e, 'access', _120 => _120.grid, 'optionalAccess', _121 => _121.cellSize]), () => (1)),majorEvery:_nullishCoalesce(_optionalChain([e, 'access', _122 => _122.grid, 'optionalAccess', _123 => _123.majorEvery]), () => (10)),cellColor:_nullishCoalesce(_optionalChain([e, 'access', _124 => _124.grid, 'optionalAccess', _125 => _125.cellColor]), () => (8947848)),majorColor:_nullishCoalesce(_optionalChain([e, 'access', _126 => _126.grid, 'optionalAccess', _127 => _127.majorColor]), () => (4473924)),fadeDistance:_nullishCoalesce(_optionalChain([e, 'access', _128 => _128.grid, 'optionalAccess', _129 => _129.fadeDistance]), () => (100)),plane:_nullishCoalesce(_optionalChain([e, 'access', _130 => _130.grid, 'optionalAccess', _131 => _131.plane]), () => (mt(_nullishCoalesce(_optionalChain([e, 'access', _132 => _132.environment, 'optionalAccess', _133 => _133.sceneUp]), () => (Z)))))},gizmo:{enabled:_nullishCoalesce(_optionalChain([e, 'access', _134 => _134.gizmo, 'optionalAccess', _135 => _135.enabled]), () => (!1))},edges:{enabled:_nullishCoalesce(_optionalChain([e, 'access', _136 => _136.edges, 'optionalAccess', _137 => _137.enabled]), () => (!1)),color:_nullishCoalesce(_optionalChain([e, 'access', _138 => _138.edges, 'optionalAccess', _139 => _139.color]), () => (2236962)),width:_nullishCoalesce(_optionalChain([e, 'access', _140 => _140.edges, 'optionalAccess', _141 => _141.width]), () => (1.5)),thresholdAngle:_nullishCoalesce(_optionalChain([e, 'access', _142 => _142.edges, 'optionalAccess', _143 => _143.thresholdAngle]), () => (30))},measure:{enabled:_nullishCoalesce(_optionalChain([e, 'access', _144 => _144.measure, 'optionalAccess', _145 => _145.enabled]), () => (!1)),snapPixels:_optionalChain([e, 'access', _146 => _146.measure, 'optionalAccess', _147 => _147.snapPixels]),color:_optionalChain([e, 'access', _148 => _148.measure, 'optionalAccess', _149 => _149.color]),labelClassName:_optionalChain([e, 'access', _150 => _150.measure, 'optionalAccess', _151 => _151.labelClassName]),format:_optionalChain([e, 'access', _152 => _152.measure, 'optionalAccess', _153 => _153.format])},events:{onBackgroundClicked:_optionalChain([e, 'access', _154 => _154.events, 'optionalAccess', _155 => _155.onBackgroundClicked]),onObjectSelected:_optionalChain([e, 'access', _156 => _156.events, 'optionalAccess', _157 => _157.onObjectSelected]),onMeshMetadataClicked:_optionalChain([e, 'access', _158 => _158.events, 'optionalAccess', _159 => _159.onMeshMetadataClicked]),onMeshDoubleClicked:_optionalChain([e, 'access', _160 => _160.events, 'optionalAccess', _161 => _161.onMeshDoubleClicked]),selectionColor:_optionalChain([e, 'access', _162 => _162.events, 'optionalAccess', _163 => _163.selectionColor])||"#ff0000",enableEventHandlers:_nullishCoalesce(_optionalChain([e, 'access', _164 => _164.events, 'optionalAccess', _165 => _165.enableEventHandlers]), () => (!0)),enableKeyboardControls:_nullishCoalesce(_optionalChain([e, 'access', _166 => _166.events, 'optionalAccess', _167 => _167.enableKeyboardControls]), () => (!0)),enableClickToFocus:_nullishCoalesce(_optionalChain([e, 'access', _168 => _168.events, 'optionalAccess', _169 => _169.enableClickToFocus]), () => (!0)),enableDoubleClickZoom:_nullishCoalesce(_optionalChain([e, 'access', _170 => _170.events, 'optionalAccess', _171 => _171.enableDoubleClickZoom]), () => (!0)),onReady:_optionalChain([e, 'access', _172 => _172.events, 'optionalAccess', _173 => _173.onReady]),onFrame:_optionalChain([e, 'access', _174 => _174.events, 'optionalAccess', _175 => _175.onFrame])}}}var pt=new Set(["grid","floor","label-layer","measure"]);function ft(e){let r=e;for(;r;){if(typeof r.userData.id=="string"&&pt.has(r.userData.id))return!0;r=r.parent}return!1}function ne(e){let r=new p.Box3;return e.traverse(t=>{let n=t;t.visible&&!ft(t)&&n.geometry&&r.expandByObject(t)}),r}function ht(e,r){if(r.isEmpty())return;let t=r.getCenter(new p.Vector3),n=r.getSize(new p.Vector3).length()*.5*1.2,o=e.shadow.camera;o.left=-n,o.right=n,o.top=n,o.bottom=-n,e.target.position.copy(t),e.target.updateMatrixWorld();let a=e.position.distanceTo(t);o.near=Math.max(n*.01,a-n),o.far=a+n,o.updateProjectionMatrix()}function gt(e){let r=new p.Scene,t=typeof e.environment.backgroundColor=="string"?new p.Color(e.environment.backgroundColor):e.environment.backgroundColor;return r.background=t||null,r}function bt(e,r,t,n,o=200){let a=e.position.clone(),i=r.target.clone(),s=performance.now(),l=d=>1-Math.pow(1-d,3),c=()=>{let d=performance.now()-s,u=l(Math.min(d/o,1));e.position.lerpVectors(a,t,u),r.target.lerpVectors(i,n,u),r.update(),u<1&&requestAnimationFrame(c)};requestAnimationFrame(c)}function yt(e,r,t,n,o,a,i,s,l,c,d,u){let m=null,E=performance.now(),f=()=>{let{width:b,height:g}=i();if(b===0||g===0)return;let R=Math.min(window.devicePixelRatio,2),H=Math.round(b*R),P=Math.round(g*R);(e.domElement.width!==H||e.domElement.height!==P)&&(e.setPixelRatio(R),e.setSize(b,g,!1),t.aspect=b/g,t.updateProjectionMatrix(),o.updateAspect(b,g),_optionalChain([d, 'optionalCall', _176 => _176(), 'optionalAccess', _177 => _177.setSize, 'call', _178 => _178(b,g,R)]),_optionalChain([u, 'optionalAccess', _179 => _179.setSize, 'call', _180 => _180(b,g)]))},x=function(){m=requestAnimationFrame(x);let b=performance.now(),g=(b-E)/1e3;E=b,f(),(a.enableDamping||a.autoRotate)&&a.update(),l&&l.update(n().position),c&&c.update(g),_optionalChain([s, 'optionalCall', _181 => _181(g)]);let R=n(),H=_optionalChain([d, 'optionalCall', _182 => _182()]);H?(H.setCamera(R),H.render(g)):e.render(r,R),u&&u.render(r,R),c&&c.render(e)};return{animate:x,dispose:()=>{m!==null&&(cancelAnimationFrame(m),m=null)}}}function Rt(e,r){r.environment.enableEnvironmentLighting?new (0, _HDRLoaderjs.HDRLoader)().load(r.environment.hdrPath||"/baseHDR.hdr",function(t){if(!_optionalChain([t, 'optionalAccess', _183 => _183.image])){_chunkJZFH67EScjs.e.call(void 0, ).warn("HDR loaded without image data; skipping environment map."),_optionalChain([r, 'access', _184 => _184.events, 'access', _185 => _185.onReady, 'optionalCall', _186 => _186()]);return}t.mapping=p.EquirectangularReflectionMapping,e.environment=t,r.environment.showEnvironment&&(e.background=t),_optionalChain([r, 'access', _187 => _187.events, 'access', _188 => _188.onReady, 'optionalCall', _189 => _189()])},void 0,function(t){_chunkJZFH67EScjs.e.call(void 0, ).warn("HDR texture could not be loaded, falling back to basic lighting:",t),_optionalChain([r, 'access', _190 => _190.events, 'access', _191 => _191.onReady, 'optionalCall', _192 => _192()])}):_optionalChain([r, 'access', _193 => _193.events, 'access', _194 => _194.onReady, 'optionalCall', _195 => _195()])}function Tt(e,r){let t=new p.AmbientLight(r.lighting.ambientLightColor,r.lighting.ambientLightIntensity);if(e.add(t),!r.lighting.enableSunlight)return null;let n=new p.DirectionalLight(_nullishCoalesce(r.lighting.sunlightColor, () => (16777215)),r.lighting.sunlightIntensity),o=r.lighting.sunlightPosition;return o&&n.position.set(o.x,o.y,o.z),r.render.enableShadows?(n.castShadow=!0,n.shadow.mapSize.width=r.render.shadowMapSize||2048,n.shadow.mapSize.height=r.render.shadowMapSize||2048,n.shadow.bias=-1e-4,n.shadow.normalBias=.02,n.shadow.radius=4,e.add(n),e.add(n.target),n):(e.add(n),null)}function wt(e,r){let t=r.floor.size,n=new p.PlaneGeometry(t,t),o=typeof r.floor.color=="string"?new p.Color(r.floor.color):r.floor.color,a=new p.MeshStandardMaterial({color:o,roughness:r.floor.roughness,metalness:r.floor.metalness,side:p.DoubleSide}),i=new p.Mesh(n,a);i.userData.id="floor",i.name="floor";let s=(_optionalChain([r, 'access', _196 => _196.environment, 'optionalAccess', _197 => _197.sceneUp])||Z).clone().normalize();i.quaternion.setFromUnitVectors(new p.Vector3(0,0,1),s),i.position.set(0,0,0),r.floor.receiveShadow&&r.render.enableShadows&&(i.receiveShadow=!0),e.add(i)}function Ht(e,r){let t=r.parentElement,n=t?t.clientWidth:window.innerWidth,o=t?t.clientHeight:window.innerHeight,a=new p.PerspectiveCamera(e.camera.fov,n/o,e.camera.near,e.camera.far),i=e.camera.position;return i&&a.position.set(i.x,i.y,i.z),a}function vt(e,r){let t=new p.WebGLRenderer({antialias:r.render.antialias,canvas:e,alpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:r.render.preserveDrawingBuffer,logarithmicDepthBuffer:!0}),n=e.parentElement,o=n?n.clientWidth:window.innerWidth,a=n?n.clientHeight:window.innerHeight;return n&&(e.style.width="100%",e.style.height="100%",e.style.display="block"),t.setSize(o,a,!1),t.setPixelRatio(r.render.pixelRatio||Math.min(window.devicePixelRatio,2)),r.render.enableShadows&&(t.shadowMap.enabled=!0,t.shadowMap.type=p.VSMShadowMap),t.toneMapping=r.render.toneMapping,t.toneMappingExposure=r.render.toneMappingExposure||1,t.outputColorSpace=p.SRGBColorSpace,t.sortObjects=!0,t}function Mt(e,r,t,n,o,a){let i=new Set,s=new Map,l=new p.Raycaster,c=new p.Vector2,d=new p.Vector2,u=y=>{let w=y;for(;w;){if(!w.visible)return!1;w=w.parent}return!0},m=()=>{let y=ne(r);if(y.isEmpty()){_chunkJZFH67EScjs.e.call(void 0, ).warn("No objects to fit to view");return}let w=y.getCenter(new p.Vector3),C=y.getSize(new p.Vector3),O=Math.max(C.x,C.y,C.z),h=n.fov*(Math.PI/180),T=O/(2*Math.tan(h/2));T*=1.5;let M=n.position.clone().sub(o.target);M.lengthSq()<1e-12&&M.set(.8,1,1.2),M.normalize(),n.position.copy(w.clone().add(M.multiplyScalar(T))),o.target.copy(w),o.update()},E=typeof a.events.selectionColor=="string"?new p.Color(a.events.selectionColor):a.events.selectionColor instanceof p.Color?a.events.selectionColor:new p.Color("#ff0000"),f=()=>{i.forEach(y=>{let w=y;if(s.has(y)){let C=s.get(y),O=w.material;O instanceof p.Material?O.dispose():Array.isArray(O)&&O.forEach(h=>h.dispose()),w.material=C,s.delete(y)}}),i.clear()},x=y=>{let w=y;if(!(w.material instanceof p.Material))return!1;s.set(y,w.material);let C=w.material.clone();return y instanceof p.Mesh&&"emissive"in C?C.emissive=E.clone():"color"in C&&(C.color=E.clone()),w.material=C,!0},S=()=>{let y=ne(r),w=y.isEmpty()?1:y.getSize(new p.Vector3).length();l.params.Points.threshold=w*.01},b=y=>{d.set(y.clientX,y.clientY)},g=y=>{let w=new p.Vector2(y.clientX,y.clientY);if(d.distanceTo(w)>5)return;let C=e.getBoundingClientRect();c.x=(y.clientX-C.left)/C.width*2-1,c.y=-((y.clientY-C.top)/C.height)*2+1,S(),l.setFromCamera(c,t());let O=l.intersectObjects(r.children,!0).filter(h=>u(h.object));if(O.length>0){let h=O[0].object;i.has(h)||(f(),i.add(h),x(h),_optionalChain([a, 'access', _198 => _198.events, 'optionalAccess', _199 => _199.onObjectSelected, 'optionalCall', _200 => _200(h)]),h instanceof p.Mesh&&Object.keys(h.userData).length>0&&_optionalChain([a, 'access', _201 => _201.events, 'optionalAccess', _202 => _202.onMeshMetadataClicked, 'optionalCall', _203 => _203(h.userData)]))}else f(),_optionalChain([a, 'access', _204 => _204.events, 'optionalAccess', _205 => _205.onBackgroundClicked, 'optionalCall', _206 => _206({x:c.x,y:c.y})])},R=y=>{let w=e.getBoundingClientRect();c.x=(y.clientX-w.left)/w.width*2-1,c.y=-((y.clientY-w.top)/w.height)*2+1,S(),l.setFromCamera(c,t());let C=l.intersectObjects(r.children,!0).filter(D=>u(D.object));if(C.length===0)return;let O=C[0].object;if(_optionalChain([a, 'access', _207 => _207.events, 'optionalAccess', _208 => _208.onMeshDoubleClicked, 'optionalCall', _209 => _209(O)]),!_optionalChain([a, 'access', _210 => _210.events, 'optionalAccess', _211 => _211.enableDoubleClickZoom]))return;let h=new p.Box3().setFromObject(O);if(h.isEmpty())return;let T=h.getCenter(new p.Vector3),M=h.getSize(new p.Vector3),k=Math.max(M.x,M.y,M.z),U=n.fov*(Math.PI/180),W=k/(2*Math.tan(U/2))*1.5,K=n.position.clone().sub(o.target).normalize(),se=T.clone().add(K.multiplyScalar(W));bt(n,o,se,T)},H=y=>{if(_optionalChain([a, 'access', _212 => _212.events, 'optionalAccess', _213 => _213.enableKeyboardControls]))switch(y.key.toLowerCase()){case"f":y.preventDefault(),m();break;case"escape":y.preventDefault(),f();break;case" ":y.preventDefault(),m();break}};return _optionalChain([a, 'access', _214 => _214.events, 'optionalAccess', _215 => _215.enableClickToFocus])&&(e.addEventListener("mousedown",b),e.addEventListener("click",g),e.addEventListener("dblclick",R)),_optionalChain([a, 'access', _216 => _216.events, 'optionalAccess', _217 => _217.enableKeyboardControls])&&(e.setAttribute("tabindex","0"),e.addEventListener("keydown",H)),{dispose:()=>{e.removeEventListener("mousedown",b),e.removeEventListener("click",g),e.removeEventListener("dblclick",R),e.removeEventListener("keydown",H),f()},fitToView:m,clearSelection:f}}function Ct(e,r,t){let n=new (0, _OrbitControlsjs.OrbitControls)(e,r),o=t.camera.target;return o&&n.target.set(o.x,o.y,o.z),n.enableDamping=t.controls.enableDamping||!1,n.dampingFactor=t.controls.dampingFactor||.05,n.autoRotate=t.controls.autoRotate||!1,n.autoRotateSpeed=t.controls.autoRotateSpeed||.5,n.enableZoom=_nullishCoalesce(t.controls.enableZoom, () => (!0)),n.enablePan=_nullishCoalesce(t.controls.enablePan, () => (!0)),n.minDistance=t.controls.minDistance||.001,n.maxDistance=t.controls.maxDistance||1/0,n.screenSpacePanning=!1,n.maxPolarAngle=Math.PI,n.update(),n}var It={};_chunkJZFH67EScjs.a.call(void 0, It,{CONCRETE_MATERIAL:()=>At,EMISSIVE_MATERIAL:()=>xt,GLASS_MATERIAL:()=>Lt,METAL_MATERIAL:()=>St,PLASTIC_MATERIAL:()=>Dt,RUBBER_MATERIAL:()=>Pt,WOOD_MATERIAL:()=>Ot});var xt=new L.MeshPhysicalMaterial({color:0,emissive:new L.Color(16777215),emissiveIntensity:5,metalness:0,roughness:.2,clearcoat:.3,clearcoatRoughness:.2,depthWrite:!0,depthTest:!0,transparent:!1,alphaTest:0,polygonOffset:!0,side:L.FrontSide,dithering:!0}),St=new L.MeshPhysicalMaterial({color:new L.Color(0),metalness:.9,roughness:.3,envMapIntensity:1.2,clearcoat:.3,clearcoatRoughness:.2,reflectivity:1,ior:2.5,thickness:1,depthWrite:!0,transparent:!1,alphaTest:0,depthTest:!0,polygonOffset:!0,side:L.FrontSide,dithering:!0}),At=new L.MeshPhysicalMaterial({color:new L.Color(13421772),metalness:0,roughness:.92,envMapIntensity:.15,clearcoat:.05,clearcoatRoughness:.9,reflectivity:.15,transmission:0,ior:1.45,thickness:0,depthWrite:!0,transparent:!1,alphaTest:.5,depthTest:!0,polygonOffset:!0,side:L.FrontSide,dithering:!0}),Dt=new L.MeshPhysicalMaterial({color:new L.Color(16777215),metalness:0,roughness:.3,envMapIntensity:.5,clearcoat:.5,clearcoatRoughness:.1,reflectivity:.5,ior:1.4,transmission:0,transparent:!1,depthWrite:!0,side:L.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Lt=new L.MeshPhysicalMaterial({color:new L.Color(16777215),metalness:0,roughness:0,transmission:.95,transparent:!0,opacity:.3,envMapIntensity:1,clearcoat:1,clearcoatRoughness:0,ior:1.52,reflectivity:.9,thickness:1,side:L.DoubleSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Pt=new L.MeshPhysicalMaterial({color:new L.Color(1710618),metalness:0,roughness:.9,envMapIntensity:.2,clearcoat:.1,clearcoatRoughness:.8,reflectivity:.2,ior:1.3,transmission:0,depthWrite:!0,side:L.FrontSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Ot=new L.MeshPhysicalMaterial({color:new L.Color(8934707),metalness:0,roughness:.7,envMapIntensity:.3,clearcoat:.3,clearcoatRoughness:.4,reflectivity:.3,ior:1.3,transmission:0,depthWrite:!0,side:L.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});function J(e,r,t,n=!0){return{x:e,y:r,z:t}}var Ft="#ffffff",re=12,jt=4e-4,kt=12,_t=.05;function we(e,r={}){if(!e||e.length===0)return[];let{rhino:t,applyTransforms:n=!0}=r,o=[];for(let a of e)switch(a.kind){case"curve":{let i=Nt(a,t,n);i&&o.push(i);break}case"point":{o.push(Ut(a,n));break}default:{let i=a;_chunkJZFH67EScjs.e.call(void 0, ).warn(`Skipping unknown display item kind: ${String(i.kind)}`);break}}return o}var Gt=2;function Nt(e,r,t){if(!r)return _chunkJZFH67EScjs.e.call(void 0, ).warn("No rhino3dm instance provided; skipping curve display item."),null;let n=Wt(e.json,r);if(!n)return null;let o=$t(n,t);if(o.length<2)return null;let a=[];for(let u of o)a.push(u.x,u.y,u.z);let i=new _LineGeometryjs.LineGeometry;i.setPositions(a);let s=He(e.color,e.opacity),l=new (0, _LineMaterialjs.LineMaterial)({color:s.color}),c=l;c.linewidth=_nullishCoalesce(e.width, () => (Gt)),c.transparent=s.transparent,c.opacity=s.opacity;let d=new (0, _Line2js.Line2)(i,l);return d.computeLineDistances(),d.name=e.name,d.userData={id:e.id,layer:e.layer,kind:"curve",metadata:e.metadata},d}function Ut(e,r){let{x:t,y:n,z:o}=J(e.position.X,e.position.Y,e.position.Z,r),a=new j.BufferGeometry;a.setAttribute("position",new j.Float32BufferAttribute([t,n,o],3));let i=new j.PointsMaterial({...He(e.color,e.opacity),size:6,sizeAttenuation:!1}),s=new j.Points(a,i);return s.name=e.name,s.userData={id:e.id,layer:e.layer,kind:"point",metadata:e.metadata},s}function Wt(e,r){try{let t=JSON.parse(e),n=r.CommonObject.decode(t);return n&&typeof n.pointAt=="function"?n:(_chunkJZFH67EScjs.e.call(void 0, ).warn("Decoded display-item JSON is not a curve; skipping."),null)}catch(t){return _chunkJZFH67EScjs.e.call(void 0, ).warn("Failed to decode curve display item JSON:",t),null}}function $t(e,r){let t=Yt(e,r);return t||Xt(e,r)}function Yt(e,r){if(!e.isPolyline())return null;let t=e.tryGetPolyline(),n=Array.isArray(t)?t[1]:t;if(!n||typeof n.count!="number"||n.count<2)return null;let o=[];for(let a=0;a<n.count;a++){let i=n.get(a),{x:s,y:l,z:c}=J(i[0],i[1],i[2],r);o.push(new j.Vector3(s,l,c))}return o}function Xt(e,r){let t=e.domain,n=t[0],a=t[1]-n,i=c=>{let d=e.pointAt(c),{x:u,y:m,z:E}=J(d[0],d[1],d[2],r);return new j.Vector3(u,m,E)},s=qt(e),l=[i(n)];for(let c=0;c<re;c++){let d=n+a*c/re,u=n+a*(c+1)/re;oe(d,i(d),u,i(u),i,s,kt,l),l.push(i(u))}return l}function oe(e,r,t,n,o,a,i,s){if(i<=0)return;let l=(e+t)/2,c=o(l),d=Jt(c,r,n),u=Zt(r,c,n);d<=a&&u<=_t||(oe(e,r,l,c,o,a,i-1,s),s.push(c),oe(l,c,t,n,o,a,i-1,s))}function qt(e){let r=e.getBoundingBox(),t=r.min,n=r.max,o=Math.hypot(n[0]-t[0],n[1]-t[1],n[2]-t[2]);return Math.max(o*jt,1e-6)}function Zt(e,r,t){let n=r.clone().sub(e),o=t.clone().sub(r),a=n.length(),i=o.length();if(a===0||i===0)return 0;let s=Math.max(-1,Math.min(1,n.dot(o)/(a*i)));return Math.acos(s)}function Jt(e,r,t){let n=t.clone().sub(r),o=n.lengthSq();if(o===0)return e.distanceTo(r);let a=Math.max(0,Math.min(1,e.clone().sub(r).dot(n)/o)),i=r.clone().addScaledVector(n,a);return e.distanceTo(i)}function He(e,r){let t=_nullishCoalesce(r, () => (1));return{color:new j.Color(_nullishCoalesce(e, () => (Ft))),transparent:t<1,opacity:t}}var ve=1096174675,Me= exports.t =1,ae= exports.u =1,Ce=12,xe=56;function ie(e){let r=Kt(e),t=new DataView(r.buffer,r.byteOffset,r.byteLength);if(r.byteLength<Ce)throw N("Blob too small to contain SLVA header.",{expectedBytes:Ce,availableBytes:r.byteLength});let n=0,o=t.getUint32(n,!0);if(n+=4,o!==ve)throw N(`Invalid SLVA magic: 0x${o.toString(16)}`,{expectedMagic:`0x${ve.toString(16)}`,actualMagic:`0x${o.toString(16)}`});let a=t.getUint32(n,!0);if(n+=4,a!==Me)throw N(`Unsupported SLVA version: ${a}`,{expectedVersion:Me,actualVersion:a});let i=t.getUint32(n,!0);if(n+=4,n+i>r.byteLength)throw N("Insufficient data to read metadata JSON.",{expectedBytes:i,availableBytes:r.byteLength-n,offset:n});let s=r.subarray(n,n+i);n+=i;let l;try{l=JSON.parse(Qt(s))}catch(h){throw N(`Failed to parse metadata JSON: ${h instanceof Error?h.message:String(h)}`,{metadataLen:i})}if(n+xe>r.byteLength)throw N("Insufficient data to read geometry header.",{expectedBytes:xe,availableBytes:r.byteLength-n,offset:n});let c=t.getUint32(n,!0);n+=4;let d=t.getFloat64(n,!0);n+=8;let u=t.getFloat64(n,!0);n+=8;let m=t.getFloat64(n,!0);n+=8;let E=t.getFloat64(n,!0);n+=8;let f=t.getFloat64(n,!0);n+=8;let x=t.getFloat64(n,!0);n+=8;let S=t.getUint32(n,!0);n+=4;let b=(c&ae)!==0,g=S*3,H=g*(b?4:2);if(n+H>r.byteLength)throw N("Insufficient data to read vertices.",{expectedBytes:H,availableBytes:r.byteLength-n,offset:n,useFloat32:b,vertexCount:S});let P=r.byteOffset+n,y=b?tn(r.buffer,P,g):en(r.buffer,P,g);if(n+=H,n+4>r.byteLength)throw N("Insufficient data to read index count.",{expectedBytes:4,availableBytes:r.byteLength-n,offset:n});let w=t.getUint32(n,!0);n+=4;let C=w*4;if(n+C>r.byteLength)throw N("Insufficient data to read indices.",{expectedBytes:C,availableBytes:r.byteLength-n,offset:n,indexCount:w});let O=nn(r.buffer,r.byteOffset+n,w);return{metadata:l,flags:c,vertices:y,indices:O,origin:[d,u,m],scale:[E,f,x]}}function Kt(e){return typeof e=="string"?_chunkJZFH67EScjs.o.call(void 0, e):e instanceof Uint8Array?e:new Uint8Array(e)}function Qt(e){if(typeof TextDecoder<"u")return new TextDecoder("utf-8").decode(e);if(typeof globalThis.Buffer<"u")return globalThis.Buffer.from(e).toString("utf-8");throw new (0, _chunkJZFH67EScjs.d)("No UTF-8 decoder available in this environment.",_chunkJZFH67EScjs.c.INVALID_STATE)}function en(e,r,t){if(t===0)return new Int16Array(0);if(r%2===0)return new Int16Array(e,r,t);let n=new Uint8Array(t*2);return n.set(new Uint8Array(e,r,t*2)),new Int16Array(n.buffer)}function tn(e,r,t){if(t===0)return new Float32Array(0);if(r%4===0)return new Float32Array(e,r,t);let n=new Uint8Array(t*4);return n.set(new Uint8Array(e,r,t*4)),new Float32Array(n.buffer)}function nn(e,r,t){if(t===0)return new Uint32Array(0);if(r%4===0)return new Uint32Array(e,r,t);let n=new Uint8Array(t*4);return n.set(new Uint8Array(e,r,t*4)),new Uint32Array(n.buffer)}function N(e,r){return new (0, _chunkJZFH67EScjs.d)(e,_chunkJZFH67EScjs.c.VALIDATION_ERROR,{context:r})}async function Se(e,r){let{debug:t=!1}=_nullishCoalesce(r, () => ({})),n=t?performance.now():0;try{let o=performance.now(),a=JSON.parse(e),i=performance.now()-o;return await rn(a,r,{parseTime:i,perfStart:n})}catch(o){return _chunkJZFH67EScjs.e.call(void 0, ).error("Error parsing mesh batch:",o),[]}}async function rn(e,r,t){let{mergeByMaterial:n=!0,applyTransforms:o=!0,scaleFactor:a=1,debug:i=!1}=_nullishCoalesce(r, () => ({})),{parseTime:s=0,perfStart:l=i?performance.now():0}=_nullishCoalesce(t, () => ({}));try{let c=performance.now(),d=ie(e.compressedData),u=performance.now()-c,m=i?dn(e.compressedData):0;return Ae(d,{mergeByMaterial:n,applyTransforms:o,scaleFactor:a,debug:i,parseTime:s,decodeTime:u,perfStart:l,blobBytes:m,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}catch(c){return _chunkJZFH67EScjs.e.call(void 0, ).error("Error parsing mesh batch object:",c),[]}}async function gr(e,r){let{mergeByMaterial:t=!0,applyTransforms:n=!0,scaleFactor:o=1,debug:a=!1}=_nullishCoalesce(r, () => ({})),i=a?performance.now():0;try{let s=performance.now(),l=ie(e),c=performance.now()-s,d=e.byteLength;return Ae(l,{mergeByMaterial:t,applyTransforms:n,scaleFactor:o,debug:a,parseTime:0,decodeTime:c,perfStart:i,blobBytes:d})}catch(s){return _chunkJZFH67EScjs.e.call(void 0, ).error("Error parsing mesh batch blob:",s),[]}}function Ae(e,r){let{mergeByMaterial:t,applyTransforms:n,scaleFactor:o,debug:a,parseTime:i,decodeTime:s,perfStart:l,blobBytes:c,fallback:d}=r,u=_nullishCoalesce(_nullishCoalesce(e.metadata.materials, () => (_optionalChain([d, 'optionalAccess', _218 => _218.materials]))), () => ([])),m=_nullishCoalesce(_nullishCoalesce(e.metadata.groups, () => (_optionalChain([d, 'optionalAccess', _219 => _219.groups]))), () => ([])),E=_nullishCoalesce(e.metadata.sourceComponentId, () => (_optionalChain([d, 'optionalAccess', _220 => _220.sourceComponentId]))),f=(e.flags&ae)!==0,x=f?an(e.vertices,n):on(e.vertices,e.origin,e.scale,n);if(a){let H=e.vertices.byteLength+e.indices.byteLength;_chunkJZFH67EScjs.e.call(void 0, ).debug("Mesh Batch Stats:"),_chunkJZFH67EScjs.e.call(void 0, ).debug(` Materials: ${u.length} | Groups: ${m.length}`),_chunkJZFH67EScjs.e.call(void 0, ).debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),_chunkJZFH67EScjs.e.call(void 0, ).debug(` Format: ${f?"float32":"int16 quantized"}`),_chunkJZFH67EScjs.e.call(void 0, ).debug(` Blob: ${(c/1024/1024).toFixed(2)} MB | Geometry on wire: ${(H/1024/1024).toFixed(2)} MB`)}let S=performance.now(),b=u.map(sn),g=[];for(let H of m)if(t&&H.meshes.length>1){let P=ln(H,x,e.indices,b);P.userData.sourceComponentId=_nullishCoalesce(E, () => (null)),g.push(P)}else{let P=cn(H,x,e.indices,b);for(let y of P)y.userData.sourceComponentId=_nullishCoalesce(E, () => (null));g.push(...P)}if(o!==1)for(let H of g)H.scale.set(o,o,o);let R=performance.now()-S;if(a){let H=performance.now()-l;_chunkJZFH67EScjs.e.call(void 0, ).debug("Performance:"),i>0&&_chunkJZFH67EScjs.e.call(void 0, ).debug(` Parse JSON: ${i.toFixed(2)}ms`),_chunkJZFH67EScjs.e.call(void 0, ).debug(` Decode binary: ${s.toFixed(2)}ms`),_chunkJZFH67EScjs.e.call(void 0, ).debug(` Create Meshes: ${R.toFixed(2)}ms`),_chunkJZFH67EScjs.e.call(void 0, ).debug(` Total: ${H.toFixed(2)}ms`)}return Promise.resolve(g)}function on(e,r,t,n){let o=new Float32Array(e.length),a=r[0],i=r[1],s=r[2],l=t[0],c=t[1],d=t[2];for(let u=0;u<e.length;u+=3)o[u]=a+(e[u]+32767)*l,o[u+1]=i+(e[u+1]+32767)*c,o[u+2]=s+(e[u+2]+32767)*d;return o}function an(e,r){return e}function sn(e){let r=de(e.color);return new B.MeshPhysicalMaterial({color:r,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,side:B.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0})}function ln(e,r,t,n){let o=0,a=0;for(let f of e.meshes)o+=f.vertexCount,a+=f.indexCount;let i=new Float32Array(o*3),s=new Uint32Array(a),l=0,c=0;for(let f of e.meshes){let x=f.vertexStart*3,S=f.vertexCount*3;i.set(r.subarray(x,x+S),l*3);let b=t.subarray(f.indexStart,f.indexStart+f.indexCount),g=l-f.vertexStart;if(g===0)s.set(b,c);else for(let R=0;R<b.length;R++)s[c+R]=b[R]+g;l+=f.vertexCount,c+=f.indexCount}let d=new B.BufferGeometry;d.setAttribute("position",new B.BufferAttribute(i,3)),d.setIndex(new B.BufferAttribute(s,1)),d.computeVertexNormals();let u=new B.Mesh(d,n[e.materialId]),m=e.meshes[0],E=e.meshes.map(f=>f.name).filter(f=>f&&f.length>0);return u.name=E.length>0?E[0]:`merged_material_${e.materialId}`,u.castShadow=!0,u.receiveShadow=!0,u.userData={name:u.name,layer:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _221 => _221.layer]), () => ("")),originalIndex:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _222 => _222.originalIndex]), () => (0)),metadata:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _223 => _223.metadata]), () => ({})),mergedFrom:e.meshes.slice(1).map(f=>({name:f.name,layer:f.layer,originalIndex:f.originalIndex}))},u}function cn(e,r,t,n){let o=[];for(let a of e.meshes){let i=a.vertexStart*3,s=a.vertexCount*3,l=r.slice(i,i+s),c=t.subarray(a.indexStart,a.indexStart+a.indexCount),d=new Uint32Array(c.length),u=a.vertexStart;for(let f=0;f<c.length;f++)d[f]=c[f]-u;let m=new B.BufferGeometry;m.setAttribute("position",new B.BufferAttribute(l,3)),m.setIndex(new B.BufferAttribute(d,1)),m.computeVertexNormals();let E=new B.Mesh(m,n[e.materialId]);E.name=a.name,E.userData={name:a.name,layer:_nullishCoalesce(a.layer, () => ("")),originalIndex:a.originalIndex,metadata:_nullishCoalesce(a.metadata, () => ({}))},E.castShadow=!0,E.receiveShadow=!0,o.push(E)}return o}function dn(e){return Math.floor(e.length*3/4)}var un={Millimeters:1/1e3,Centimeters:1/100,Meters:1,Inches:1/39.37,Feet:1/3.28084},mn="Display";async function Hr(e,r){let t=performance.now(),n=[],{allowScaling:o=!0,allowAutoPosition:a=!0,rhino:i,debug:s=!1,parsing:l={}}=_nullishCoalesce(r, () => ({}));try{let c=o?En(e.modelunits):1;return await pn(e,n,c,l,i,s),a&&bn(n),n}catch(c){throw yn(c,n),c}finally{s&&Tn(t)}}function En(e){return _nullishCoalesce(un[e], () => (1))}async function pn(e,r,t,n,o,a){for(let i of e.values){let s=i.InnerTree;for(let l in s){let c=s[l];c&&await fn(c,r,t,n,o,a)}}}async function fn(e,r,t,n,o,a){for(let i of e){if(!i.type.includes(mn))continue;let s={mergeByMaterial:!0,applyTransforms:!0,debug:!1,...n},l=await Se(i.data,s),c=we(hn(i.data),{rhino:o,applyTransforms:s.applyTransforms}),d=[...l,...c];if(t!==1)for(let u of d)u.scale.set(t,t,t);r.push(...d),a&&_chunkJZFH67EScjs.e.call(void 0, ).debug(`Extracted ${l.length} meshes and ${c.length} items from batch`)}}function hn(e){return_optionalChain([(typeof e=="string"?gn(e):e), 'optionalAccess', _224 => _224.items])}function gn(e){try{return JSON.parse(e)}catch (e4){return}}function bn(e){if(e.length===0)return;let t=Y(e).min.y;ue(e,t)}function yn(e,r){_chunkJZFH67EScjs.e.call(void 0, ).error("An unexpected error occurred:",e),Rn(r)}function Rn(e){for(let r of e){let t=r;t.geometry&&t.geometry.dispose(),t.material&&(Array.isArray(t.material)?t.material.forEach(n=>n.dispose()):t.material.dispose())}}function Tn(e){let r=performance.now()-e;_chunkJZFH67EScjs.e.call(void 0, ).info("Time to process meshes:",`${r.toFixed(2)}ms`)}exports.a = Hn; exports.b = de; exports.c = ue; exports.d = Y; exports.e = me; exports.f = Ee; exports.g = pe; exports.h = X; exports.i = he; exports.j = qe; exports.k = On; exports.l = ge; exports.m = ye; exports.n = ct; exports.o = Te; exports.p = nr; exports.q = It; exports.r = we; exports.s = ve; exports.t = Me; exports.u = ae; exports.v = ie; exports.w = Se; exports.x = rn; exports.y = gr; exports.z = un; exports.A = Hr;
|
|
55
|
-
//# sourceMappingURL=chunk-
|
|
54
|
+
\u0394x ${q(r.x)} \u0394y ${q(r.y)} \u0394z ${q(r.z)}`;function lt(e){let r=e.object;return r instanceof A.Mesh?e.face?[e.face.a,e.face.b,e.face.c]:null:r instanceof A.Points?e.index!=null?[e.index]:null:r instanceof A.Line&&e.index!=null?[e.index,e.index+1]:null}function ct(e,r,t,n){let o=e.point.clone(),a=e.object,i=lt(e);if(!i||!a.geometry)return o;let s=a.geometry.attributes.position;if(!s)return o;let l=m=>{let E=m.clone().project(r);return new A.Vector2((E.x+1)/2*t.width,(1-E.y)/2*t.height)},c=l(o),d=o,u=n;for(let m of i){if(m>=s.count)continue;let f=new A.Vector3().fromBufferAttribute(s,m).applyMatrix4(a.matrixWorld),x=l(f).distanceTo(c);x<u&&(u=x,d=f)}return d}function Te(e){let{canvas:r,scene:t,getActiveCamera:n,labelLayer:o,options:a={}}=e,i=_nullishCoalesce(a.snapPixels, () => (at)),s=new A.Color(_nullishCoalesce(a.color, () => (it))),l=_nullishCoalesce(a.format, () => (st)),c=new A.Raycaster,d=new A.Vector2,u=!1,m=[],E=[],f=null,x=null,S=new A.PointsMaterial({color:s,size:8,sizeAttenuation:!1,depthTest:!1}),b=new A.PointsMaterial({color:s,size:11,sizeAttenuation:!1,depthTest:!1,transparent:!0,opacity:.5}),g=null,R=h=>{if(!h){g&&(g.visible=!1);return}if(!g){let T=new A.BufferGeometry;T.setAttribute("position",new A.Float32BufferAttribute([0,0,0],3)),g=new A.Points(T,b),g.renderOrder=1e3,g.userData.id="measure",g.raycast=()=>{},t.add(g)}g.position.copy(h),g.visible=!0},H=h=>{let T=new A.BufferGeometry;T.setAttribute("position",new A.Float32BufferAttribute([h.x,h.y,h.z],3));let M=new A.Points(T,S);return M.renderOrder=999,M.userData.id="measure",M.raycast=()=>{},t.add(M),M},P=()=>{m.length=0,E.forEach(h=>{h.geometry.dispose(),h.removeFromParent()}),E.length=0,f&&(f.geometry.dispose(),f.material.dispose(),f.removeFromParent(),f=null),_optionalChain([x, 'optionalAccess', _12 => _12.remove, 'call', _13 => _13()]),x=null},y=()=>{if(m.length!==2)return;let[h,T]=m,M=new _LineGeometryjs.LineGeometry;M.setPositions([h.x,h.y,h.z,T.x,T.y,T.z]);let k=new (0, _LineMaterialjs.LineMaterial)({color:s});k.linewidth=2,k.depthTest=!1,f=new (0, _Line2js.Line2)(M,k),f.renderOrder=998,f.userData.id="measure",f.raycast=()=>{},t.add(f);let U=h.clone().add(T).multiplyScalar(.5),W=new A.Vector3(Math.abs(T.x-h.x),Math.abs(T.y-h.y),Math.abs(T.z-h.z));x=o.addLabel(l(h.distanceTo(T),W),U,a.labelClassName)},w=h=>{let T=r.getBoundingClientRect();d.x=(h.clientX-T.left)/T.width*2-1,d.y=-((h.clientY-T.top)/T.height)*2+1;let M=n();c.setFromCamera(d,M);let k=M.position.length();c.params.Line={threshold:k*Re},c.params.Points={threshold:k*Re};let U=c.intersectObjects(t.children,!0).filter(W=>W.object.userData.id!=="measure"&&W.object.userData.id!=="grid");return U.length===0?null:ct(U[0],M,{width:T.width,height:T.height},i)};return{setEnabled:h=>{u=h,h||(P(),R(null))},isEnabled:()=>u,handleClick:h=>{if(!u)return!1;m.length===2&&P();let T=w(h);return T===null||(m.push(T),E.push(H(T)),m.length===2&&y()),!0},handleMove:h=>{u&&R(w(h))},clear:P,dispose:()=>{P(),g&&(g.geometry.dispose(),g.removeFromParent(),g=null),S.dispose(),b.dispose()}}}var _OrbitControlsjs = require('three/addons/controls/OrbitControls.js');var _HDRLoaderjs = require('three/addons/loaders/HDRLoader.js');var Z=new p.Vector3(0,0,1);function mt(e){let r=Math.abs(e.x),t=Math.abs(e.y),n=Math.abs(e.z);return n>=r&&n>=t?"z":t>=r&&t>=n?"y":"x"}var nr=function(e,r){let t=Et(r||{}),n=_optionalChain([t, 'access', _14 => _14.environment, 'optionalAccess', _15 => _15.sceneUp])||Z,o=gt(t),a=Ht(t,e);a.up.copy(n);let i=vt(e,t),s=Ct(a,e,t),l=me({scene:o,perspective:a,controls:s,onActiveCameraChange:()=>{},up:n}),c=()=>l.getActiveCamera();Rt(o,t);let d=Tt(o,t),u=()=>{d&&ht(d,ne(o))};_optionalChain([t, 'access', _16 => _16.floor, 'optionalAccess', _17 => _17.enabled])&&wt(o,t);let m=t.grid.enabled?Ee({cellSize:t.grid.cellSize,majorEvery:t.grid.majorEvery,cellColor:t.grid.cellColor,majorColor:t.grid.majorColor,fadeDistance:t.grid.fadeDistance,plane:t.grid.plane}):null;m&&o.add(m.object);let E=t.gizmo.enabled?pe({camera:a,domElement:e,controller:l}):null,f=_nullishCoalesce(e.parentElement, () => (e)),x=t.measure.enabled?ye(f,o):null,S=t.measure.enabled&&x?Te({canvas:e,scene:o,getActiveCamera:c,labelLayer:x,options:{snapPixels:t.measure.snapPixels,color:t.measure.color,labelClassName:t.measure.labelClassName,format:t.measure.format}}):null,b=t.events.enableEventHandlers!==!1?Mt(e,o,c,a,s,t):{dispose:()=>{},fitToView:()=>{},clearSelection:()=>{}},g=5,R=0,H=0,P=D=>{R=D.clientX,H=D.clientY},y=D=>Math.hypot(D.clientX-R,D.clientY-H)>g,w=D=>{if(!y(D)){if(_optionalChain([S, 'optionalAccess', _18 => _18.handleClick, 'call', _19 => _19(D)])){D.stopImmediatePropagation();return}_optionalChain([E, 'optionalAccess', _20 => _20.handleClick, 'call', _21 => _21(D)])&&D.stopImmediatePropagation()}};(E||S)&&(e.addEventListener("mousedown",P,{capture:!0}),e.addEventListener("click",w,{capture:!0}));let C=D=>_optionalChain([S, 'optionalAccess', _22 => _22.handleMove, 'call', _23 => _23(D)]);S&&e.addEventListener("mousemove",C,{passive:!0});let O=D=>{he(D,{color:t.edges.color,width:t.edges.width,thresholdAngle:t.edges.thresholdAngle})},h=e.parentElement,T=()=>h?{width:h.clientWidth,height:h.clientHeight}:{width:window.innerWidth,height:window.innerHeight},M=null,k=()=>{let{width:D,height:G}=T(),Q=Math.min(window.devicePixelRatio,2),le=ge(i,o,c(),Math.max(1,D),Math.max(1,G),{toneMapping:_nullishCoalesce(t.render.toneMapping, () => (p.NeutralToneMapping)),toneMappingExposure:_nullishCoalesce(t.render.toneMappingExposure, () => (1)),aoIntensity:t.render.aoIntensity});return le.setSize(Math.max(1,D),Math.max(1,G),Q),le},U=D=>{D&&!M?M=k():!D&&M&&(M.dispose(),M=null)};t.render.ambientOcclusion&&(M=k());let{animate:W,dispose:K}=yt(i,o,a,c,l,s,T,t.events.onFrame,m,E,()=>M,x);return W(),o.up.set(n.x,n.y,n.z),u(),{scene:o,camera:a,controls:s,renderer:i,cameraController:l,grid:m,gizmo:E,measureTool:S,applyEdges:O,setAmbientOcclusion:U,updateShadowBounds:u,dispose:()=>{K(),b.dispose(),(E||S)&&(e.removeEventListener("mousedown",P,{capture:!0}),e.removeEventListener("click",w,{capture:!0})),S&&e.removeEventListener("mousemove",C),_optionalChain([S, 'optionalAccess', _24 => _24.dispose, 'call', _25 => _25()]),_optionalChain([x, 'optionalAccess', _26 => _26.dispose, 'call', _27 => _27()]),_optionalChain([E, 'optionalAccess', _28 => _28.dispose, 'call', _29 => _29()]),_optionalChain([m, 'optionalAccess', _30 => _30.dispose, 'call', _31 => _31()]),_optionalChain([M, 'optionalAccess', _32 => _32.dispose, 'call', _33 => _33()]),s.dispose(),i.dispose(),o.traverse(D=>{let G=D;!G.geometry&&!G.material||(_optionalChain([G, 'access', _34 => _34.geometry, 'optionalAccess', _35 => _35.dispose, 'call', _36 => _36()]),Array.isArray(G.material)?G.material.forEach(Q=>Q.dispose()):_optionalChain([G, 'access', _37 => _37.material, 'optionalAccess', _38 => _38.dispose, 'call', _39 => _39()]))})},fitToView:b.fitToView,clearSelection:b.clearSelection}};function Et(e){let r=e.sceneScale||"m",n={mm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:10,lightHeight:20,minDistance:.1,shadowSize:100,scaleFactor:1e3},cm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:25,lightHeight:50,minDistance:.1,shadowSize:100,scaleFactor:100},m:{cameraDistance:10,near:.01,far:2e3,floorSize:50,lightDistance:25,lightHeight:50,minDistance:.001,shadowSize:100,scaleFactor:1},inches:{cameraDistance:15,near:.1,far:2e3,floorSize:80,lightDistance:20,lightHeight:40,minDistance:.1,shadowSize:80,scaleFactor:39.37},feet:{cameraDistance:8,near:.1,far:2e3,floorSize:40,lightDistance:15,lightHeight:30,minDistance:.1,shadowSize:60,scaleFactor:3.28084}}[r];return{sceneScale:r,camera:{position:_optionalChain([e, 'access', _40 => _40.camera, 'optionalAccess', _41 => _41.position])||new p.Vector3(-n.cameraDistance,-n.cameraDistance,n.cameraDistance),fov:_optionalChain([e, 'access', _42 => _42.camera, 'optionalAccess', _43 => _43.fov])||20,near:_optionalChain([e, 'access', _44 => _44.camera, 'optionalAccess', _45 => _45.near])||n.near,far:_optionalChain([e, 'access', _46 => _46.camera, 'optionalAccess', _47 => _47.far])||n.far,target:_optionalChain([e, 'access', _48 => _48.camera, 'optionalAccess', _49 => _49.target])||new p.Vector3(0,0,0)},lighting:{enableSunlight:_nullishCoalesce(_optionalChain([e, 'access', _50 => _50.lighting, 'optionalAccess', _51 => _51.enableSunlight]), () => (!0)),sunlightIntensity:_optionalChain([e, 'access', _52 => _52.lighting, 'optionalAccess', _53 => _53.sunlightIntensity])||1,sunlightPosition:_optionalChain([e, 'access', _54 => _54.lighting, 'optionalAccess', _55 => _55.sunlightPosition])||new p.Vector3(n.lightDistance,n.lightDistance,n.lightHeight),ambientLightColor:_optionalChain([e, 'access', _56 => _56.lighting, 'optionalAccess', _57 => _57.ambientLightColor])||new p.Color(4210752),ambientLightIntensity:_optionalChain([e, 'access', _58 => _58.lighting, 'optionalAccess', _59 => _59.ambientLightIntensity])||1,sunlightColor:_optionalChain([e, 'access', _60 => _60.lighting, 'optionalAccess', _61 => _61.sunlightColor])||16777215},environment:{hdrPath:_optionalChain([e, 'access', _62 => _62.environment, 'optionalAccess', _63 => _63.hdrPath])||"/baseHDR.hdr",backgroundColor:_optionalChain([e, 'access', _64 => _64.environment, 'optionalAccess', _65 => _65.backgroundColor])||new p.Color(15790320),enableEnvironmentLighting:_nullishCoalesce(_optionalChain([e, 'access', _66 => _66.environment, 'optionalAccess', _67 => _67.enableEnvironmentLighting]), () => (!0)),sceneUp:_optionalChain([e, 'access', _68 => _68.environment, 'optionalAccess', _69 => _69.sceneUp])||Z,showEnvironment:_nullishCoalesce(_optionalChain([e, 'access', _70 => _70.environment, 'optionalAccess', _71 => _71.showEnvironment]), () => (!1))},floor:{enabled:_nullishCoalesce(_optionalChain([e, 'access', _72 => _72.floor, 'optionalAccess', _73 => _73.enabled]), () => (!1)),size:_optionalChain([e, 'access', _74 => _74.floor, 'optionalAccess', _75 => _75.size])||n.floorSize,color:_optionalChain([e, 'access', _76 => _76.floor, 'optionalAccess', _77 => _77.color])||new p.Color(8421504),roughness:_optionalChain([e, 'access', _78 => _78.floor, 'optionalAccess', _79 => _79.roughness])||.7,metalness:_optionalChain([e, 'access', _80 => _80.floor, 'optionalAccess', _81 => _81.metalness])||0,receiveShadow:_nullishCoalesce(_optionalChain([e, 'access', _82 => _82.floor, 'optionalAccess', _83 => _83.receiveShadow]), () => (!0))},render:{enableShadows:_nullishCoalesce(_optionalChain([e, 'access', _84 => _84.render, 'optionalAccess', _85 => _85.enableShadows]), () => (!0)),shadowMapSize:_optionalChain([e, 'access', _86 => _86.render, 'optionalAccess', _87 => _87.shadowMapSize])||2048,antialias:_nullishCoalesce(_optionalChain([e, 'access', _88 => _88.render, 'optionalAccess', _89 => _89.antialias]), () => (!0)),pixelRatio:_optionalChain([e, 'access', _90 => _90.render, 'optionalAccess', _91 => _91.pixelRatio])||Math.min(window.devicePixelRatio,2),toneMapping:_optionalChain([e, 'access', _92 => _92.render, 'optionalAccess', _93 => _93.toneMapping])||p.NeutralToneMapping,toneMappingExposure:_optionalChain([e, 'access', _94 => _94.render, 'optionalAccess', _95 => _95.toneMappingExposure])||1,preserveDrawingBuffer:_nullishCoalesce(_optionalChain([e, 'access', _96 => _96.render, 'optionalAccess', _97 => _97.preserveDrawingBuffer]), () => (!1)),ambientOcclusion:_nullishCoalesce(_optionalChain([e, 'access', _98 => _98.render, 'optionalAccess', _99 => _99.ambientOcclusion]), () => (!1)),aoIntensity:_nullishCoalesce(_optionalChain([e, 'access', _100 => _100.render, 'optionalAccess', _101 => _101.aoIntensity]), () => (1))},controls:{enableDamping:_nullishCoalesce(_optionalChain([e, 'access', _102 => _102.controls, 'optionalAccess', _103 => _103.enableDamping]), () => (!1)),dampingFactor:_optionalChain([e, 'access', _104 => _104.controls, 'optionalAccess', _105 => _105.dampingFactor])||.05,autoRotate:_nullishCoalesce(_optionalChain([e, 'access', _106 => _106.controls, 'optionalAccess', _107 => _107.autoRotate]), () => (!1)),autoRotateSpeed:_optionalChain([e, 'access', _108 => _108.controls, 'optionalAccess', _109 => _109.autoRotateSpeed])||.5,enableZoom:_nullishCoalesce(_optionalChain([e, 'access', _110 => _110.controls, 'optionalAccess', _111 => _111.enableZoom]), () => (!0)),enablePan:_nullishCoalesce(_optionalChain([e, 'access', _112 => _112.controls, 'optionalAccess', _113 => _113.enablePan]), () => (!0)),minDistance:_optionalChain([e, 'access', _114 => _114.controls, 'optionalAccess', _115 => _115.minDistance])||n.minDistance,maxDistance:_optionalChain([e, 'access', _116 => _116.controls, 'optionalAccess', _117 => _117.maxDistance])||1/0},grid:{enabled:_nullishCoalesce(_optionalChain([e, 'access', _118 => _118.grid, 'optionalAccess', _119 => _119.enabled]), () => (!1)),cellSize:_nullishCoalesce(_optionalChain([e, 'access', _120 => _120.grid, 'optionalAccess', _121 => _121.cellSize]), () => (1)),majorEvery:_nullishCoalesce(_optionalChain([e, 'access', _122 => _122.grid, 'optionalAccess', _123 => _123.majorEvery]), () => (10)),cellColor:_nullishCoalesce(_optionalChain([e, 'access', _124 => _124.grid, 'optionalAccess', _125 => _125.cellColor]), () => (8947848)),majorColor:_nullishCoalesce(_optionalChain([e, 'access', _126 => _126.grid, 'optionalAccess', _127 => _127.majorColor]), () => (4473924)),fadeDistance:_nullishCoalesce(_optionalChain([e, 'access', _128 => _128.grid, 'optionalAccess', _129 => _129.fadeDistance]), () => (100)),plane:_nullishCoalesce(_optionalChain([e, 'access', _130 => _130.grid, 'optionalAccess', _131 => _131.plane]), () => (mt(_nullishCoalesce(_optionalChain([e, 'access', _132 => _132.environment, 'optionalAccess', _133 => _133.sceneUp]), () => (Z)))))},gizmo:{enabled:_nullishCoalesce(_optionalChain([e, 'access', _134 => _134.gizmo, 'optionalAccess', _135 => _135.enabled]), () => (!1))},edges:{enabled:_nullishCoalesce(_optionalChain([e, 'access', _136 => _136.edges, 'optionalAccess', _137 => _137.enabled]), () => (!1)),color:_nullishCoalesce(_optionalChain([e, 'access', _138 => _138.edges, 'optionalAccess', _139 => _139.color]), () => (2236962)),width:_nullishCoalesce(_optionalChain([e, 'access', _140 => _140.edges, 'optionalAccess', _141 => _141.width]), () => (1.5)),thresholdAngle:_nullishCoalesce(_optionalChain([e, 'access', _142 => _142.edges, 'optionalAccess', _143 => _143.thresholdAngle]), () => (30))},measure:{enabled:_nullishCoalesce(_optionalChain([e, 'access', _144 => _144.measure, 'optionalAccess', _145 => _145.enabled]), () => (!1)),snapPixels:_optionalChain([e, 'access', _146 => _146.measure, 'optionalAccess', _147 => _147.snapPixels]),color:_optionalChain([e, 'access', _148 => _148.measure, 'optionalAccess', _149 => _149.color]),labelClassName:_optionalChain([e, 'access', _150 => _150.measure, 'optionalAccess', _151 => _151.labelClassName]),format:_optionalChain([e, 'access', _152 => _152.measure, 'optionalAccess', _153 => _153.format])},events:{onBackgroundClicked:_optionalChain([e, 'access', _154 => _154.events, 'optionalAccess', _155 => _155.onBackgroundClicked]),onObjectSelected:_optionalChain([e, 'access', _156 => _156.events, 'optionalAccess', _157 => _157.onObjectSelected]),onMeshMetadataClicked:_optionalChain([e, 'access', _158 => _158.events, 'optionalAccess', _159 => _159.onMeshMetadataClicked]),onMeshDoubleClicked:_optionalChain([e, 'access', _160 => _160.events, 'optionalAccess', _161 => _161.onMeshDoubleClicked]),selectionColor:_optionalChain([e, 'access', _162 => _162.events, 'optionalAccess', _163 => _163.selectionColor])||"#ff0000",enableEventHandlers:_nullishCoalesce(_optionalChain([e, 'access', _164 => _164.events, 'optionalAccess', _165 => _165.enableEventHandlers]), () => (!0)),enableKeyboardControls:_nullishCoalesce(_optionalChain([e, 'access', _166 => _166.events, 'optionalAccess', _167 => _167.enableKeyboardControls]), () => (!0)),enableClickToFocus:_nullishCoalesce(_optionalChain([e, 'access', _168 => _168.events, 'optionalAccess', _169 => _169.enableClickToFocus]), () => (!0)),enableDoubleClickZoom:_nullishCoalesce(_optionalChain([e, 'access', _170 => _170.events, 'optionalAccess', _171 => _171.enableDoubleClickZoom]), () => (!0)),onReady:_optionalChain([e, 'access', _172 => _172.events, 'optionalAccess', _173 => _173.onReady]),onFrame:_optionalChain([e, 'access', _174 => _174.events, 'optionalAccess', _175 => _175.onFrame])}}}var pt=new Set(["grid","floor","label-layer","measure"]);function ft(e){let r=e;for(;r;){if(typeof r.userData.id=="string"&&pt.has(r.userData.id))return!0;r=r.parent}return!1}function ne(e){let r=new p.Box3;return e.traverse(t=>{let n=t;t.visible&&!ft(t)&&n.geometry&&r.expandByObject(t)}),r}function ht(e,r){if(r.isEmpty())return;let t=r.getCenter(new p.Vector3),n=r.getSize(new p.Vector3).length()*.5*1.2,o=e.shadow.camera;o.left=-n,o.right=n,o.top=n,o.bottom=-n,e.target.position.copy(t),e.target.updateMatrixWorld();let a=e.position.distanceTo(t);o.near=Math.max(n*.01,a-n),o.far=a+n,o.updateProjectionMatrix()}function gt(e){let r=new p.Scene,t=typeof e.environment.backgroundColor=="string"?new p.Color(e.environment.backgroundColor):e.environment.backgroundColor;return r.background=t||null,r}function bt(e,r,t,n,o=200){let a=e.position.clone(),i=r.target.clone(),s=performance.now(),l=d=>1-Math.pow(1-d,3),c=()=>{let d=performance.now()-s,u=l(Math.min(d/o,1));e.position.lerpVectors(a,t,u),r.target.lerpVectors(i,n,u),r.update(),u<1&&requestAnimationFrame(c)};requestAnimationFrame(c)}function yt(e,r,t,n,o,a,i,s,l,c,d,u){let m=null,E=performance.now(),f=()=>{let{width:b,height:g}=i();if(b===0||g===0)return;let R=Math.min(window.devicePixelRatio,2),H=Math.round(b*R),P=Math.round(g*R);(e.domElement.width!==H||e.domElement.height!==P)&&(e.setPixelRatio(R),e.setSize(b,g,!1),t.aspect=b/g,t.updateProjectionMatrix(),o.updateAspect(b,g),_optionalChain([d, 'optionalCall', _176 => _176(), 'optionalAccess', _177 => _177.setSize, 'call', _178 => _178(b,g,R)]),_optionalChain([u, 'optionalAccess', _179 => _179.setSize, 'call', _180 => _180(b,g)]))},x=function(){m=requestAnimationFrame(x);let b=performance.now(),g=(b-E)/1e3;E=b,f(),(a.enableDamping||a.autoRotate)&&a.update(),l&&l.update(n().position),c&&c.update(g),_optionalChain([s, 'optionalCall', _181 => _181(g)]);let R=n(),H=_optionalChain([d, 'optionalCall', _182 => _182()]);H?(H.setCamera(R),H.render(g)):e.render(r,R),u&&u.render(r,R),c&&c.render(e)};return{animate:x,dispose:()=>{m!==null&&(cancelAnimationFrame(m),m=null)}}}function Rt(e,r){r.environment.enableEnvironmentLighting?new (0, _HDRLoaderjs.HDRLoader)().load(r.environment.hdrPath||"/baseHDR.hdr",function(t){if(!_optionalChain([t, 'optionalAccess', _183 => _183.image])){_chunkBTH6J34Xcjs.e.call(void 0, ).warn("HDR loaded without image data; skipping environment map."),_optionalChain([r, 'access', _184 => _184.events, 'access', _185 => _185.onReady, 'optionalCall', _186 => _186()]);return}t.mapping=p.EquirectangularReflectionMapping,e.environment=t,r.environment.showEnvironment&&(e.background=t),_optionalChain([r, 'access', _187 => _187.events, 'access', _188 => _188.onReady, 'optionalCall', _189 => _189()])},void 0,function(t){_chunkBTH6J34Xcjs.e.call(void 0, ).warn("HDR texture could not be loaded, falling back to basic lighting:",t),_optionalChain([r, 'access', _190 => _190.events, 'access', _191 => _191.onReady, 'optionalCall', _192 => _192()])}):_optionalChain([r, 'access', _193 => _193.events, 'access', _194 => _194.onReady, 'optionalCall', _195 => _195()])}function Tt(e,r){let t=new p.AmbientLight(r.lighting.ambientLightColor,r.lighting.ambientLightIntensity);if(e.add(t),!r.lighting.enableSunlight)return null;let n=new p.DirectionalLight(_nullishCoalesce(r.lighting.sunlightColor, () => (16777215)),r.lighting.sunlightIntensity),o=r.lighting.sunlightPosition;return o&&n.position.set(o.x,o.y,o.z),r.render.enableShadows?(n.castShadow=!0,n.shadow.mapSize.width=r.render.shadowMapSize||2048,n.shadow.mapSize.height=r.render.shadowMapSize||2048,n.shadow.bias=-1e-4,n.shadow.normalBias=.02,n.shadow.radius=4,e.add(n),e.add(n.target),n):(e.add(n),null)}function wt(e,r){let t=r.floor.size,n=new p.PlaneGeometry(t,t),o=typeof r.floor.color=="string"?new p.Color(r.floor.color):r.floor.color,a=new p.MeshStandardMaterial({color:o,roughness:r.floor.roughness,metalness:r.floor.metalness,side:p.DoubleSide}),i=new p.Mesh(n,a);i.userData.id="floor",i.name="floor";let s=(_optionalChain([r, 'access', _196 => _196.environment, 'optionalAccess', _197 => _197.sceneUp])||Z).clone().normalize();i.quaternion.setFromUnitVectors(new p.Vector3(0,0,1),s),i.position.set(0,0,0),r.floor.receiveShadow&&r.render.enableShadows&&(i.receiveShadow=!0),e.add(i)}function Ht(e,r){let t=r.parentElement,n=t?t.clientWidth:window.innerWidth,o=t?t.clientHeight:window.innerHeight,a=new p.PerspectiveCamera(e.camera.fov,n/o,e.camera.near,e.camera.far),i=e.camera.position;return i&&a.position.set(i.x,i.y,i.z),a}function vt(e,r){let t=new p.WebGLRenderer({antialias:r.render.antialias,canvas:e,alpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:r.render.preserveDrawingBuffer,logarithmicDepthBuffer:!0}),n=e.parentElement,o=n?n.clientWidth:window.innerWidth,a=n?n.clientHeight:window.innerHeight;return n&&(e.style.width="100%",e.style.height="100%",e.style.display="block"),t.setSize(o,a,!1),t.setPixelRatio(r.render.pixelRatio||Math.min(window.devicePixelRatio,2)),r.render.enableShadows&&(t.shadowMap.enabled=!0,t.shadowMap.type=p.VSMShadowMap),t.toneMapping=r.render.toneMapping,t.toneMappingExposure=r.render.toneMappingExposure||1,t.outputColorSpace=p.SRGBColorSpace,t.sortObjects=!0,t}function Mt(e,r,t,n,o,a){let i=new Set,s=new Map,l=new p.Raycaster,c=new p.Vector2,d=new p.Vector2,u=y=>{let w=y;for(;w;){if(!w.visible)return!1;w=w.parent}return!0},m=()=>{let y=ne(r);if(y.isEmpty()){_chunkBTH6J34Xcjs.e.call(void 0, ).warn("No objects to fit to view");return}let w=y.getCenter(new p.Vector3),C=y.getSize(new p.Vector3),O=Math.max(C.x,C.y,C.z),h=n.fov*(Math.PI/180),T=O/(2*Math.tan(h/2));T*=1.5;let M=n.position.clone().sub(o.target);M.lengthSq()<1e-12&&M.set(.8,1,1.2),M.normalize(),n.position.copy(w.clone().add(M.multiplyScalar(T))),o.target.copy(w),o.update()},E=typeof a.events.selectionColor=="string"?new p.Color(a.events.selectionColor):a.events.selectionColor instanceof p.Color?a.events.selectionColor:new p.Color("#ff0000"),f=()=>{i.forEach(y=>{let w=y;if(s.has(y)){let C=s.get(y),O=w.material;O instanceof p.Material?O.dispose():Array.isArray(O)&&O.forEach(h=>h.dispose()),w.material=C,s.delete(y)}}),i.clear()},x=y=>{let w=y;if(!(w.material instanceof p.Material))return!1;s.set(y,w.material);let C=w.material.clone();return y instanceof p.Mesh&&"emissive"in C?C.emissive=E.clone():"color"in C&&(C.color=E.clone()),w.material=C,!0},S=()=>{let y=ne(r),w=y.isEmpty()?1:y.getSize(new p.Vector3).length();l.params.Points.threshold=w*.01},b=y=>{d.set(y.clientX,y.clientY)},g=y=>{let w=new p.Vector2(y.clientX,y.clientY);if(d.distanceTo(w)>5)return;let C=e.getBoundingClientRect();c.x=(y.clientX-C.left)/C.width*2-1,c.y=-((y.clientY-C.top)/C.height)*2+1,S(),l.setFromCamera(c,t());let O=l.intersectObjects(r.children,!0).filter(h=>u(h.object));if(O.length>0){let h=O[0].object;i.has(h)||(f(),i.add(h),x(h),_optionalChain([a, 'access', _198 => _198.events, 'optionalAccess', _199 => _199.onObjectSelected, 'optionalCall', _200 => _200(h)]),h instanceof p.Mesh&&Object.keys(h.userData).length>0&&_optionalChain([a, 'access', _201 => _201.events, 'optionalAccess', _202 => _202.onMeshMetadataClicked, 'optionalCall', _203 => _203(h.userData)]))}else f(),_optionalChain([a, 'access', _204 => _204.events, 'optionalAccess', _205 => _205.onBackgroundClicked, 'optionalCall', _206 => _206({x:c.x,y:c.y})])},R=y=>{let w=e.getBoundingClientRect();c.x=(y.clientX-w.left)/w.width*2-1,c.y=-((y.clientY-w.top)/w.height)*2+1,S(),l.setFromCamera(c,t());let C=l.intersectObjects(r.children,!0).filter(D=>u(D.object));if(C.length===0)return;let O=C[0].object;if(_optionalChain([a, 'access', _207 => _207.events, 'optionalAccess', _208 => _208.onMeshDoubleClicked, 'optionalCall', _209 => _209(O)]),!_optionalChain([a, 'access', _210 => _210.events, 'optionalAccess', _211 => _211.enableDoubleClickZoom]))return;let h=new p.Box3().setFromObject(O);if(h.isEmpty())return;let T=h.getCenter(new p.Vector3),M=h.getSize(new p.Vector3),k=Math.max(M.x,M.y,M.z),U=n.fov*(Math.PI/180),W=k/(2*Math.tan(U/2))*1.5,K=n.position.clone().sub(o.target).normalize(),se=T.clone().add(K.multiplyScalar(W));bt(n,o,se,T)},H=y=>{if(_optionalChain([a, 'access', _212 => _212.events, 'optionalAccess', _213 => _213.enableKeyboardControls]))switch(y.key.toLowerCase()){case"f":y.preventDefault(),m();break;case"escape":y.preventDefault(),f();break;case" ":y.preventDefault(),m();break}};return _optionalChain([a, 'access', _214 => _214.events, 'optionalAccess', _215 => _215.enableClickToFocus])&&(e.addEventListener("mousedown",b),e.addEventListener("click",g),e.addEventListener("dblclick",R)),_optionalChain([a, 'access', _216 => _216.events, 'optionalAccess', _217 => _217.enableKeyboardControls])&&(e.setAttribute("tabindex","0"),e.addEventListener("keydown",H)),{dispose:()=>{e.removeEventListener("mousedown",b),e.removeEventListener("click",g),e.removeEventListener("dblclick",R),e.removeEventListener("keydown",H),f()},fitToView:m,clearSelection:f}}function Ct(e,r,t){let n=new (0, _OrbitControlsjs.OrbitControls)(e,r),o=t.camera.target;return o&&n.target.set(o.x,o.y,o.z),n.enableDamping=t.controls.enableDamping||!1,n.dampingFactor=t.controls.dampingFactor||.05,n.autoRotate=t.controls.autoRotate||!1,n.autoRotateSpeed=t.controls.autoRotateSpeed||.5,n.enableZoom=_nullishCoalesce(t.controls.enableZoom, () => (!0)),n.enablePan=_nullishCoalesce(t.controls.enablePan, () => (!0)),n.minDistance=t.controls.minDistance||.001,n.maxDistance=t.controls.maxDistance||1/0,n.screenSpacePanning=!1,n.maxPolarAngle=Math.PI,n.update(),n}var It={};_chunkBTH6J34Xcjs.a.call(void 0, It,{CONCRETE_MATERIAL:()=>At,EMISSIVE_MATERIAL:()=>xt,GLASS_MATERIAL:()=>Lt,METAL_MATERIAL:()=>St,PLASTIC_MATERIAL:()=>Dt,RUBBER_MATERIAL:()=>Pt,WOOD_MATERIAL:()=>Ot});var xt=new L.MeshPhysicalMaterial({color:0,emissive:new L.Color(16777215),emissiveIntensity:5,metalness:0,roughness:.2,clearcoat:.3,clearcoatRoughness:.2,depthWrite:!0,depthTest:!0,transparent:!1,alphaTest:0,polygonOffset:!0,side:L.FrontSide,dithering:!0}),St=new L.MeshPhysicalMaterial({color:new L.Color(0),metalness:.9,roughness:.3,envMapIntensity:1.2,clearcoat:.3,clearcoatRoughness:.2,reflectivity:1,ior:2.5,thickness:1,depthWrite:!0,transparent:!1,alphaTest:0,depthTest:!0,polygonOffset:!0,side:L.FrontSide,dithering:!0}),At=new L.MeshPhysicalMaterial({color:new L.Color(13421772),metalness:0,roughness:.92,envMapIntensity:.15,clearcoat:.05,clearcoatRoughness:.9,reflectivity:.15,transmission:0,ior:1.45,thickness:0,depthWrite:!0,transparent:!1,alphaTest:.5,depthTest:!0,polygonOffset:!0,side:L.FrontSide,dithering:!0}),Dt=new L.MeshPhysicalMaterial({color:new L.Color(16777215),metalness:0,roughness:.3,envMapIntensity:.5,clearcoat:.5,clearcoatRoughness:.1,reflectivity:.5,ior:1.4,transmission:0,transparent:!1,depthWrite:!0,side:L.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Lt=new L.MeshPhysicalMaterial({color:new L.Color(16777215),metalness:0,roughness:0,transmission:.95,transparent:!0,opacity:.3,envMapIntensity:1,clearcoat:1,clearcoatRoughness:0,ior:1.52,reflectivity:.9,thickness:1,side:L.DoubleSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Pt=new L.MeshPhysicalMaterial({color:new L.Color(1710618),metalness:0,roughness:.9,envMapIntensity:.2,clearcoat:.1,clearcoatRoughness:.8,reflectivity:.2,ior:1.3,transmission:0,depthWrite:!0,side:L.FrontSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),Ot=new L.MeshPhysicalMaterial({color:new L.Color(8934707),metalness:0,roughness:.7,envMapIntensity:.3,clearcoat:.3,clearcoatRoughness:.4,reflectivity:.3,ior:1.3,transmission:0,depthWrite:!0,side:L.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});function J(e,r,t,n=!0){return{x:e,y:r,z:t}}var Ft="#ffffff",re=12,jt=4e-4,kt=12,_t=.05;function we(e,r={}){if(!e||e.length===0)return[];let{rhino:t,applyTransforms:n=!0}=r,o=[];for(let a of e)switch(a.kind){case"curve":{let i=Nt(a,t,n);i&&o.push(i);break}case"point":{o.push(Ut(a,n));break}default:{let i=a;_chunkBTH6J34Xcjs.e.call(void 0, ).warn(`Skipping unknown display item kind: ${String(i.kind)}`);break}}return o}var Gt=2;function Nt(e,r,t){if(!r)return _chunkBTH6J34Xcjs.e.call(void 0, ).warn("No rhino3dm instance provided; skipping curve display item."),null;let n=Wt(e.json,r);if(!n)return null;let o=$t(n,t);if(o.length<2)return null;let a=[];for(let u of o)a.push(u.x,u.y,u.z);let i=new _LineGeometryjs.LineGeometry;i.setPositions(a);let s=He(e.color,e.opacity),l=new (0, _LineMaterialjs.LineMaterial)({color:s.color}),c=l;c.linewidth=_nullishCoalesce(e.width, () => (Gt)),c.transparent=s.transparent,c.opacity=s.opacity;let d=new (0, _Line2js.Line2)(i,l);return d.computeLineDistances(),d.name=e.name,d.userData={id:e.id,layer:e.layer,kind:"curve",metadata:e.metadata},d}function Ut(e,r){let{x:t,y:n,z:o}=J(e.position.X,e.position.Y,e.position.Z,r),a=new j.BufferGeometry;a.setAttribute("position",new j.Float32BufferAttribute([t,n,o],3));let i=new j.PointsMaterial({...He(e.color,e.opacity),size:6,sizeAttenuation:!1}),s=new j.Points(a,i);return s.name=e.name,s.userData={id:e.id,layer:e.layer,kind:"point",metadata:e.metadata},s}function Wt(e,r){try{let t=JSON.parse(e),n=r.CommonObject.decode(t);return n&&typeof n.pointAt=="function"?n:(_chunkBTH6J34Xcjs.e.call(void 0, ).warn("Decoded display-item JSON is not a curve; skipping."),null)}catch(t){return _chunkBTH6J34Xcjs.e.call(void 0, ).warn("Failed to decode curve display item JSON:",t),null}}function $t(e,r){let t=Yt(e,r);return t||Xt(e,r)}function Yt(e,r){if(!e.isPolyline())return null;let t=e.tryGetPolyline(),n=Array.isArray(t)?t[1]:t;if(!n||typeof n.count!="number"||n.count<2)return null;let o=[];for(let a=0;a<n.count;a++){let i=n.get(a),{x:s,y:l,z:c}=J(i[0],i[1],i[2],r);o.push(new j.Vector3(s,l,c))}return o}function Xt(e,r){let t=e.domain,n=t[0],a=t[1]-n,i=c=>{let d=e.pointAt(c),{x:u,y:m,z:E}=J(d[0],d[1],d[2],r);return new j.Vector3(u,m,E)},s=qt(e),l=[i(n)];for(let c=0;c<re;c++){let d=n+a*c/re,u=n+a*(c+1)/re;oe(d,i(d),u,i(u),i,s,kt,l),l.push(i(u))}return l}function oe(e,r,t,n,o,a,i,s){if(i<=0)return;let l=(e+t)/2,c=o(l),d=Jt(c,r,n),u=Zt(r,c,n);d<=a&&u<=_t||(oe(e,r,l,c,o,a,i-1,s),s.push(c),oe(l,c,t,n,o,a,i-1,s))}function qt(e){let r=e.getBoundingBox(),t=r.min,n=r.max,o=Math.hypot(n[0]-t[0],n[1]-t[1],n[2]-t[2]);return Math.max(o*jt,1e-6)}function Zt(e,r,t){let n=r.clone().sub(e),o=t.clone().sub(r),a=n.length(),i=o.length();if(a===0||i===0)return 0;let s=Math.max(-1,Math.min(1,n.dot(o)/(a*i)));return Math.acos(s)}function Jt(e,r,t){let n=t.clone().sub(r),o=n.lengthSq();if(o===0)return e.distanceTo(r);let a=Math.max(0,Math.min(1,e.clone().sub(r).dot(n)/o)),i=r.clone().addScaledVector(n,a);return e.distanceTo(i)}function He(e,r){let t=_nullishCoalesce(r, () => (1));return{color:new j.Color(_nullishCoalesce(e, () => (Ft))),transparent:t<1,opacity:t}}var ve=1096174675,Me= exports.t =1,ae= exports.u =1,Ce=12,xe=56;function ie(e){let r=Kt(e),t=new DataView(r.buffer,r.byteOffset,r.byteLength);if(r.byteLength<Ce)throw N("Blob too small to contain SLVA header.",{expectedBytes:Ce,availableBytes:r.byteLength});let n=0,o=t.getUint32(n,!0);if(n+=4,o!==ve)throw N(`Invalid SLVA magic: 0x${o.toString(16)}`,{expectedMagic:`0x${ve.toString(16)}`,actualMagic:`0x${o.toString(16)}`});let a=t.getUint32(n,!0);if(n+=4,a!==Me)throw N(`Unsupported SLVA version: ${a}`,{expectedVersion:Me,actualVersion:a});let i=t.getUint32(n,!0);if(n+=4,n+i>r.byteLength)throw N("Insufficient data to read metadata JSON.",{expectedBytes:i,availableBytes:r.byteLength-n,offset:n});let s=r.subarray(n,n+i);n+=i;let l;try{l=JSON.parse(Qt(s))}catch(h){throw N(`Failed to parse metadata JSON: ${h instanceof Error?h.message:String(h)}`,{metadataLen:i})}if(n+xe>r.byteLength)throw N("Insufficient data to read geometry header.",{expectedBytes:xe,availableBytes:r.byteLength-n,offset:n});let c=t.getUint32(n,!0);n+=4;let d=t.getFloat64(n,!0);n+=8;let u=t.getFloat64(n,!0);n+=8;let m=t.getFloat64(n,!0);n+=8;let E=t.getFloat64(n,!0);n+=8;let f=t.getFloat64(n,!0);n+=8;let x=t.getFloat64(n,!0);n+=8;let S=t.getUint32(n,!0);n+=4;let b=(c&ae)!==0,g=S*3,H=g*(b?4:2);if(n+H>r.byteLength)throw N("Insufficient data to read vertices.",{expectedBytes:H,availableBytes:r.byteLength-n,offset:n,useFloat32:b,vertexCount:S});let P=r.byteOffset+n,y=b?tn(r.buffer,P,g):en(r.buffer,P,g);if(n+=H,n+4>r.byteLength)throw N("Insufficient data to read index count.",{expectedBytes:4,availableBytes:r.byteLength-n,offset:n});let w=t.getUint32(n,!0);n+=4;let C=w*4;if(n+C>r.byteLength)throw N("Insufficient data to read indices.",{expectedBytes:C,availableBytes:r.byteLength-n,offset:n,indexCount:w});let O=nn(r.buffer,r.byteOffset+n,w);return{metadata:l,flags:c,vertices:y,indices:O,origin:[d,u,m],scale:[E,f,x]}}function Kt(e){return typeof e=="string"?_chunkBTH6J34Xcjs.o.call(void 0, e):e instanceof Uint8Array?e:new Uint8Array(e)}function Qt(e){if(typeof TextDecoder<"u")return new TextDecoder("utf-8").decode(e);if(typeof globalThis.Buffer<"u")return globalThis.Buffer.from(e).toString("utf-8");throw new (0, _chunkBTH6J34Xcjs.d)("No UTF-8 decoder available in this environment.",_chunkBTH6J34Xcjs.c.INVALID_STATE)}function en(e,r,t){if(t===0)return new Int16Array(0);if(r%2===0)return new Int16Array(e,r,t);let n=new Uint8Array(t*2);return n.set(new Uint8Array(e,r,t*2)),new Int16Array(n.buffer)}function tn(e,r,t){if(t===0)return new Float32Array(0);if(r%4===0)return new Float32Array(e,r,t);let n=new Uint8Array(t*4);return n.set(new Uint8Array(e,r,t*4)),new Float32Array(n.buffer)}function nn(e,r,t){if(t===0)return new Uint32Array(0);if(r%4===0)return new Uint32Array(e,r,t);let n=new Uint8Array(t*4);return n.set(new Uint8Array(e,r,t*4)),new Uint32Array(n.buffer)}function N(e,r){return new (0, _chunkBTH6J34Xcjs.d)(e,_chunkBTH6J34Xcjs.c.VALIDATION_ERROR,{context:r})}async function Se(e,r){let{debug:t=!1}=_nullishCoalesce(r, () => ({})),n=t?performance.now():0;try{let o=performance.now(),a=JSON.parse(e),i=performance.now()-o;return await rn(a,r,{parseTime:i,perfStart:n})}catch(o){return _chunkBTH6J34Xcjs.e.call(void 0, ).error("Error parsing mesh batch:",o),[]}}async function rn(e,r,t){let{mergeByMaterial:n=!0,applyTransforms:o=!0,scaleFactor:a=1,debug:i=!1}=_nullishCoalesce(r, () => ({})),{parseTime:s=0,perfStart:l=i?performance.now():0}=_nullishCoalesce(t, () => ({}));try{let c=performance.now(),d=ie(e.compressedData),u=performance.now()-c,m=i?dn(e.compressedData):0;return Ae(d,{mergeByMaterial:n,applyTransforms:o,scaleFactor:a,debug:i,parseTime:s,decodeTime:u,perfStart:l,blobBytes:m,fallback:{materials:e.materials,groups:e.groups,sourceComponentId:e.sourceComponentId}})}catch(c){return _chunkBTH6J34Xcjs.e.call(void 0, ).error("Error parsing mesh batch object:",c),[]}}async function gr(e,r){let{mergeByMaterial:t=!0,applyTransforms:n=!0,scaleFactor:o=1,debug:a=!1}=_nullishCoalesce(r, () => ({})),i=a?performance.now():0;try{let s=performance.now(),l=ie(e),c=performance.now()-s,d=e.byteLength;return Ae(l,{mergeByMaterial:t,applyTransforms:n,scaleFactor:o,debug:a,parseTime:0,decodeTime:c,perfStart:i,blobBytes:d})}catch(s){return _chunkBTH6J34Xcjs.e.call(void 0, ).error("Error parsing mesh batch blob:",s),[]}}function Ae(e,r){let{mergeByMaterial:t,applyTransforms:n,scaleFactor:o,debug:a,parseTime:i,decodeTime:s,perfStart:l,blobBytes:c,fallback:d}=r,u=_nullishCoalesce(_nullishCoalesce(e.metadata.materials, () => (_optionalChain([d, 'optionalAccess', _218 => _218.materials]))), () => ([])),m=_nullishCoalesce(_nullishCoalesce(e.metadata.groups, () => (_optionalChain([d, 'optionalAccess', _219 => _219.groups]))), () => ([])),E=_nullishCoalesce(e.metadata.sourceComponentId, () => (_optionalChain([d, 'optionalAccess', _220 => _220.sourceComponentId]))),f=(e.flags&ae)!==0,x=f?an(e.vertices,n):on(e.vertices,e.origin,e.scale,n);if(a){let H=e.vertices.byteLength+e.indices.byteLength;_chunkBTH6J34Xcjs.e.call(void 0, ).debug("Mesh Batch Stats:"),_chunkBTH6J34Xcjs.e.call(void 0, ).debug(` Materials: ${u.length} | Groups: ${m.length}`),_chunkBTH6J34Xcjs.e.call(void 0, ).debug(` Vertices: ${e.vertices.length/3} | Indices: ${e.indices.length}`),_chunkBTH6J34Xcjs.e.call(void 0, ).debug(` Format: ${f?"float32":"int16 quantized"}`),_chunkBTH6J34Xcjs.e.call(void 0, ).debug(` Blob: ${(c/1024/1024).toFixed(2)} MB | Geometry on wire: ${(H/1024/1024).toFixed(2)} MB`)}let S=performance.now(),b=u.map(sn),g=[];for(let H of m)if(t&&H.meshes.length>1){let P=ln(H,x,e.indices,b);P.userData.sourceComponentId=_nullishCoalesce(E, () => (null)),g.push(P)}else{let P=cn(H,x,e.indices,b);for(let y of P)y.userData.sourceComponentId=_nullishCoalesce(E, () => (null));g.push(...P)}if(o!==1)for(let H of g)H.scale.set(o,o,o);let R=performance.now()-S;if(a){let H=performance.now()-l;_chunkBTH6J34Xcjs.e.call(void 0, ).debug("Performance:"),i>0&&_chunkBTH6J34Xcjs.e.call(void 0, ).debug(` Parse JSON: ${i.toFixed(2)}ms`),_chunkBTH6J34Xcjs.e.call(void 0, ).debug(` Decode binary: ${s.toFixed(2)}ms`),_chunkBTH6J34Xcjs.e.call(void 0, ).debug(` Create Meshes: ${R.toFixed(2)}ms`),_chunkBTH6J34Xcjs.e.call(void 0, ).debug(` Total: ${H.toFixed(2)}ms`)}return Promise.resolve(g)}function on(e,r,t,n){let o=new Float32Array(e.length),a=r[0],i=r[1],s=r[2],l=t[0],c=t[1],d=t[2];for(let u=0;u<e.length;u+=3)o[u]=a+(e[u]+32767)*l,o[u+1]=i+(e[u+1]+32767)*c,o[u+2]=s+(e[u+2]+32767)*d;return o}function an(e,r){return e}function sn(e){let r=de(e.color);return new B.MeshPhysicalMaterial({color:r,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,side:B.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0})}function ln(e,r,t,n){let o=0,a=0;for(let f of e.meshes)o+=f.vertexCount,a+=f.indexCount;let i=new Float32Array(o*3),s=new Uint32Array(a),l=0,c=0;for(let f of e.meshes){let x=f.vertexStart*3,S=f.vertexCount*3;i.set(r.subarray(x,x+S),l*3);let b=t.subarray(f.indexStart,f.indexStart+f.indexCount),g=l-f.vertexStart;if(g===0)s.set(b,c);else for(let R=0;R<b.length;R++)s[c+R]=b[R]+g;l+=f.vertexCount,c+=f.indexCount}let d=new B.BufferGeometry;d.setAttribute("position",new B.BufferAttribute(i,3)),d.setIndex(new B.BufferAttribute(s,1)),d.computeVertexNormals();let u=new B.Mesh(d,n[e.materialId]),m=e.meshes[0],E=e.meshes.map(f=>f.name).filter(f=>f&&f.length>0);return u.name=E.length>0?E[0]:`merged_material_${e.materialId}`,u.castShadow=!0,u.receiveShadow=!0,u.userData={name:u.name,layer:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _221 => _221.layer]), () => ("")),originalIndex:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _222 => _222.originalIndex]), () => (0)),metadata:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _223 => _223.metadata]), () => ({})),mergedFrom:e.meshes.slice(1).map(f=>({name:f.name,layer:f.layer,originalIndex:f.originalIndex}))},u}function cn(e,r,t,n){let o=[];for(let a of e.meshes){let i=a.vertexStart*3,s=a.vertexCount*3,l=r.slice(i,i+s),c=t.subarray(a.indexStart,a.indexStart+a.indexCount),d=new Uint32Array(c.length),u=a.vertexStart;for(let f=0;f<c.length;f++)d[f]=c[f]-u;let m=new B.BufferGeometry;m.setAttribute("position",new B.BufferAttribute(l,3)),m.setIndex(new B.BufferAttribute(d,1)),m.computeVertexNormals();let E=new B.Mesh(m,n[e.materialId]);E.name=a.name,E.userData={name:a.name,layer:_nullishCoalesce(a.layer, () => ("")),originalIndex:a.originalIndex,metadata:_nullishCoalesce(a.metadata, () => ({}))},E.castShadow=!0,E.receiveShadow=!0,o.push(E)}return o}function dn(e){return Math.floor(e.length*3/4)}var un={Millimeters:1/1e3,Centimeters:1/100,Meters:1,Inches:1/39.37,Feet:1/3.28084},mn="Display";async function Hr(e,r){let t=performance.now(),n=[],{allowScaling:o=!0,allowAutoPosition:a=!0,rhino:i,debug:s=!1,parsing:l={}}=_nullishCoalesce(r, () => ({}));try{let c=o?En(e.modelunits):1;return await pn(e,n,c,l,i,s),a&&bn(n),n}catch(c){throw yn(c,n),c}finally{s&&Tn(t)}}function En(e){return _nullishCoalesce(un[e], () => (1))}async function pn(e,r,t,n,o,a){for(let i of e.values){let s=i.InnerTree;for(let l in s){let c=s[l];c&&await fn(c,r,t,n,o,a)}}}async function fn(e,r,t,n,o,a){for(let i of e){if(!i.type.includes(mn))continue;let s={mergeByMaterial:!0,applyTransforms:!0,debug:!1,...n},l=await Se(i.data,s),c=we(hn(i.data),{rhino:o,applyTransforms:s.applyTransforms}),d=[...l,...c];if(t!==1)for(let u of d)u.scale.set(t,t,t);r.push(...d),a&&_chunkBTH6J34Xcjs.e.call(void 0, ).debug(`Extracted ${l.length} meshes and ${c.length} items from batch`)}}function hn(e){return_optionalChain([(typeof e=="string"?gn(e):e), 'optionalAccess', _224 => _224.items])}function gn(e){try{return JSON.parse(e)}catch (e4){return}}function bn(e){if(e.length===0)return;let r=Y(e);ue(e,r.min.z,"z")}function yn(e,r){_chunkBTH6J34Xcjs.e.call(void 0, ).error("An unexpected error occurred:",e),Rn(r)}function Rn(e){for(let r of e){let t=r;t.geometry&&t.geometry.dispose(),t.material&&(Array.isArray(t.material)?t.material.forEach(n=>n.dispose()):t.material.dispose())}}function Tn(e){let r=performance.now()-e;_chunkBTH6J34Xcjs.e.call(void 0, ).info("Time to process meshes:",`${r.toFixed(2)}ms`)}exports.a = Hn; exports.b = de; exports.c = ue; exports.d = Y; exports.e = me; exports.f = Ee; exports.g = pe; exports.h = X; exports.i = he; exports.j = qe; exports.k = On; exports.l = ge; exports.m = ye; exports.n = ct; exports.o = Te; exports.p = nr; exports.q = It; exports.r = we; exports.s = ve; exports.t = Me; exports.u = ae; exports.v = ie; exports.w = Se; exports.x = rn; exports.y = gr; exports.z = un; exports.A = Hr;
|
|
55
|
+
//# sourceMappingURL=chunk-NFPYFIYS.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-NFPYFIYS.cjs","../src/features/visualization/threejs/three-helpers.ts","../src/features/visualization/threejs/grid.ts","../src/features/visualization/threejs/view-gizmo.ts","../src/features/visualization/threejs/measure.ts"],"names":["CAMERA_CONFIG","updateScene","scene","meshes","camera","controls","initialPositionSet","clearScene","mesh","unionBoundingBox","computeCombinedBoundingBox","center","size","maxDim","distance","parseColor","colorString","getLogger","trimmed","hex","hoverMarker"],"mappings":"AAAA,2/BAAwE,keCAjD,IAKjBA,CAAAA,CAAgB,CACrB,cAAA,CAAgB,GAAA,CAChB,eAAA,CAAiB,GAAA,CACjB,qBAAA,CAAuB,GAAA,CACvB,iBAAA,CAAmB,CAClB,IAAA,CAAM,IAAA,CACN,KAAA,CAAO,IAAA,CACP,MAAA,CAAQ,GACT,CAAA,CACA,gBAAA,CAAkB,CACjB,IAAA,CAAM,GAAA,CACN,KAAA,CAAO,EAAA,CACP,MAAA,CAAQ,EACT,CAAA,CACA,2BAAA,CAA6B,CAC9B,CAAA,CAWO,SAASC,EAAAA,CACfC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACC,CAGD,EAAA,CAFAC,EAAAA,CAAWL,CAAK,CAAA,CAEZC,CAAAA,CAAO,MAAA,GAAW,CAAA,CAAG,MAAA,CAGzBA,CAAAA,CAAO,OAAA,CAASK,CAAAA,EAAS,CACxBN,CAAAA,CAAM,GAAA,CAAIM,CAAI,CACf,CAAC,CAAA,CAGD,IAAMC,CAAAA,CAAmBC,CAAAA,CAA2BP,CAAM,CAAA,CAGpDQ,CAAAA,CAASF,CAAAA,CAAiB,SAAA,CAAU,IAAU,CAAA,CAAA,OAAS,CAAA,CACvDG,CAAAA,CAAOH,CAAAA,CAAiB,OAAA,CAAQ,IAAU,CAAA,CAAA,OAAS,CAAA,CAGnDI,CAAAA,CAAS,IAAA,CAAK,GAAA,CAAID,CAAAA,CAAK,CAAA,CAAGA,CAAAA,CAAK,CAAA,CAAGA,CAAAA,CAAK,CAAC,CAAA,CAuB9C,EAAA,CAnBmBC,CAAAA,CAAS,IAAA,CAAK,GAAA,CAAID,CAAAA,CAAK,CAAA,EAAK,CAAA,CAAGA,CAAAA,CAAK,CAAA,EAAK,CAAA,CAAGA,CAAAA,CAAK,CAAA,EAAK,CAAC,CAAA,CAEzDZ,CAAAA,CAAc,qBAAA,EAAyBa,CAAAA,CAASb,CAAAA,CAAc,cAAA,CAAA,CAE9EI,CAAAA,CAAO,IAAA,CAAOS,CAAAA,CAASb,CAAAA,CAAc,iBAAA,CAAkB,IAAA,CACvDI,CAAAA,CAAO,GAAA,CAAMS,CAAAA,CAASb,CAAAA,CAAc,gBAAA,CAAiB,IAAA,CAAA,CAC3Ca,CAAAA,CAASb,CAAAA,CAAc,eAAA,CAAA,CAEjCI,CAAAA,CAAO,IAAA,CAAOS,CAAAA,CAASb,CAAAA,CAAc,iBAAA,CAAkB,KAAA,CACvDI,CAAAA,CAAO,GAAA,CAAMS,CAAAA,CAASb,CAAAA,CAAc,gBAAA,CAAiB,KAAA,CAAA,CAAA,CAGrDI,CAAAA,CAAO,IAAA,CAAO,IAAA,CAAK,GAAA,CAAI,GAAA,CAAMS,CAAAA,CAASb,CAAAA,CAAc,iBAAA,CAAkB,MAAM,CAAA,CAC5EI,CAAAA,CAAO,GAAA,CAAM,IAAA,CAAK,GAAA,CAAI,GAAA,CAAMS,CAAAA,CAASb,CAAAA,CAAc,gBAAA,CAAiB,MAAM,CAAA,CAAA,CAG3EI,CAAAA,CAAO,sBAAA,CAAuB,CAAA,CAGzBE,CAAAA,CAWJD,CAAAA,CAAS,WAAA,CAAcD,CAAAA,CAAO,IAAA,CAAO,CAAA,CACrCC,CAAAA,CAAS,WAAA,CAAcD,CAAAA,CAAO,GAAA,CAAM,EAAA,CAAA,IAZZ,CACxB,IAAMU,CAAAA,CAAWD,CAAAA,CAASb,CAAAA,CAAc,2BAAA,CAExCI,CAAAA,CAAO,QAAA,CAAS,GAAA,CAAIO,CAAAA,CAAO,CAAA,CAAIG,CAAAA,CAAW,EAAA,CAAKH,CAAAA,CAAO,CAAA,CAAIG,CAAAA,CAAUH,CAAAA,CAAO,CAAA,CAAIG,CAAAA,CAAW,GAAG,CAAA,CAC7FT,CAAAA,CAAS,MAAA,CAAO,IAAA,CAAKM,CAAM,CAAA,CAC3BN,CAAAA,CAAS,WAAA,CAAcD,CAAAA,CAAO,IAAA,CAAO,CAAA,CACrCC,CAAAA,CAAS,WAAA,CAAcD,CAAAA,CAAO,GAAA,CAAM,EAAA,CAEpCC,CAAAA,CAAS,MAAA,CAAO,CACjB,CAKD,CAeO,SAASU,EAAAA,CAAWC,CAAAA,CAAkC,CAC5D,EAAA,CAAI,CAACA,CAAAA,EAAe,OAAOA,CAAAA,EAAgB,QAAA,CAC1C,OAAAC,iCAAAA,CAAU,CAAE,IAAA,CAAK,CAAA,qBAAA,EAAwBD,CAAW,CAAA,aAAA,CAAe,CAAA,CAC5D,IAAU,CAAA,CAAA,KAAA,CAAM,QAAQ,CAAA,CAGhC,IAAME,CAAAA,CAAUF,CAAAA,CAAY,IAAA,CAAK,CAAA,CAGjC,EAAA,CAAI,oBAAA,CAAqB,IAAA,CAAKE,CAAO,CAAA,CACpC,GAAI,CACH,IAAMC,CAAAA,CAAMD,CAAAA,CAAQ,UAAA,CAAW,GAAG,CAAA,CAAIA,CAAAA,CAAU,CAAA,CAAA,EAAIA,CAAO,CAAA,CAAA;AChF/B;AAAA;AAAA;AAAA;AAAA;AAAA;AASE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACe/B;AC4HCE,QAAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-NFPYFIYS.cjs","sourcesContent":[null,"import * as THREE from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\nimport { getLogger } from '@/core';\n\n// Camera configuration constants\nconst CAMERA_CONFIG = {\n\tHUGE_THRESHOLD: 10000,\n\tLARGE_THRESHOLD: 1000,\n\tSCALE_RATIO_THRESHOLD: 100,\n\tNEAR_PLANE_FACTOR: {\n\t\tTINY: 0.0001,\n\t\tSMALL: 0.001,\n\t\tNORMAL: 0.01\n\t},\n\tFAR_PLANE_FACTOR: {\n\t\tHUGE: 100,\n\t\tLARGE: 50,\n\t\tNORMAL: 20\n\t},\n\tINITIAL_DISTANCE_MULTIPLIER: 4\n};\n\n/**\n * Updates the scene with the given meshes and camera settings.\n * If initialPositionSet is false, it positions the camera and sets the controls target based on the bounding boxes of the meshes.\n * @param scene - The THREE.Scene object to update.\n * @param meshes - An array of THREE.Mesh objects to add to the scene.\n * @param camera - The THREE.PerspectiveCamera object to position.\n * @param controls - The OrbitControls object to update.\n * @param initialPositionSet - A boolean indicating whether the initial position of the camera and controls have been set.\n */\nexport function updateScene(\n\tscene: THREE.Scene,\n\tmeshes: THREE.Object3D[],\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls,\n\tinitialPositionSet: boolean\n) {\n\tclearScene(scene);\n\n\tif (meshes.length === 0) return;\n\n\t// Add new objects (meshes, lines, points) to scene\n\tmeshes.forEach((mesh) => {\n\t\tscene.add(mesh);\n\t});\n\n\t// Calculate bounds of the new content\n\tconst unionBoundingBox = computeCombinedBoundingBox(meshes);\n\n\t// Get the center of the union bounding box\n\tconst center = unionBoundingBox.getCenter(new THREE.Vector3());\n\tconst size = unionBoundingBox.getSize(new THREE.Vector3());\n\n\t// Calculate a distance that is slightly larger than the largest dimension of the union bounding box\n\tconst maxDim = Math.max(size.x, size.y, size.z);\n\n\t// Always update camera frustum to ensure geometry is visible\n\t// This prevents clipping when geometry size changes significantly\n\tconst scaleRatio = maxDim / Math.min(size.x || 1, size.y || 1, size.z || 1);\n\n\tif (scaleRatio > CAMERA_CONFIG.SCALE_RATIO_THRESHOLD || maxDim > CAMERA_CONFIG.HUGE_THRESHOLD) {\n\t\t// Large scale range detected - use logarithmic depth buffer approach\n\t\tcamera.near = maxDim * CAMERA_CONFIG.NEAR_PLANE_FACTOR.TINY;\n\t\tcamera.far = maxDim * CAMERA_CONFIG.FAR_PLANE_FACTOR.HUGE;\n\t} else if (maxDim > CAMERA_CONFIG.LARGE_THRESHOLD) {\n\t\t// Large scene\n\t\tcamera.near = maxDim * CAMERA_CONFIG.NEAR_PLANE_FACTOR.SMALL;\n\t\tcamera.far = maxDim * CAMERA_CONFIG.FAR_PLANE_FACTOR.LARGE;\n\t} else {\n\t\t// Normal scene\n\t\tcamera.near = Math.max(0.01, maxDim * CAMERA_CONFIG.NEAR_PLANE_FACTOR.NORMAL);\n\t\tcamera.far = Math.max(2000, maxDim * CAMERA_CONFIG.FAR_PLANE_FACTOR.NORMAL);\n\t}\n\n\tcamera.updateProjectionMatrix();\n\n\t// Only reposition camera and controls on first frame\n\tif (!initialPositionSet) {\n\t\tconst distance = maxDim * CAMERA_CONFIG.INITIAL_DISTANCE_MULTIPLIER;\n\n\t\tcamera.position.set(center.x + distance * 0.8, center.y + distance, center.z + distance * 1.2);\n\t\tcontrols.target.copy(center);\n\t\tcontrols.minDistance = camera.near * 2;\n\t\tcontrols.maxDistance = camera.far * 0.9;\n\n\t\tcontrols.update();\n\t} else {\n\t\t// Update control constraints to match new frustum\n\t\tcontrols.minDistance = camera.near * 2;\n\t\tcontrols.maxDistance = camera.far * 0.9;\n\t}\n}\n\n// =========================\n// Helper functions\n// =========================\n\n/**\n * Parses a color string in multiple formats to a THREE.Color object.\n * Supported formats:\n * - Hex: \"#C7A5A5\", \"C7A5A5\"\n * - RGB: \"199, 165, 165\"\n * - CSS named colors: \"red\", \"blue\", etc.\n * @param colorString - The color string to parse.\n * @returns A THREE.Color object.\n */\nexport function parseColor(colorString: string): THREE.Color {\n\tif (!colorString || typeof colorString !== 'string') {\n\t\tgetLogger().warn(`Invalid color input: ${colorString}, using white`);\n\t\treturn new THREE.Color(0xffffff);\n\t}\n\n\tconst trimmed = colorString.trim();\n\n\t// Try hex format (#C7A5A5 or C7A5A5) — require exactly 6 hex chars\n\tif (/^#?[0-9A-Fa-f]{6}$/.test(trimmed)) {\n\t\ttry {\n\t\t\tconst hex = trimmed.startsWith('#') ? trimmed : `#${trimmed}`;\n\t\t\treturn new THREE.Color(hex);\n\t\t} catch {\n\t\t\tgetLogger().warn(`Invalid hex color: ${colorString}, using white`);\n\t\t\treturn new THREE.Color(0xffffff);\n\t\t}\n\t}\n\n\t// Try RGB format (R, G, B)\n\tif (trimmed.includes(',')) {\n\t\tconst rgb = trimmed.split(',').map((c) => parseInt(c.trim(), 10));\n\t\tif (rgb.length === 3 && rgb.every((n) => !isNaN(n) && n >= 0 && n <= 255)) {\n\t\t\treturn new THREE.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255);\n\t\t}\n\t}\n\n\t// Try CSS named color\n\ttry {\n\t\treturn new THREE.Color(trimmed.toLowerCase());\n\t} catch {\n\t\tgetLogger().warn(`Invalid color string: ${colorString}, using white`);\n\t\treturn new THREE.Color(0xffffff);\n\t}\n}\n\n/**\n * Shift objects along one world axis. Defaults to `z` — the up axis of the unified Z-up scene\n * frame (see `../coordinate-transform.ts`), so grounding subtracts the content's lowest z.\n */\nexport function applyOffset(\n\tmeshes: THREE.Object3D[],\n\toffset: number,\n\taxis: 'x' | 'y' | 'z' = 'z'\n): void {\n\tmeshes.forEach((mesh) => {\n\t\tmesh.position[axis] -= offset;\n\t});\n}\n\n/**\n * Computes the combined world-axis-aligned bounding box of a set of objects (meshes, lines, points).\n * Correctly accounts for transformations (rotation, position, scale).\n */\nexport function computeCombinedBoundingBox(meshes: THREE.Object3D[]): THREE.Box3 {\n\tconst combinedBoundingBox = new THREE.Box3();\n\tif (meshes.length === 0) return combinedBoundingBox;\n\tmeshes.forEach((mesh) => {\n\t\t// Ensure the world matrix is up to date before calculating the box\n\t\tmesh.updateMatrixWorld(true);\n\t\tconst bbox = new THREE.Box3().setFromObject(mesh);\n\t\tcombinedBoundingBox.union(bbox);\n\t});\n\treturn combinedBoundingBox;\n}\n\n/**\n * `userData.id`s of scene infrastructure that is created once at init and must survive content\n * updates: the floor, the grid, and the CSS2D label layer's group. Content (meshes/lines/points)\n * carries no such id and is cleared on every solve.\n */\nconst PERSISTENT_SCENE_IDS = new Set(['floor', 'grid', 'label-layer']);\n\n/**\n * Clears the given THREE.Scene by removing all top-level content children (everything except\n * persistent infrastructure, see {@link PERSISTENT_SCENE_IDS}) and recursively disposing of their\n * geometry and materials.\n *\n * Removes at the top level rather than traversing for meshes, so parent Groups\n * don't accumulate as ghost nodes after their mesh children are disposed.\n */\nfunction clearScene(scene: THREE.Scene): void {\n\t// Snapshot children — we mutate the array via removeFromParent during iteration\n\tconst topLevel = [...scene.children];\n\n\ttopLevel.forEach((object) => {\n\t\t// Persistent scene infrastructure (floor, grid, the CSS2D label layer) outlives content\n\t\t// updates — it's added once at init, not per solve. Removing the label-layer group here\n\t\t// orphans it, so labels created afterwards never render (the CSS2D renderer walks the live\n\t\t// scene and never finds them).\n\t\tif (PERSISTENT_SCENE_IDS.has(object.userData.id)) return;\n\n\t\t// Recursively dispose all renderable objects (meshes, lines, points) in this subtree.\n\t\tobject.traverse((child) => {\n\t\t\tconst renderable = child as Partial<THREE.Mesh> & THREE.Object3D;\n\t\t\tif (!renderable.geometry && !renderable.material) return;\n\n\t\t\trenderable.geometry?.dispose();\n\n\t\t\tconst material = renderable.material;\n\t\t\tif (!material) return;\n\t\t\tconst materials = Array.isArray(material) ? material : [material];\n\t\t\tmaterials.forEach((material) => {\n\t\t\t\t// Walk only own enumerable properties — `for...in` on a Three.js material\n\t\t\t\t// also iterates the prototype chain, which is needlessly expensive.\n\t\t\t\tfor (const value of Object.values(material)) {\n\t\t\t\t\tif (value instanceof THREE.Texture) {\n\t\t\t\t\t\tvalue.dispose();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmaterial.dispose();\n\t\t\t});\n\t\t});\n\n\t\tobject.removeFromParent();\n\t});\n}\n","import * as THREE from 'three';\n\n/**\n * An \"infinite\", distance-fading reference grid — the single strongest visual cue that reads as CAD.\n *\n * Why not `GridHelper`: it's a fixed-size square of line segments that visibly ends and looks wrong\n * once you pan or zoom past it. Instead we draw one large screen-facing plane and compute the grid\n * in the fragment shader from world coordinates, fading lines out with distance so the edge is never\n * a hard cutoff. The plane is big enough to cover any reasonable view; the fade hides its bounds.\n *\n * Two line frequencies (minor + major every 10th) give the usual graph-paper depth read. Spacing is\n * in world units (meters — the scene's normalized unit), so a `cellSize` of 1 = 1m minor cells.\n */\n\nexport interface GridOptions {\n\t/** Minor cell size in world units (meters). Default 1. */\n\tcellSize?: number;\n\t/** How many minor cells per major line. Default 10. */\n\tmajorEvery?: number;\n\t/** Minor line color. */\n\tcellColor?: THREE.ColorRepresentation;\n\t/** Major line color. */\n\tmajorColor?: THREE.ColorRepresentation;\n\t/** World-space radius at which the grid has fully faded out. Default 100. */\n\tfadeDistance?: number;\n\t/** Plane to lay the grid on. 'y' = horizontal ground (Three Y-up). Default 'y'. */\n\tplane?: 'x' | 'y' | 'z';\n}\n\nexport interface Grid {\n\t/** The grid mesh; add to the scene. Tagged `userData.id = 'grid'` so pick/fit code skips it. */\n\treadonly object: THREE.Mesh;\n\t/** Keep the fade centered on the camera so the grid feels infinite as you move. Call per frame. */\n\tupdate(cameraPosition: THREE.Vector3): void;\n\tsetVisible(visible: boolean): void;\n\tdispose(): void;\n}\n\nconst GRID_VERTEX = /* glsl */ `\n\tvarying vec3 vWorldPos;\n\tvoid main() {\n\t\tvec4 world = modelMatrix * vec4(position, 1.0);\n\t\tvWorldPos = world.xyz;\n\t\tgl_Position = projectionMatrix * viewMatrix * world;\n\t}\n`;\n\nconst GRID_FRAGMENT = /* glsl */ `\n\tprecision highp float;\n\tvarying vec3 vWorldPos;\n\n\tuniform vec2 uAxes; // indices (0=x,1=y,2=z) of the two in-plane world axes\n\tuniform float uCell;\n\tuniform float uMajor;\n\tuniform vec3 uCellColor;\n\tuniform vec3 uMajorColor;\n\tuniform vec3 uCenter; // fade center (camera position), projected onto plane\n\tuniform float uFade;\n\n\t// Antialiased grid line intensity for a given spacing, using screen-space derivatives so lines\n\t// stay ~1px regardless of zoom (the standard \"pristine grid\" technique).\n\tfloat gridLine(vec2 coord, float spacing) {\n\t\tvec2 c = coord / spacing;\n\t\tvec2 d = fwidth(c);\n\t\tvec2 g = abs(fract(c - 0.5) - 0.5) / max(d, 1e-6);\n\t\tfloat line = min(g.x, g.y);\n\t\treturn 1.0 - clamp(line, 0.0, 1.0);\n\t}\n\n\t// Index a vec3 by a float axis id (0/1/2) without dynamic indexing (WebGL1-safe).\n\tfloat axis(vec3 v, float i) {\n\t\treturn i < 0.5 ? v.x : (i < 1.5 ? v.y : v.z);\n\t}\n\n\tvoid main() {\n\t\t// Pick the two in-plane world coordinates.\n\t\tvec2 coord = vec2(axis(vWorldPos, uAxes.x), axis(vWorldPos, uAxes.y));\n\n\t\tfloat minor = gridLine(coord, uCell);\n\t\tfloat major = gridLine(coord, uCell * uMajor);\n\n\t\tvec3 color = mix(uCellColor, uMajorColor, major);\n\t\tfloat alpha = max(minor, major);\n\n\t\t// Radial fade from the camera-projected center.\n\t\tfloat dist = distance(vWorldPos, uCenter);\n\t\tfloat fade = 1.0 - clamp(dist / uFade, 0.0, 1.0);\n\t\talpha *= fade * fade;\n\n\t\tif (alpha < 0.001) discard;\n\t\tgl_FragColor = vec4(color, alpha);\n\t}\n`;\n\nexport function createGrid(options: GridOptions = {}): Grid {\n\tconst {\n\t\tcellSize = 1,\n\t\tmajorEvery = 10,\n\t\tcellColor = 0x888888,\n\t\tmajorColor = 0x444444,\n\t\tfadeDistance = 100,\n\t\tplane = 'y'\n\t} = options;\n\n\t// The two in-plane world axes (0=x,1=y,2=z): ground 'y' grids over x,z; 'z' over x,y; 'x' over y,z.\n\tconst axes =\n\t\tplane === 'y'\n\t\t\t? new THREE.Vector2(0, 2) // x, z\n\t\t\t: plane === 'z'\n\t\t\t\t? new THREE.Vector2(0, 1) // x, y\n\t\t\t\t: new THREE.Vector2(1, 2); // y, z\n\n\tconst size = fadeDistance * 2.5; // comfortably larger than the fade radius\n\tconst geometry = new THREE.PlaneGeometry(size, size);\n\n\t// PlaneGeometry is in the XY plane by default; rotate it onto the requested world plane.\n\tif (plane === 'y') geometry.rotateX(-Math.PI / 2);\n\telse if (plane === 'x') geometry.rotateY(Math.PI / 2);\n\n\tconst material = new THREE.ShaderMaterial({\n\t\tvertexShader: GRID_VERTEX,\n\t\tfragmentShader: GRID_FRAGMENT,\n\t\ttransparent: true,\n\t\tdepthWrite: false,\n\t\tside: THREE.DoubleSide,\n\t\tuniforms: {\n\t\t\tuAxes: { value: axes },\n\t\t\tuCell: { value: cellSize },\n\t\t\tuMajor: { value: majorEvery },\n\t\t\tuCellColor: { value: new THREE.Color(cellColor) },\n\t\t\tuMajorColor: { value: new THREE.Color(majorColor) },\n\t\t\tuCenter: { value: new THREE.Vector3() },\n\t\t\tuFade: { value: fadeDistance }\n\t\t}\n\t});\n\n\tconst mesh = new THREE.Mesh(geometry, material);\n\tmesh.name = 'grid';\n\tmesh.userData.id = 'grid'; // excluded from raycasting/fit-to-view, like the floor\n\tmesh.renderOrder = -1; // draw before content so transparent geometry blends over it\n\n\tconst center = new THREE.Vector3();\n\n\treturn {\n\t\tobject: mesh,\n\t\tupdate: (cameraPosition) => {\n\t\t\t// Re-center the plane and the fade on the camera so the grid tracks the view \"infinitely\".\n\t\t\t// Keep the plane's own axis fixed (don't lift the ground grid up to the camera height).\n\t\t\tif (plane === 'y') {\n\t\t\t\tmesh.position.set(cameraPosition.x, 0, cameraPosition.z);\n\t\t\t\tcenter.set(cameraPosition.x, 0, cameraPosition.z);\n\t\t\t} else if (plane === 'z') {\n\t\t\t\tmesh.position.set(cameraPosition.x, cameraPosition.y, 0);\n\t\t\t\tcenter.set(cameraPosition.x, cameraPosition.y, 0);\n\t\t\t} else {\n\t\t\t\tmesh.position.set(0, cameraPosition.y, cameraPosition.z);\n\t\t\t\tcenter.set(0, cameraPosition.y, cameraPosition.z);\n\t\t\t}\n\t\t\tmaterial.uniforms.uCenter.value.copy(center);\n\t\t},\n\t\tsetVisible: (visible) => {\n\t\t\tmesh.visible = visible;\n\t\t},\n\t\tdispose: () => {\n\t\t\tgeometry.dispose();\n\t\t\tmaterial.dispose();\n\t\t}\n\t};\n}\n","import * as THREE from 'three';\nimport { ViewHelper } from 'three/addons/helpers/ViewHelper.js';\n\nimport type { CameraController } from './camera-controller';\n\n/**\n * The corner nav-cube/axis gizmo. Uses three's {@link ViewHelper} purely as the rendered widget, but\n * NOT its click→animate behavior: ViewHelper's built-in snap assumes a Y-up world and animates the\n * camera straight onto the up axis, which in our Z-up scene rolls the view and makes the gizmo jitter\n * at the pole. Instead we hit-test the axis sprites ourselves and drive the viewer's up-aware camera\n * controller, which snaps (no animation) with a pole nudge so the orbit basis never degenerates.\n *\n * Integration points with the viewer's dual-camera setup:\n * 1. The snap frames the current orbit target via the controller, so it rotates about what the user\n * is looking at (not the world origin).\n * 2. The nav cube is inherently a 3D-orientation tool, so if the viewer is in orthographic (2D) mode\n * when the gizmo is clicked, we first flip back to perspective.\n *\n * Caller responsibilities (mirror ViewHelper's own contract):\n * - call {@link ViewGizmo.render} *after* the main scene render each frame (overlay viewport),\n * - call {@link ViewGizmo.update} each frame (no-op now; kept for API symmetry),\n * - forward pointer clicks to {@link ViewGizmo.handleClick}.\n */\nexport interface ViewGizmo {\n\trender(renderer: THREE.WebGLRenderer): void;\n\tupdate(delta: number): void;\n\t/** Hit-test a click. Returns true if it hit the gizmo (and a view change started). */\n\thandleClick(event: MouseEvent): boolean;\n\treadonly isAnimating: boolean;\n\t/** Show/hide the gizmo at runtime. Hidden = not rendered and not click-hittable. */\n\tsetVisible(visible: boolean): void;\n\tisVisible(): boolean;\n\tdispose(): void;\n}\n\ninterface ViewGizmoDeps {\n\t/** The perspective (primary) camera the gizmo visualizes and re-orients. */\n\tcamera: THREE.PerspectiveCamera;\n\tdomElement: HTMLElement;\n\tcontroller: CameraController;\n}\n\nexport function createViewGizmo(deps: ViewGizmoDeps): ViewGizmo {\n\tconst { camera, domElement, controller } = deps;\n\n\tconst helper = new ViewHelper(camera, domElement);\n\thelper.setLabels('X', 'Y', 'Z');\n\n\tlet visible = true;\n\n\t// Our own hit-test against the helper's axis sprites, mirroring ViewHelper's internal viewport math\n\t// (a `dim`×`dim` square in the corner given by `location`). We do this instead of ViewHelper's own\n\t// `handleClick` so the camera move goes through the viewer's up-aware controller — ViewHelper's\n\t// built-in snap assumes a Y-up world and animates straight onto the pole, which rolls the view and\n\t// makes the gizmo jitter in our Z-up scene.\n\tconst DIM = 128;\n\tconst raycaster = new THREE.Raycaster();\n\tconst gizmoCamera = new THREE.OrthographicCamera(-2, 2, 2, -2, 0, 4);\n\tgizmoCamera.position.set(0, 0, 2);\n\n\t// Map a clicked axis sprite to the world-space view direction (from target toward camera).\n\tconst AXIS_DIRECTIONS: Record<string, THREE.Vector3> = {\n\t\tposX: new THREE.Vector3(1, 0, 0),\n\t\tnegX: new THREE.Vector3(-1, 0, 0),\n\t\tposY: new THREE.Vector3(0, 1, 0),\n\t\tnegY: new THREE.Vector3(0, -1, 0),\n\t\tposZ: new THREE.Vector3(0, 0, 1),\n\t\tnegZ: new THREE.Vector3(0, 0, -1)\n\t};\n\n\t/** Which axis sprite (if any) a click landed on. Returns its `userData.type` or null. */\n\tconst pickAxis = (event: MouseEvent): string | null => {\n\t\tconst rect = domElement.getBoundingClientRect();\n\t\t// The gizmo viewport sits in the bottom-right corner (helper.location defaults: right/bottom 0).\n\t\tconst offsetX = rect.left + domElement.offsetWidth - DIM - helper.location.right;\n\t\tconst offsetY = rect.top + domElement.offsetHeight - DIM - helper.location.bottom;\n\n\t\tconst mouse = new THREE.Vector2(\n\t\t\t((event.clientX - offsetX) / DIM) * 2 - 1,\n\t\t\t-((event.clientY - offsetY) / DIM) * 2 + 1\n\t\t);\n\t\t// Outside the gizmo square — not our click.\n\t\tif (Math.abs(mouse.x) > 1 || Math.abs(mouse.y) > 1) return null;\n\n\t\t// Orient the helper as it's rendered (inverse of the camera), so the sprites are where the user\n\t\t// sees them, then raycast the interactive axis sprites.\n\t\thelper.quaternion.copy(camera.quaternion).invert();\n\t\thelper.updateMatrixWorld();\n\n\t\traycaster.setFromCamera(mouse, gizmoCamera);\n\t\tconst hits = raycaster.intersectObjects(helper.children, false);\n\t\tfor (const hit of hits) {\n\t\t\tconst type = hit.object.userData?.type;\n\t\t\tif (typeof type === 'string' && type in AXIS_DIRECTIONS) return type;\n\t\t}\n\t\treturn null;\n\t};\n\n\tconst handleClick = (event: MouseEvent): boolean => {\n\t\tif (!visible) return false;\n\n\t\tconst axis = pickAxis(event);\n\t\tif (!axis) return false;\n\n\t\t// The cube orients in 3D, so a click while in 2D returns us to perspective first.\n\t\tif (controller.getProjection() === 'orthographic') {\n\t\t\tcontroller.setProjection('perspective');\n\t\t}\n\n\t\t// Snap directly via the up-aware controller — no animation, no Y-up pole roll.\n\t\tcontroller.setViewDirection(AXIS_DIRECTIONS[axis]!, false);\n\t\treturn true;\n\t};\n\n\treturn {\n\t\trender: (renderer) => {\n\t\t\tif (!visible) return;\n\t\t\t// ViewHelper.render() calls renderer.render(this, orthoCamera), which with the default\n\t\t\t// autoClear=true clears the FULL framebuffer (to the scene's grey clear color) before drawing\n\t\t\t// the cube in its corner viewport — wiping the just-rendered scene. It only needs the depth\n\t\t\t// clear it does internally (clearDepth). So suppress the automatic color/depth clear here.\n\t\t\tconst prevAutoClear = renderer.autoClear;\n\t\t\trenderer.autoClear = false;\n\t\t\thelper.render(renderer);\n\t\t\trenderer.autoClear = prevAutoClear;\n\t\t},\n\t\t// ViewHelper.update() unconditionally rewrites camera.position from (center, radius, q1) — at\n\t\t// rest (radius 0, center origin) that pins the camera to the origin every frame, blanking the\n\t\t// view. It's only meant to run while a click-snap is animating, so guard on `animating`.\n\t\tupdate: (delta) => {\n\t\t\tif (helper.animating) helper.update(delta);\n\t\t},\n\t\thandleClick,\n\t\tget isAnimating() {\n\t\t\treturn helper.animating;\n\t\t},\n\t\tsetVisible: (value) => {\n\t\t\tvisible = value;\n\t\t},\n\t\tisVisible: () => visible,\n\t\tdispose: () => helper.dispose()\n\t};\n}\n","import * as THREE from 'three';\nimport { Line2 } from 'three/addons/lines/Line2.js';\nimport { LineGeometry } from 'three/addons/lines/LineGeometry.js';\nimport { LineMaterial } from 'three/addons/lines/LineMaterial.js';\n\nimport type { LabelLayer, LabelHandle } from './label-layer';\n\n/**\n * A two-click distance measurement tool — the CAD verb users expect. Click a point, click a second,\n * read the distance off a label on the connecting line; a third click starts a new measurement.\n *\n * Picking snaps to geometry so measurements are exact, not \"wherever the ray happened to land\":\n * on a mesh hit we snap to the nearest vertex of the struck triangle if it's within\n * {@link MeasureOptions.snapPixels} on screen, else use the raw hit point. This is a cheap local\n * snap (three candidate vertices), no spatial index — enough for clean vertex-to-vertex measurement\n * without the cost/complexity of full edge/midpoint snapping (a later refinement).\n *\n * The tool is dormant until {@link MeasureTool.setEnabled}(true). While enabled it intercepts clicks\n * (the caller forwards them and swallows the event when {@link MeasureTool.handleClick} returns\n * true) so measuring doesn't also select objects.\n */\n\nexport interface MeasureTool {\n\tsetEnabled(enabled: boolean): void;\n\tisEnabled(): boolean;\n\t/** Process a click. Returns true if the tool consumed it (caller should not also select). */\n\thandleClick(event: MouseEvent): boolean;\n\t/**\n\t * Process pointer movement to preview the next snap point — a ghost marker tracks the cursor and\n\t * jumps to the vertex a click would snap to, so users can aim before committing. No-op when the\n\t * tool is disabled. The caller forwards mousemove; nothing is consumed.\n\t */\n\thandleMove(event: MouseEvent): void;\n\t/** Clear the current measurement (markers, line, label). */\n\tclear(): void;\n\tdispose(): void;\n}\n\nexport interface MeasureOptions {\n\t/** Snap to a vertex when the cursor is within this many screen pixels of it. Default 12. */\n\tsnapPixels?: number;\n\t/** Marker + line color. Default yellow. */\n\tcolor?: THREE.ColorRepresentation;\n\t/** CSS class applied to the distance label, for styling. */\n\tlabelClassName?: string;\n\t/**\n\t * Format the measurement → label text. Receives the straight-line `distance` and the per-axis\n\t * `delta` (|b − a| on each axis). May return multi-line text or HTML; the default renders the\n\t * total plus a Δx/Δy/Δz breakdown. Old `(distance) => string` callbacks remain valid.\n\t */\n\tformat?: (distance: number, delta: THREE.Vector3) => string;\n}\n\ninterface MeasureDeps {\n\tcanvas: HTMLCanvasElement;\n\tscene: THREE.Scene;\n\tgetActiveCamera: () => THREE.Camera;\n\tlabelLayer: LabelLayer;\n\toptions?: MeasureOptions;\n}\n\nconst DEFAULT_SNAP_PIXELS = 12;\nconst DEFAULT_COLOR = 0xffcc00;\n// Line/Points raycast threshold as a fraction of the view distance (camera→target). ~1.5% gives a\n// comfortable few-pixel grab band at typical framing without snapping to far-off geometry.\nconst LINE_PICK_FRACTION = 0.015;\nconst fmt = (n: number) => `${n.toPrecision(3)} m`;\nconst defaultFormat = (d: number, delta: THREE.Vector3) =>\n\t`${fmt(d)}\\nΔx ${fmt(delta.x)} Δy ${fmt(delta.y)} Δz ${fmt(delta.z)}`;\n\n/**\n * The vertex indices to consider snapping to for a given hit, by object type:\n * - Mesh: the three vertices of the struck triangle (`hit.face`).\n * - Line / LineSegments: the two endpoints of the struck segment (`hit.index`, `hit.index + 1`).\n * - Points: the struck vertex (`hit.index`).\n * Returns null when the hit carries no usable index info (e.g. a fat `Line2`), so the caller keeps\n * the raw hit point.\n */\nfunction snapCandidateIndices(hit: THREE.Intersection): number[] | null {\n\tconst obj = hit.object;\n\tif (obj instanceof THREE.Mesh) {\n\t\treturn hit.face ? [hit.face.a, hit.face.b, hit.face.c] : null;\n\t}\n\tif (obj instanceof THREE.Points) {\n\t\treturn hit.index != null ? [hit.index] : null;\n\t}\n\t// THREE.Line / LineSegments / LineLoop. `hit.index` is the first vertex of the struck segment.\n\tif (obj instanceof THREE.Line) {\n\t\treturn hit.index != null ? [hit.index, hit.index + 1] : null;\n\t}\n\treturn null;\n}\n\n/**\n * Snap a raycast hit to the nearest geometry vertex within `snapPixels` on screen; otherwise return\n * the raw hit point. Works for meshes (triangle vertices), lines (segment endpoints), and points\n * (the vertex itself). Pure (no DOM) so it's unit-testable: it takes the screen size explicitly\n * rather than reading the canvas. Exported for that reason.\n *\n * Falls back to the raw point for hits without usable vertex indices or positions.\n */\nexport function snapToVertex(\n\thit: THREE.Intersection,\n\tcamera: THREE.Camera,\n\tscreenSize: { width: number; height: number },\n\tsnapPixels: number\n): THREE.Vector3 {\n\tconst raw = hit.point.clone();\n\tconst obj = hit.object as THREE.Object3D & { geometry?: THREE.BufferGeometry };\n\tconst indices = snapCandidateIndices(hit);\n\tif (!indices || !obj.geometry) return raw;\n\n\tconst pos = obj.geometry.attributes.position as THREE.BufferAttribute | undefined;\n\tif (!pos) return raw;\n\n\tconst toScreen = (worldP: THREE.Vector3): THREE.Vector2 => {\n\t\tconst ndc = worldP.clone().project(camera);\n\t\treturn new THREE.Vector2(\n\t\t\t((ndc.x + 1) / 2) * screenSize.width,\n\t\t\t((1 - ndc.y) / 2) * screenSize.height\n\t\t);\n\t};\n\tconst rawScreen = toScreen(raw);\n\n\tlet best = raw;\n\tlet bestPx = snapPixels;\n\tfor (const idx of indices) {\n\t\tif (idx >= pos.count) continue; // guard the line `index + 1` against the geometry end\n\t\tconst local = new THREE.Vector3().fromBufferAttribute(pos, idx);\n\t\tconst world = local.applyMatrix4(obj.matrixWorld);\n\t\tconst px = toScreen(world).distanceTo(rawScreen);\n\t\tif (px < bestPx) {\n\t\t\tbestPx = px;\n\t\t\tbest = world;\n\t\t}\n\t}\n\treturn best;\n}\n\nexport function createMeasureTool(deps: MeasureDeps): MeasureTool {\n\tconst { canvas, scene, getActiveCamera, labelLayer, options = {} } = deps;\n\tconst snapPixels = options.snapPixels ?? DEFAULT_SNAP_PIXELS;\n\tconst color = new THREE.Color(options.color ?? DEFAULT_COLOR);\n\tconst format = options.format ?? defaultFormat;\n\n\tconst raycaster = new THREE.Raycaster();\n\tconst pointer = new THREE.Vector2();\n\n\tlet enabled = false;\n\tconst points: THREE.Vector3[] = [];\n\n\t// Visuals, created lazily and reused. Markers are small always-on-top points; the line connects\n\t// them; the label rides the line's midpoint.\n\tconst markers: THREE.Points[] = [];\n\tlet line: Line2 | null = null;\n\tlet label: LabelHandle | null = null;\n\n\tconst markerMaterial = new THREE.PointsMaterial({\n\t\tcolor,\n\t\tsize: 8,\n\t\tsizeAttenuation: false,\n\t\tdepthTest: false // markers stay visible through geometry, like CAD snap dots\n\t});\n\n\t// A hollow-feeling preview dot: dimmer + bigger than a committed marker so the snap target the\n\t// next click will lock onto is obvious before clicking. Shown only while hovering geometry.\n\tconst hoverMaterial = new THREE.PointsMaterial({\n\t\tcolor,\n\t\tsize: 11,\n\t\tsizeAttenuation: false,\n\t\tdepthTest: false,\n\t\ttransparent: true,\n\t\topacity: 0.5\n\t});\n\tlet hoverMarker: THREE.Points | null = null;\n\n\tconst showHover = (p: THREE.Vector3 | null) => {\n\t\tif (!p) {\n\t\t\tif (hoverMarker) hoverMarker.visible = false;\n\t\t\treturn;\n\t\t}\n\t\tif (!hoverMarker) {\n\t\t\tconst geometry = new THREE.BufferGeometry();\n\t\t\tgeometry.setAttribute('position', new THREE.Float32BufferAttribute([0, 0, 0], 3));\n\t\t\thoverMarker = new THREE.Points(geometry, hoverMaterial);\n\t\t\thoverMarker.renderOrder = 1000;\n\t\t\thoverMarker.userData.id = 'measure';\n\t\t\thoverMarker.raycast = () => {};\n\t\t\tscene.add(hoverMarker);\n\t\t}\n\t\thoverMarker.position.copy(p);\n\t\thoverMarker.visible = true;\n\t};\n\n\tconst makeMarker = (p: THREE.Vector3): THREE.Points => {\n\t\tconst geometry = new THREE.BufferGeometry();\n\t\tgeometry.setAttribute('position', new THREE.Float32BufferAttribute([p.x, p.y, p.z], 3));\n\t\tconst marker = new THREE.Points(geometry, markerMaterial);\n\t\tmarker.renderOrder = 999;\n\t\tmarker.userData.id = 'measure'; // excluded from pick/fit\n\t\tmarker.raycast = () => {}; // don't let markers be measure targets themselves\n\t\tscene.add(marker);\n\t\treturn marker;\n\t};\n\n\tconst clear = () => {\n\t\tpoints.length = 0;\n\t\tmarkers.forEach((m) => {\n\t\t\tm.geometry.dispose();\n\t\t\tm.removeFromParent();\n\t\t});\n\t\tmarkers.length = 0;\n\t\tif (line) {\n\t\t\tline.geometry.dispose();\n\t\t\t(line.material as LineMaterial).dispose();\n\t\t\tline.removeFromParent();\n\t\t\tline = null;\n\t\t}\n\t\tlabel?.remove();\n\t\tlabel = null;\n\t};\n\n\tconst drawMeasurement = () => {\n\t\tif (points.length !== 2) return;\n\t\tconst [a, b] = points;\n\n\t\tconst geometry = new LineGeometry();\n\t\tgeometry.setPositions([a.x, a.y, a.z, b.x, b.y, b.z]);\n\t\tconst material = new LineMaterial({ color });\n\t\t(material as LineMaterial & { linewidth: number; depthTest: boolean }).linewidth = 2;\n\t\tmaterial.depthTest = false;\n\n\t\tline = new Line2(geometry, material);\n\t\tline.renderOrder = 998;\n\t\tline.userData.id = 'measure';\n\t\tline.raycast = () => {};\n\t\tscene.add(line);\n\n\t\tconst mid = a.clone().add(b).multiplyScalar(0.5);\n\t\tconst delta = new THREE.Vector3(Math.abs(b.x - a.x), Math.abs(b.y - a.y), Math.abs(b.z - a.z));\n\t\tlabel = labelLayer.addLabel(format(a.distanceTo(b), delta), mid, options.labelClassName);\n\t};\n\n\t/** Raycast the cursor and return the snapped pick point, or null if it hit no measurable geometry. */\n\tconst pickPoint = (event: MouseEvent): THREE.Vector3 | null => {\n\t\tconst rect = canvas.getBoundingClientRect();\n\t\tpointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;\n\t\tpointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;\n\n\t\tconst camera = getActiveCamera();\n\t\traycaster.setFromCamera(pointer, camera);\n\n\t\t// Lines and points have no surface area, so they're only \"hit\" when the ray passes within a\n\t\t// world-space threshold of them — left at the default ~1 unit they're nearly impossible to\n\t\t// click. Scale the threshold with the view size (camera distance to the orbit target, here the\n\t\t// origin) so the pick tolerance stays roughly constant on screen as the user zooms.\n\t\tconst viewScale = camera.position.length();\n\t\traycaster.params.Line = { threshold: viewScale * LINE_PICK_FRACTION };\n\t\traycaster.params.Points = { threshold: viewScale * LINE_PICK_FRACTION };\n\n\t\tconst hits = raycaster\n\t\t\t.intersectObjects(scene.children, true)\n\t\t\t.filter((i) => i.object.userData.id !== 'measure' && i.object.userData.id !== 'grid');\n\n\t\tif (hits.length === 0) return null;\n\t\treturn snapToVertex(hits[0], camera, { width: rect.width, height: rect.height }, snapPixels);\n\t};\n\n\tconst handleMove = (event: MouseEvent): void => {\n\t\tif (!enabled) return;\n\t\tshowHover(pickPoint(event));\n\t};\n\n\tconst handleClick = (event: MouseEvent): boolean => {\n\t\tif (!enabled) return false;\n\n\t\t// A third click after a completed measurement starts fresh.\n\t\tif (points.length === 2) clear();\n\n\t\tconst point = pickPoint(event);\n\t\tif (point === null) return true; // consumed: a measuring click that missed still isn't a select\n\n\t\tpoints.push(point);\n\t\tmarkers.push(makeMarker(point));\n\n\t\tif (points.length === 2) drawMeasurement();\n\t\treturn true;\n\t};\n\n\treturn {\n\t\tsetEnabled: (value) => {\n\t\t\tenabled = value;\n\t\t\tif (!value) {\n\t\t\t\tclear();\n\t\t\t\tshowHover(null);\n\t\t\t}\n\t\t},\n\t\tisEnabled: () => enabled,\n\t\thandleClick,\n\t\thandleMove,\n\t\tclear,\n\t\tdispose: () => {\n\t\t\tclear();\n\t\t\tif (hoverMarker) {\n\t\t\t\thoverMarker.geometry.dispose();\n\t\t\t\thoverMarker.removeFromParent();\n\t\t\t\thoverMarker = null;\n\t\t\t}\n\t\t\tmarkerMaterial.dispose();\n\t\t\thoverMaterial.dispose();\n\t\t}\n\t};\n}\n"]}
|