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

feat: add metallic material rendering to URDF robot #33

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/components/robot/robotRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,24 @@ const RobotRenderer: React.FC = () => {

const loader = new URDFLoader();
loader.load(URDF_URL, (robot: THREE.Object3D) => {
const updateMaterials = () => {
robot.traverse((child) => {
if (child instanceof THREE.Mesh) {
const originalColor =
child.material instanceof THREE.Material
? (child.material as THREE.MeshPhysicalMaterial).color
: new THREE.Color(0x808080);
child.material = new THREE.MeshPhysicalMaterial({
metalness: 0.4,
roughness: 0.5,
color: originalColor,
});
}
});
};

scene.add(robot);
updateMaterials();

// Correcting for the robot initial size and position.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need to delete this comment

robot.rotateY(Math.PI / 2);
Expand Down Expand Up @@ -109,12 +126,16 @@ const RobotRenderer: React.FC = () => {
animate();
});

const light = new THREE.AmbientLight(0x404040);
scene.add(light);
const ambientLight = new THREE.AmbientLight(0xffffff, 0.3);
scene.add(ambientLight);

const mainLight = new THREE.DirectionalLight(0xffffff, 2.0);
mainLight.position.set(5, 5, 5);
scene.add(mainLight);

const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
directionalLight.position.set(1, 1, 1).normalize();
scene.add(directionalLight);
const fillLight = new THREE.DirectionalLight(0xffffff, 0.8);
fillLight.position.set(-5, 2, -5);
scene.add(fillLight);
Comment on lines -112 to +138
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems unrelated to the pr but is a good change. can we make this into a separare pr, with a screenshot of how it looks?


camera.position.z = 5;

Expand Down
Loading