mirror of
https://github.com/3b1b/manim.git
synced 2025-08-01 17:29:06 +08:00
Feature: SVGMobject("unpack_groups" = False) preserve the hierarchy of
groups in the file.
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from vectorized_mobject import VMobject
|
from vectorized_mobject import VMobject, VGroup
|
||||||
from topics.geometry import Rectangle, Circle
|
from topics.geometry import Rectangle, Circle
|
||||||
from helpers import *
|
from helpers import *
|
||||||
|
|
||||||
@ -21,6 +21,7 @@ class SVGMobject(VMobject):
|
|||||||
"width" : None,
|
"width" : None,
|
||||||
#Must be filled in in a subclass, or when called
|
#Must be filled in in a subclass, or when called
|
||||||
"file_name" : None,
|
"file_name" : None,
|
||||||
|
"unpack_groups" : True, # if False, creates a hierarchy of VGroups
|
||||||
"stroke_width" : 0,
|
"stroke_width" : 0,
|
||||||
"fill_opacity" : 1,
|
"fill_opacity" : 1,
|
||||||
# "fill_color" : LIGHT_GREY,
|
# "fill_color" : LIGHT_GREY,
|
||||||
@ -50,7 +51,9 @@ class SVGMobject(VMobject):
|
|||||||
doc = minidom.parse(self.file_path)
|
doc = minidom.parse(self.file_path)
|
||||||
self.ref_to_element = {}
|
self.ref_to_element = {}
|
||||||
for svg in doc.getElementsByTagName("svg"):
|
for svg in doc.getElementsByTagName("svg"):
|
||||||
self.add(*self.get_mobjects_from(svg))
|
mobjects = self.get_mobjects_from(svg)
|
||||||
|
if self.unpack_groups: self.add(*mobjects)
|
||||||
|
else: self.add(*mobjects[0].submobjects)
|
||||||
doc.unlink()
|
doc.unlink()
|
||||||
|
|
||||||
def get_mobjects_from(self, element):
|
def get_mobjects_from(self, element):
|
||||||
@ -85,6 +88,9 @@ class SVGMobject(VMobject):
|
|||||||
# warnings.warn("Unknown element type: " + element.tagName)
|
# warnings.warn("Unknown element type: " + element.tagName)
|
||||||
result = filter(lambda m : m is not None, result)
|
result = filter(lambda m : m is not None, result)
|
||||||
self.handle_transforms(element, VMobject(*result))
|
self.handle_transforms(element, VMobject(*result))
|
||||||
|
if len(result) > 1 and not self.unpack_groups:
|
||||||
|
result = [VGroup(*result)]
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def g_to_mobjects(self, g_element):
|
def g_to_mobjects(self, g_element):
|
||||||
|
Reference in New Issue
Block a user