1

I am a newbie and I am trying to use the OutlineEffect from threejs in my application, using react three fiber. I need the outline of the meshes such as in this example https://threejs.org/examples/#webgl_loader_mmd . I am not sure how to add the effect in react three fiber syntax.

I tried the code below and there is no error but also the effect is not showing. Can anyone help me, please? Thank you in advance!

import { useGLTF } from "@react-three/drei"
import React, { useRef } from "react";
import { OutlineEffect } from "three/examples/jsm/effects/OutlineEffect.js"
import { extend, useThree } from "@react-three/fiber";

extend({ OutlineEffect })

export default function Model(props) {

    const { gl, camera, scene } = useThree() //finds the renderer
    const model = useGLTF('./Test_Online3DViewerVisible.glb')

    const torus = useRef()

    const effect = new OutlineEffect(gl)

    effect.render(scene, camera)

    return <>
        <mesh ref={torus}>
            <torusGeometry />
            <meshStandardMaterial />
        </mesh>
    </>

}

useGLTF.preload('./Test_Online3DViewerVisible.glb')

1 Answer 1

0

You can use postprocessing for it. I attached the code.

 import * as THREE from 'three';
    import { EffectComposer, OutlineEffect, RenderPass } from 'postprocessing';
    import { Canvas, extend, useThree } from 'react-three-fiber';
    
    extend({ OutlineEffect });
    
    const Effects = () => {
      const { gl, scene, camera, size } = useThree();
    
      const composer = React.useRef();
      React.useEffect(() => void composer.current.setSize(size.width, size.height), [size]);
      return (
        <effectComposer ref={composer} args={[gl]}>
          <renderPass attachArray="passes" args={[scene, camera]} />
          <outlineEffect attachArray="passes" args={[new THREE.Vector2(size.width, size.height), scene, camera]} />
        </effectComposer>
      );
    };
Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.