Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set amount of segments for shapes within compoundBody #443

Open
DaveSeidman opened this issue Nov 15, 2023 · 0 comments
Open

Can't set amount of segments for shapes within compoundBody #443

DaveSeidman opened this issue Nov 15, 2023 · 0 comments

Comments

@DaveSeidman
Copy link

Thanks in advance for this module, it's very performant and fairly straightforward to implement!

I am using this library to calculate physics for toruses (rings) which I'm achieving by creating a ring of spheres and passing the shapes array to a CompoundBody. This is working as expected, however I'd like to the ability to turn down the amount of segments on each sphere. I've tried using the second two args which I'd assume behave the same as they would if one was implementing the sphereBody outside of a compoundBody. However, when I enable the Debug view (which I assume is displaying the real geometries cannon is using to calculate collisions) I don't see any change in the amount of segments. I've also tried putting negative numbers and even strings in place and the library doesn't even throw an error so I'm guessing anything other than the first parameter (radius) is ignored.

Here is my relevant code which is a component within a ReactJS app:

import React, { useRef } from 'react';
import { useCompoundBody } from '@react-three/cannon';
import { MeshTransmissionMaterial } from '@react-three/drei';

function Ring(props) {
  const { position } = props;
  const shapes = [];
  const radius = 1;
  const segments = 8;
  for (let i = 0; i < 1; i += (1 / segments)) {
    const angle = i * 2 * Math.PI;
    shapes.push({
      args: [0.4, 1, 1], // <- second two properties are ignored
      position: [radius * Math.cos(angle), radius * Math.sin(angle), 0],
      type: 'Sphere',
    });
  }
  const [ref, api] = useCompoundBody(
    () => ({
      mass: 1,
      position,
      shapes,
    }),
    useRef(),
  );

  return (
    <group>
      <mesh ref={ref}>
        <torusGeometry />
        <MeshTransmissionMaterial
          transmission={0.9}
          roughness={0.1}
          thickness={0.5}
          ior={1.5}
          reflectivity={0.1}
          color={0xee6688}
          backsideThickness={0.1}
        />
      </mesh>
    </group>
  );
}

export default Ring;
@DaveSeidman DaveSeidman changed the title Add ability to controls amount of segments for shapes within compoundBody Can't set amount of segments for shapes within compoundBody Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant