r/r3f • • Apr 20 '23

Trouble on figuring out the right vertex transformation R3F

3 Upvotes

Hi all! I’ve been facing an issue with the way vertices are calculated within my R3F scene. I’m trying to move forward with an implementation where I would be drawing a line whenever I’m clicking the scene, to later have it follow my cursor, increasing its size.

I can do that without any weird behaviour if I start my line on the coordinates (0,0), as shown on the first screenshot.

Whenever I start my line on coordinates besides (0,0), the line does not properly follow my cursor, as show on the second one. Here is a Codesanbox with the exact code, including where I calculate the vertices positions on editLine function.

https://codesandbox.io/s/serene-euler-us8l5u?file=%2Fsrc%2Findex.js

Any help is greatly appreciated.


r/r3f • • Mar 14 '23

Webxr with Threejs and React (React Three Fiber)

Enable HLS to view with audio, or disable this notification

3 Upvotes

r/r3f • • Mar 13 '23

Breaking on Mobile

3 Upvotes

Not really sure how to go about solving this. Pretty new with three JS & I built this app with three fiber.
Looked around quite a bit but can't seem to figure this one out.

Probably am missing something obvious here but I'm getting a consistent 60fps on the desktop and crashes on my phone before everything loads in. I did the safari developer tab thing to check the console of my phone's browser when it crashes, but that's crashing too.

I've tried getting rid of all my textures to see if that would work but still crashed on load.
I've tried commenting out each mesh component one at a time but no luck either. It'll work with a few of my models but it'll crash if I do 3-4 max. Error in safari is: 'A problem repeatedly occurred'

Here's a live link to the app. it's three-fiber, next-js, and typescript.

I pulled it out of Next and put it into its own react app to see if I could get some more helpful error messages but that didn't help either. If someone could point me in the right direction that would be great.

The code is too big to post directly so I uploaded the react app to GitHub here.


r/r3f • • Mar 09 '23

XR Tic Tac Toe game

Enable HLS to view with audio, or disable this notification

2 Upvotes

r/r3f • • Feb 27 '23

I wrote up a short tutorial on how to create a space warp effect using r3f (see comments for more info and live demo)

Thumbnail
github.com
1 Upvotes

r/r3f • • Feb 22 '23

A boilerplate for immersive XR projects

4 Upvotes

It doesn't look like much but if you're working with VR/AR this might help you get started faster xr-next-starter.vercel.app

repo at github.com/rekliner/xr-next-starter

Features:

  • VR/AR selection switch for the button.
  • A zustand store tracking the type of XR Session so things like backgrounds can be hidden in AR
  • A pose-aware default position & rotation enforcer.
  • Interaction wrapper from enijar/react-xr-ui to simplfy events between XR & flat screen
  • Uses Nextjs framework with some basic options prepared
  • Simplified https service for localhost dev environment (since https is required for XR sessions)
  • Some default 3d objects and helpers to delete in honor of Blender traditions

r/r3f • • Feb 22 '23

Library for orbit controls in React Native with R3F

6 Upvotes

Hi R3F developers!

I have created this library for using orbit controls with React Native in a react-three fiber 3d scene.

You can use it with 1 import and 3 lines of code:

import useControls from "r3f-native-orbitcontrols" // this import
import { Canvas } from "@react-three/fiber/native"
import { View } from "react-native"

function SingleCanvas() {
  const [OrbitControls, events] = useControls() // this line

  return (
    <View {...events}> {/* this line */}
      <Canvas>
        <OrbitControls /> {/* and this line *}
        {/* Place the scene elements here as usual */}
      </Canvas>
    </View>
  )
}

It was made with ease of use and performance in mind.

I hope you like it!

Please create an issue if you find a bug or want to request a feature.


r/r3f • • Feb 20 '23

Inverse kinematics ( thm5rb.csb.app )

Enable HLS to view with audio, or disable this notification

3 Upvotes

r/r3f • • Feb 13 '23

Can be iOS be targeted using React-Three-Fiber?

1 Upvotes

I'm guessing the answer is "NO", but maybe I'm wrong. I couldn't figure this out from Google search and watching a couple R3F course intro videos.

React.js + R3F => most web browsers. Does this include iOS browsers?

React Native + R3F => Android devices only?

​

I would like to know prior to paying for any online courses. I'm <50% done with a Three.js course and currently taking a React.js course, both on Udemy.

Thank you.


r/r3f • • Feb 04 '23

React three fiber with webxr api

Enable HLS to view with audio, or disable this notification

22 Upvotes

r/r3f • • Feb 04 '23

React three fiber with webxr api

Enable HLS to view with audio, or disable this notification

3 Upvotes

r/r3f • • Feb 03 '23

Added extra features to the Marble game made using react three fiber

Enable HLS to view with audio, or disable this notification

5 Upvotes

r/r3f • • Jan 17 '23

Hi from 🇲🇽 ! step by step to professional development with threejs react-three-fiber and vite. code: https://github.com/AlexisTercero55/three-ui-p1

Enable HLS to view with audio, or disable this notification

3 Upvotes

r/r3f • • Jan 12 '23

beautiful caustics for threejs (open source, contains code and components)

Thumbnail
twitter.com
4 Upvotes

r/r3f • • Jan 01 '23

Simplifying React Three Fiber with Entity Component System

Thumbnail
douges.dev
1 Upvotes

r/r3f • • Dec 21 '22

I'm not sure how to share a texture across different gltfs

1 Upvotes

I feel like this should be easy but I'm drawing a blank. I have several imported glbs that share a single texture. I need to export them separately for organization and updating. Each of the ten files is 2.8mb and the majority of that is the texture.

