// Generated by scripts/generate.mjs from bindings/api.mjs. Do not edit.
///|
#external
pub type MeshSurfaceSampler
///|
#module("@mizchi/three-mbt/modeling-workflow")
pub extern "js" fn MeshSurfaceSampler::MeshSurfaceSampler(
mesh : Mesh,
) -> MeshSurfaceSampler = "meshSurfaceSampler"
///|
extern "js" fn MeshSurfaceSampler::ffi_set_weight_attribute(
self : MeshSurfaceSampler,
value : Nullable[String],
) -> Unit =
#| (self, value) => { self.setWeightAttribute(value); self.distribution = null; }
///|
pub fn MeshSurfaceSampler::set_weight_attribute(
self : MeshSurfaceSampler,
value : String?,
) -> Unit {
self.ffi_set_weight_attribute(Nullable::from_option(value))
}
///|
extern "js" fn MeshSurfaceSampler::ffi_build(
self : MeshSurfaceSampler,
) -> JsResult[MeshSurfaceSampler] =
#| (self) => { try { return { ok: true, value: (() => { const weights = self.weightAttribute; if (weights) for(let i=0;i0) || !Number.isFinite(d[d.length-1])) throw new RangeError("Positive total surface area and weight required"); return self; })() }; } catch (error) { return { ok: false, error: String(error) }; } }
///|
pub fn MeshSurfaceSampler::build(
self : MeshSurfaceSampler,
) -> MeshSurfaceSampler raise ModelingError {
match self.ffi_build().into_result() {
Ok(value) => value
Err(message) => raise ModelingError(message)
}
}
///|
pub extern "js" fn MeshSurfaceSampler::set_random_generator(
self : MeshSurfaceSampler,
random : () -> Double,
) -> MeshSurfaceSampler =
#| (self, random) => self.setRandomGenerator(random)
///|
extern "js" fn MeshSurfaceSampler::ffi_sample(
self : MeshSurfaceSampler,
position : Vector3,
) -> JsResult[MeshSurfaceSampler] =
#| (self, position) => { try { return { ok: true, value: (() => { if (!self.distribution || !(self.distribution.at(-1)>0)) throw new Error("Build the sampler before sampling"); return self.sample(position); })() }; } catch (error) { return { ok: false, error: String(error) }; } }
///|
pub fn MeshSurfaceSampler::sample(
self : MeshSurfaceSampler,
position : Vector3,
) -> MeshSurfaceSampler raise ModelingError {
match self.ffi_sample(position).into_result() {
Ok(value) => value
Err(message) => raise ModelingError(message)
}
}
///|
extern "js" fn MeshSurfaceSampler::ffi_sample_full(
self : MeshSurfaceSampler,
position : Vector3,
normal : Vector3,
color : Color,
uv : Vector2,
) -> JsResult[MeshSurfaceSampler] =
#| (self, position, normal, color, uv) => { try { return { ok: true, value: (() => { if (!self.distribution || !(self.distribution.at(-1)>0)) throw new Error("Build the sampler before sampling"); return self.sample(position,normal,color,uv); })() }; } catch (error) { return { ok: false, error: String(error) }; } }
///|
pub fn MeshSurfaceSampler::sample_full(
self : MeshSurfaceSampler,
position : Vector3,
normal : Vector3,
color : Color,
uv : Vector2,
) -> MeshSurfaceSampler raise ModelingError {
match self.ffi_sample_full(position, normal, color, uv).into_result() {
Ok(value) => value
Err(message) => raise ModelingError(message)
}
}