Outline of clicked/selected object

I found this example on three.js three.js examples Can we do this this effect with needle? I

Original Post on Discord

by user 869976161550217286

Yes you can either implement the example code from above (see the three.js sample code)

Or add a new postprocessing effect.

For that run npm i postprocessing in your package directory

And then add this to your scripts:

import { EffectProviderResult, PostProcessingEffect, registerCustomEffectType, serializable } from "@needle-tools/engine";
import { OutlineEffect } from "postprocessing";
import { Object3D } from "three";


export class OutlinePostEffect extends PostProcessingEffect {
    get typeName(): string {
        return "Outline";
    }

    @serializable(Object3D)
    selection!: Object3D[];

    private _outlineEffect: void | undefined | OutlineEffect;

    onCreateEffect(): EffectProviderResult | undefined {

        const outlineEffect = new OutlineEffect(this.context.scene, this.context.mainCamera!);
        this._outlineEffect = outlineEffect;
        outlineEffect.edgeStrength = 10;
        outlineEffect.visibleEdgeColor.set(0xff0000);
        for (const obj of this.selection) {
            outlineEffect.selection.add(obj);
        }

        return outlineEffect;
    }

    updateSelection() {
        if (this._outlineEffect) {
            this._outlineEffect.selection.clear();
            for (const obj of this.selection) {
                this._outlineEffect.selection.add(obj);
            }
        }
    }
}
registerCustomEffectType("Outline", OutlinePostEffect);

And then you can add it to a Volume like so:

image.png

it is using this library: Post Processing - Demo

thank you

by user 869976161550217286

hi Marcel, my structure is C:\Users\MISS3RADIM\Desktop\unity_test\My project\Needle\Svojanov

by user 869976161550217286

by user 869976161550217286

so in VS i go to Svojanov and run npm i postprocessing, to get postprocessing folder in node_modules?

by user 869976161550217286

by user 869976161550217286

yes

I am getting this errors now, cant build my scene now

by user 869976161550217286

by user 869976161550217286

should i clear packageCache? and run clean install?

by user 869976161550217286

eh its some error related to exporter

by user 869976161550217286

ok, I have reinstalled vite, and it seems to be OK now

by user 869976161550217286

I am not sure what I am missing, but probably correct profile? What is GameOject in profile asigned?

by user 869976161550217286

by user 869976161550217286

Have you assigned the object in the scene?

yes

by user 869976161550217286