How to use the meshcat.geometry.MeshBasicMaterial function in meshcat

To help you get started, we’ve selected a few meshcat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github danieljfarrell / pvtrace / pvtrace / scene / renderer.py View on Github external
def add_geometry(self, geometry, pathname, transform):
        vis = self.vis
        material = g.MeshBasicMaterial(
            reflectivity=self.reflectivity, sides=0, wireframe=self.wireframe
        )
        material.transparency = self.transparency
        material.opacity = self.opacity

        if isinstance(geometry, Sphere):
            sphere = geometry
            vis[pathname].set_object(g.Sphere(sphere.radius), material)
            vis[pathname].set_transform(transform)

        elif isinstance(geometry, Cylinder):
            cyl = geometry
            vis[pathname].set_object(g.Cylinder(cyl.length, cyl.radius), material)
            # meshcat cylinder is aligned along y-axis. Align along z then apply the
            # node's transform as normal.
            transform = np.copy(transform)
github danieljfarrell / pvtrace / pvtrace / scene / renderer.py View on Github external
Returns
            -------
            identifier : str
                The string identifier used to add the line to the scene.
        """
        vis = self.vis
        line = (start, end)
        self._will_add_expendable_to_scene(line)
        vertices = np.column_stack(line)
        assert vertices.shape[0] == 3  # easy to get this wrong
        identifier = self.get_next_identifer()
        vis[identifier].set_object(
            g.Line(
                g.PointsGeometry(vertices),
                g.MeshBasicMaterial(color=colour, transparency=False, opacity=1),
            )
        )
        self._did_add_expendable_to_scene(identifier)
        return identifier
github danieljfarrell / pvtrace / pvtrace / scene / renderer.py View on Github external
if world_segment == "short":
                if end_ray == history[-1][0]:
                    end = (
                        np.array(start_ray.position)
                        + np.array(start_ray.direction) * short_length
                    )
            colour = wavelength_to_hex_int(nanometers)
            ids.append(self.add_line_segment(start, end, colour=colour))

            if baubles:
                event = start_part[1]
                if event in {Event.TRANSMIT}:
                    baubid = self.get_next_identifer()
                    vis[f"exit/{baubid}"].set_object(
                        g.Sphere(bauble_radius),
                        g.MeshBasicMaterial(
                            color=colour, transparency=False, opacity=1
                        ),
                    )
                    vis[f"exit/{baubid}"].set_transform(tf.translation_matrix(start))

                    ids.append(baubid)
        return ids
github danieljfarrell / pvtrace / pvtrace / scene / renderer.py View on Github external
method when each line segment needs to be drawn with a different colour.
        
            Returns
            -------
            identifier : str
                The string identifier used to add the line to the scene.
        """
        vis = self.vis
        self._will_add_expendable_to_scene(vertices)
        vertices = np.array(vertices)
        assert vertices.shape[0] == 3  # easy to get this wrong
        identifier = self.get_next_identifer()
        vis[identifier].set_object(
            g.Line(
                g.PointsGeometry(vertices),
                g.MeshBasicMaterial(color=colour, transparency=False, opacity=1.0),
            )
        )
        self._did_add_expendable_to_scene(identifier)
        return identifier