diff --git a/mathics/builtin/box/graphics3d.py b/mathics/builtin/box/graphics3d.py index 272161c2e..e6975c1fb 100644 --- a/mathics/builtin/box/graphics3d.py +++ b/mathics/builtin/box/graphics3d.py @@ -63,40 +63,40 @@ def _prepare_elements(self, leaves, options, max_width=None): if lighting == "System`Automatic": self.lighting = [ - {"type": "Ambient", "color": [0.3, 0.2, 0.4]}, + {"type": "ambient", "color": [0.3, 0.2, 0.4]}, { - "type": "Directional", + "type": "directional", "color": [0.8, 0.0, 0.0], - "position": [2, 0, 2], + "coords": [[2, 0, 2]], }, { - "type": "Directional", + "type": "directional", "color": [0.0, 0.8, 0.0], - "position": [2, 2, 2], + "coords": [[2, 2, 2]], }, { - "type": "Directional", + "type": "directional", "color": [0.0, 0.0, 0.8], - "position": [0, 2, 2], + "coords": [[0, 2, 2]], }, ] elif lighting == "Neutral": # Lighting->"Neutral" self.lighting = [ - {"type": "Ambient", "color": [0.3, 0.3, 0.3]}, + {"type": "ambient", "color": [0.3, 0.3, 0.3]}, { - "type": "Directional", + "type": "directional", "color": [0.3, 0.3, 0.3], - "position": [2, 0, 2], + "coords": [[2, 0, 2]], }, { - "type": "Directional", + "type": "directional", "color": [0.3, 0.3, 0.3], - "position": [2, 2, 2], + "coords": [[2, 2, 2]], }, { - "type": "Directional", + "type": "directional", "color": [0.3, 0.3, 0.3], - "position": [0, 2, 2], + "coords": [[0, 2, 2]], }, ] elif lighting == "System`None": @@ -114,7 +114,7 @@ def _prepare_elements(self, leaves, options, max_width=None): color = get_class(head)(light[1]) if light[0] == '"Ambient"': self.lighting.append( - {"type": "Ambient", "color": color.to_rgba()} + {"type": "ambient", "color": color.to_rgba()} ) elif light[0] == '"Directional"': position = [0, 0, 0] @@ -129,9 +129,9 @@ def _prepare_elements(self, leaves, options, max_width=None): ] self.lighting.append( { - "type": "Directional", + "type": "directional", "color": color.to_rgba(), - "position": position, + "coords": [position], } ) elif light[0] == '"Point"': @@ -140,9 +140,9 @@ def _prepare_elements(self, leaves, options, max_width=None): position = light[2] self.lighting.append( { - "type": "Point", + "type": "point", "color": color.to_rgba(), - "position": position, + "coords": [position], } ) elif light[0] == '"Spot"': @@ -165,9 +165,9 @@ def _prepare_elements(self, leaves, options, max_width=None): angle = light[3] self.lighting.append( { - "type": "Spot", + "type": "spot", "color": color.to_rgba(), - "position": position, + "coords": [position], "target": target, "angle": angle, } @@ -295,20 +295,14 @@ def calc_dimensions(final_pass=True): # Rescale lighting for i, light in enumerate(self.lighting): if self.lighting[i]["type"] != "Ambient": - self.lighting[i]["position"] = [ - light["position"][j] * boxscale[j] for j in range(3) + self.lighting[i]["coords"][0] = [ + light["coords"][0][j] * boxscale[j] for j in range(3) ] if self.lighting[i]["type"] == "Spot": self.lighting[i]["target"] = [ light["target"][j] * boxscale[j] for j in range(3) ] - # Rescale viewpoint - self.viewpoint = [ - vp * max([xmax - xmin, ymax - ymin, zmax - zmin]) - for vp in self.viewpoint - ] - w = 0 if (xmin is None or xmax is None) else xmax - xmin h = 0 if (ymin is None or ymax is None) else ymax - ymin @@ -363,9 +357,6 @@ def boxes_to_json(self, leaves=None, **options): elements._apply_boxscaling(boxscale) - xmin, xmax, ymin, ymax, zmin, zmax, boxscale, w, h = calc_dimensions() - elements.view_width = w - # FIXME: json is the only thing we can convert MathML into. # Handle other graphics formats. format_fn = lookup_method(elements, "json") @@ -373,7 +364,7 @@ def boxes_to_json(self, leaves=None, **options): json_repr = format_fn(elements, **options) # TODO: Cubeoid (like this) - # json_repr = [{'faceColor': (1, 1, 1, 1), 'position': [(0,0,0), None], + # json_repr = [{'color': (1, 1, 1, 1), 'position': [(0,0,0), None], # 'size':[(1,1,1), None], 'type': 'cube'}] json_repr = json.dumps( @@ -384,14 +375,6 @@ def boxes_to_json(self, leaves=None, **options): "ticks": ticks, "ticks_style": js_ticks_style, }, - "extent": { - "xmin": xmin, - "xmax": xmax, - "ymin": ymin, - "ymax": ymax, - "zmin": zmin, - "zmax": zmax, - }, "lighting": self.lighting, "viewpoint": self.viewpoint, } @@ -601,7 +584,11 @@ def boxes_to_tex(self, leaves=None, **options): """.format( asy_number(width / 60), asy_number(height / 60), - self.viewpoint, + # Rescale viewpoint + [ + vp * max([xmax - xmin, ymax - ymin, zmax - zmin]) + for vp in self.viewpoint + ], asy, boundbox_asy, ) diff --git a/mathics/format/json.py b/mathics/format/json.py index c5ba4b399..27cf2afdf 100644 --- a/mathics/format/json.py +++ b/mathics/format/json.py @@ -41,7 +41,6 @@ def convert_coord_collection( "type": object_type, "coords": [coords.pos() for coords in items], "opacity": opacity, - "rgb_color": color[:3], }, } ) @@ -93,7 +92,7 @@ def cylinder_3d_box(self): [self.points], "cylinder", face_color, - {"faceColor": face_color, "radius": self.radius}, + {"color": face_color, "radius": self.radius}, ) # print("### json Cylinder3DBox", data) return data @@ -163,7 +162,7 @@ def polygon_3d_box(self) -> list: self.lines, "polygon", face_color, - {"faceColor": face_color}, + {"color": face_color}, ) # print("### json Polygon3DBox", data) return data @@ -180,7 +179,7 @@ def sphere_3d_box(self) -> list: [self.points], "sphere", face_color, - {"faceColor": face_color, "radius": self.radius}, + {"color": face_color, "radius": self.radius}, ) # print("### json Sphere3DBox", data) return data