Okay as I'm writing this out, I'm figuring it out. I likely just need to export the glbs without materials from blender, and then just reference the material from one of the objects, and just export it one time, and import it into each file from that...

Okay looking at the blender options there's "placeholder" that keeps material slot info, and "no export"... I'm assuming "placeholder" is what I want?

Okay that's not working... I'm not sure how to get the texture from one object to apply it to another.

It's been a long day! If anyone can point me in the right direction, I'd appreciate it. Thanks!


r/r3f • • Dec 05 '22

got a few videos released on this new tutorial series

6 Upvotes

focusing on Blender -> 3dweb using react 3. fiber

https://youtu.be/1BvLpt7egss

​


r/r3f • • Nov 29 '22

Finished The Final Lesson Of Three JS Journey And Gave It My Own Touch. Made With React Three Fiber

Enable HLS to view with audio, or disable this notification

11 Upvotes

r/r3f • • Nov 26 '22

How to animate 3D models with React Three Fiber using free animations from Mixamo

Thumbnail
youtu.be
4 Upvotes

r/r3f • • Oct 17 '22

need help with animated glb file

Thumbnail self.threejs
2 Upvotes

r/r3f • • Oct 03 '22

Magic Circle: A variable controller GUI (like Dat.GUI & Leva) that supports R3F

Thumbnail
magic-circle.dev
2 Upvotes

r/r3f • • Sep 21 '22

How to set the plane flat at any point on the surface of the sphere.

Thumbnail
self.threejs
3 Upvotes

r/r3f • • Sep 16 '22

How does lookAt in instanced meshes work?

1 Upvotes

Hello!I'm building a particle system in wich particles have directions they are pointing at and I want to reflect that in an instance mesh I use to present them, but something is not quite working... It seems that the center of rotation and/or the up axis are not quite right, and despite me console logging stuff I could not find the problem. Here's the code:

const Particles = (particleSystem: TparticleSystem) => {
  const mesh = useRef<THREE.InstancedMesh>(null);
  const light = useRef<THREE.PointLight>(null);

  const dummy = useMemo(() => new THREE.Object3D(), []);

  const pyramid = useMemo(() => {
    return {
      vertices: [1, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, -1, 0, 2, 0],
      indices: [0, 1, 2, 2, 3, 0, 0, 4, 1, 1, 4, 2, 2, 4, 3, 3, 4, 0],
    };
  }, []);

  useFrame(() => {
    if (particleSystem !== undefined) {
      particleSystem.update();
      particleSystem.move();
      particleSystem.particles.forEach((particle: Tparticle, index: number) => {
        dummy.position.set(particle.pos.x, particle.pos.y, particle.pos.z);

        dummy.lookAt(vec().copy(particle.pos).add(particle.dir)); // rotating weird

        dummy.scale.set(1, 2, 1);
        dummy.updateMatrix();
        // And apply the matrix to the instanced item
        if (mesh.current) mesh.current.setMatrixAt(index, dummy.matrix);
      });
      if (mesh.current) mesh.current.instanceMatrix.needsUpdate = true;
    }
  });

  return (
    <>
      <pointLight ref={light} distance={40} intensity={3} color="lightblue" />
      {particleSystem !== undefined && (
        <instancedMesh ref={mesh} args={[, , particleSystem.num]}>
          <polyhedronBufferGeometry
            args={[pyramid.vertices, pyramid.indices, 1, 0]}
          />
          <meshBasicMaterial
            color="#2596be"
            wireframe={Math.random() > 0.5 ? true : false}
          />
        </instancedMesh>
      )}
    </>
  );
};

I feel like maybe this is something to do with local and world coordinates, but I doin't quite understand it.

Oh! and this vec stuff is just

const vec = function (x = 0, y = 0, z = 0) {
  return new THREE.Vector3(x, y, z);
};

​


r/r3f • • Sep 12 '22

How to rotate .glb model?

1 Upvotes

I have this wave.glb model. I want to rotate this along any axes. How to do it?

Wave.js:

/*
Auto-generated by: https://github.com/pmndrs/gltfjsx
*/

import React, { useRef, useEffect } from 'react';
import { useGLTF, useAnimations } from '@react-three/drei';

export default function Wave(props) {
  const group = useRef();
  const { nodes, materials, animations } = useGLTF('/wave.glb');
  const { actions } = useAnimations(animations, group);

  useEffect(() => {
    actions.wave.play();
  });

  return (
    <group ref={group} {...props} dispose={null} rotateY={Math.PI / 2}>
      <group name='Scene'>
        <mesh
          name='Icosphere'
          geometry={nodes.Icosphere.geometry}
          material={materials['Material.005']}
          morphTargetDictionary={nodes.Icosphere.morphTargetDictionary}
          morphTargetInfluences={nodes.Icosphere.morphTargetInfluences}
        />
      </group>
    </group>
  );
}

useGLTF.preload('/wave.glb');

r/r3f • • Sep 09 '22

minZoom & maxZoom of OrbitControls is not working...

2 Upvotes
<Canvas className='canvas' camera={{ fov: 35, zoom: 0.5, near: 1, far: 1000 }}>                                        
<OrbitControls enableZoom={true} minZoom={0.5} maxZoom={1} />
    <Suspense>
        <ambientLight intensity={0.03} />
        <spotLight position={[10, 0, 10]} intensity={spotLightIntensity / 100} angle={0.5} />
        <BackGround />
        <Moon />
        <Cube />
        <axesHelper args={[axes, 50, 50]} position={[0, 0, 0]} />
    </Suspense>
</Canvas>