You could also go a cheeky route and trick the compiler another way ^^
// this is outside your class:
declare type Material = MeshStandardMaterial;
// this is your field inside the class:
@serializable(Material) materialToSetColor?: Material;
You could also go a cheeky route and trick the compiler another way ^^
// this is outside your class:
declare type Material = MeshStandardMaterial;
// this is your field inside the class:
@serializable(Material) materialToSetColor?: Material;
Because it actually just sees the typename (Material
is knows but MeshStandardMaterial
it doesnt know) and then tries to find a type in C# that is knows with the same name ^^
but Iāll make sure to add support for these types right now
we have a little list of threejs specific types that we map to Unity types
This is crazy, I guess you donāt know the power of TS until you actually use it haha. I appreciate the help Marcel!
Problem solved.
by user 198447544408342528
No problem, good luck
I would love to have the documentation for the attributes available in the engine (such as @type) if one exists
by user 198447544408342528
Can you elaborate? You mean for something like this //@type UnityEngine.Material
?
In form of a Typescript decorator? (attributes in C# are called decorators in typescript^^)
Yes! Thank you for letting me know
So that is a TS thing huh. not Needleās unique or ThreeJS⦠interesting
by user 198447544408342528
Yeah thatās a TS thing
@serializable
is a Needle thing tho
These are the ones we currently have: Typescript Decorators | Needle Engine Documentation
amazing, thanks! I will make sure to read it through
by user 198447544408342528
If you make a clean install (hold ALT + click install in the ExportInfo) you should have the updated component compiler
updated as in with the materialmesh ā unityengine.material?
You are quick as a bolt Marcel :>
by user 198447544408342528
I have a weird behaviour happening. I try to cache the materialās color on start() and on update, change it to limegreen whenever it is interactable.
What happens is, as soon as the first interaction occurs, the materialās color is changed to black. any idea whats wrong?
import { Behaviour, EventList, serializable } from "@needle-tools/engine"
import { Color, Material, MeshStandardMaterial } from "three";
export class InteractableObject extends Behaviour {
//@type UnityEngine.Material
/** The material to set the color of interactable object. Leave undefined to not apply material change */
@serializable(MeshStandardMaterial) materialToSetColor?: MeshStandardMaterial;
/** Is object isInteractable */
@serializable() isInteractable?: boolean;
/** The event that will occur opun interaction */
@serializable(EventList) onInteraction?: EventList;
/** The color of the interactable object. */
colorOfInteractable = Color.NAMES.limegreen;
/** caching the starting color */
startingColor?;
start(): void {
this.startingColor = this.materialToSetColor?.color;
}
update(): void {
this.materialToSetColor!.color = this.isInteractable ? this.colorOfInteractable : this.startingColor!;
}
public changeInteractable(isInteractable: boolean): void {
console.log(`1 isinteracable ${this.isInteractable}`);
this.isInteractable = isInteractable;
console.log(`2 isinteracable ${this.isInteractable}`);
}
public interact(): (() => void) | undefined{
console.log(`isinteracable ${this.isInteractable}`);
if (!this.isInteractable) return undefined;
return () => this.onInteraction?.invoke();
}
}
by user 198447544408342528
Yes. You can get rid of the @type annotation then the compiler version is 1.11.0 (visible in the ComponentCompiler component or the npmdef footer if you use any of those yet)
The color names is just a hex string and not a Three Color. You can use it with new Color(Color.NAMES.limegreen)
i think and cache that then