Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/AnyCadComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { GltfModel } from "./three-components/GltfModel"
import { JscadModel } from "./three-components/JscadModel"
import { FootprinterModel } from "./three-components/FootprinterModel"
import { tuple } from "./utils/tuple"
import { getModelUrl } from "./utils/get-model-url"
import { Html } from "./react-three/Html"

export const AnyCadComponent = ({
Expand Down Expand Up @@ -46,10 +47,7 @@ export const AnyCadComponent = ({
})?.name
}, [circuitJson, cad_component.source_component_id])

const url =
cad_component.model_obj_url ??
cad_component.model_wrl_url ??
cad_component.model_stl_url
const url = getModelUrl(cad_component)
const gltfUrl = cad_component.model_gltf_url
const rotationOffset = cad_component.rotation
? tuple(
Expand Down
20 changes: 20 additions & 0 deletions src/utils/get-model-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function getModelUrl(component: {
model_obj_url?: string
model_wrl_url?: string
model_stl_url?: string
footprinter_string?: string
}): string | undefined {
return (
component.model_obj_url ??
component.model_wrl_url ??
component.model_stl_url ??
getKicadUrl(component.footprinter_string)
)
}

function getKicadUrl(footprinter?: string): string | undefined {
if (!footprinter) return undefined
if (!footprinter.startsWith("kicad:")) return undefined
const path = footprinter.replace(/^kicad:/, "").replace(/:/g, "/")
return `https://kicad-mod-cache.tscircuit.com/${path}.wrl`
}
9 changes: 3 additions & 6 deletions src/utils/render-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ import { executeJscadOperations } from "jscad-planner"
import * as THREE from "three"
import { load3DModel } from "./load-model"
import type { CadComponent } from "circuit-json"
import { getModelUrl } from "./get-model-url"

export async function renderComponent(
component: CadComponent,
scene: THREE.Scene,
) {
// Handle STL/OBJ models first
const url =
component.model_obj_url ??
component.model_wrl_url ??
component.model_stl_url ??
component.model_gltf_url
// Handle STL/OBJ/WRL/GLTF models first
const url = getModelUrl(component) ?? component.model_gltf_url
Comment on lines +17 to +18

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Keep GLTF model priority over footprinter URLs

By resolving getModelUrl(component) ?? component.model_gltf_url, a component that provides both a model_gltf_url and a kicad: footprinter will now fetch the synthesized .wrl first and never reach the GLTF. Prior behaviour (and the summary that says explicit model URLs should be preferred over footprinter strings) rendered the provided GLTF, which is typically the higher fidelity asset. This reversal will cause components that ship both assets to render the fallback instead of the intended GLTF model. The same precedence is used in AnyCadComponent, so the regression affects both render paths. Consider checking model_gltf_url before translating the footprinter string or moving GLTF support into getModelUrl ahead of the footprinter fallback.

Useful? React with 👍 / 👎.

if (url) {
const model = await load3DModel(url)
if (model) {
Expand Down