Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 7 additions & 3 deletions javascript/src/URDFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,15 @@ class URDFLoader {

} else if (obj) {

if (obj instanceof THREE.Mesh) {
obj.traverse(child => {

obj.material = material;
if (child instanceof THREE.Mesh) {

}
child.material = material;

}

});

// We don't expect non identity rotations or positions. In the case of
// COLLADA files the model might come in with a custom scale for unit
Expand Down
46 changes: 45 additions & 1 deletion javascript/test/URDFLoader.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JSDOM } from 'jsdom';
import { Mesh, Color } from 'three';
import { Mesh, Group, Color } from 'three';
import fetch from 'node-fetch';
import URDFLoader from '../src/URDFLoader.js';

Expand Down Expand Up @@ -432,6 +432,50 @@ describe('Material Tags', () => {

});

it('should apply URDF material to child meshes when loadMeshCb returns a Group.', () => {

const loader = new URDFLoader();
loader.loadMeshCb = (path, manager, done) => {

const group = new Group();
group.add(new Mesh());
group.add(new Mesh());
done(group);

};

const res = loader.parse(`
<robot name="TEST">
<material name="Cyan">
<color rgba="0 1.0 1.0 1.0"/>
</material>
<link name="LINK">
<visual>
<geometry>
<mesh filename="package://meshes/link.obj" />
</geometry>
<material name="Cyan"/>
</visual>
</link>
</robot>
`);

const visual = res.children[0].children[0];
const group = visual.children[0];

group.traverse(child => {

if (child instanceof Mesh) {

expect(child.material.name).toEqual('Cyan');
expect(child.material.color).toEqual(new Color(0, 1, 1).convertSRGBToLinear());

}

});

});

it('should parse transparent materials correctly.', () => {

const loader = new URDFLoader();
Expand Down
Loading