Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh : check case mesh was provided with no .material or .geometry set. #84

Closed
vatro opened this issue Jun 13, 2022 · 2 comments
Closed

Comments

@vatro
Copy link
Owner

vatro commented Jun 13, 2022

"this will most probably never happen" or "it can / will never happen" ?
If in both cases three.js throws an Error (I'm pretty sure it will) at some point, we don't need to do it -> simplify.

/** IMPORTANT Executed when / if an instance was provided **on initializiation** -> only once if at all! */
function on_instance_provided(): void {
// check if type of provided instance is correct and then do something with it...
if (mesh.type === "Mesh") {
if (mesh.geometry) {
geometry = mesh.geometry
if (verbose && log_dev) console.debug(...c_dev(c_name, "saved geometry:", { geometry }))
} else {
// this will most probably never happen ( TODO when would it?)
throw new Error("SVELTHREE > Mesh : 'mesh' provided, but has no geometry!")
}
if (mesh.material) {
material = mesh.material as AnyMaterial
if (verbose && log_dev) console.debug(...c_dev(c_name, "saved material:", { material }))
} else {
// this will most probably never happen ( TODO when would it?)
throw new Error("SVELTHREE > Mesh : 'mesh' provided, but has no material!")
}
mesh.userData.initScale = mesh.scale.x
mesh.userData.svelthreeComponent = self
} else {
throw new Error(
`SVELTHREE > Mesh Error: provided 'mesh' instance has wrong type '${mesh.type}', should be 'Mesh'!`
)
}
}

@vatro vatro added this to the 1.0.0-next.1 milestone Jun 13, 2022
@vatro vatro assigned vatro and unassigned vatro Jun 13, 2022
@vatro vatro added the good first issue Good for newcomers label Jun 13, 2022
@vatro
Copy link
Owner Author

vatro commented Jun 20, 2022

// NO ERROR
// has default geometry: empty `BufferGeometry`
// has default material: white `BasicMaterial`
const new_mesh = new _Mesh()

// three.js throws Error: `Uncaught (in promise) TypeError: Cannot read properties of null (reading 'morphAttributes')`
const new_mesh = new _Mesh(null, null)

// SVELTHREE throws Error: `Error: SVELTHREE > Mesh : 'mesh' provided, but has no geometry!`
const new_mesh = new _Mesh()
new_mesh.material = null
new_mesh.geometry = null

// SVELTHREE throws Error: `Error: SVELTHREE > Mesh : 'mesh' provided, but has no material!`
const new_mesh = new _Mesh()
new_mesh.material = null

// SVELTHREE throws Error: Error: `SVELTHREE > Mesh Error: provided 'mesh' instance has wrong type 'OrthographicCamera', should be 'Mesh'!`
const new_mesh = new _OrthographicCamera()

Means: it's ok as it is, but remove unsure comments.

@vatro
Copy link
Owner Author

vatro commented Jun 20, 2022

resolved, see 3478ee6

@vatro vatro closed this as completed Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant