我目前正在开始使用 pythreejs,我正在关注以下示例:https ://pythreejs.readthedocs.io/en/stable/examples/Animation.html#Skeletal-animation
但我不断收到上面提到的 ValueError 告诉我“超出范围的浮点值不符合 JSON”。这很奇怪,因为我使用的是示例中提到的完全相同的代码。互联网说当存在 NaN 值时会发生此错误,这是我能找到的唯一解释。但我没有 NaN 值,也不知道它们应该来自哪里。我也不知道为什么应该有超出范围的浮点值,因为我使用的值非常少且非常简单。
这是第一个示例中的代码:
from pythreejs import *
import ipywidgets
from IPython.display import display
# Reduce repo churn for examples with embedded state:
from pythreejs._example_helper import use_example_model_ids
use_example_model_ids()
view_width = 600
view_height = 400
sphere = Mesh(
SphereBufferGeometry(1, 32, 16),
MeshStandardMaterial(color='red')
)
cube = Mesh(
BoxBufferGeometry(1, 1, 1),
MeshPhysicalMaterial(color='green'),
position=[2, 0, 4]
)
camera = PerspectiveCamera( position=[10, 6, 10], aspect=view_width/view_height)
key_light = DirectionalLight(position=[0, 10, 10])
ambient_light = AmbientLight()
positon_track = VectorKeyframeTrack(name='.position',
times=[0, 2, 5],
values=[10, 6, 10,
6.3, 3.78, 6.3,
-2.98, 0.84, 9.2,
])
rotation_track = QuaternionKeyframeTrack(name='.quaternion',
times=[0, 2, 5],
values=[-0.184, 0.375, 0.0762, 0.905,
-0.184, 0.375, 0.0762, 0.905,
-0.0430, -0.156, -0.00681, 0.987,
])
camera_clip = AnimationClip(tracks=[positon_track, rotation_track])
camera_action = AnimationAction(AnimationMixer(camera), camera_clip, camera)
scene = Scene(children=[sphere, cube, camera, key_light, ambient_light])
controller = OrbitControls(controlling=camera)
renderer = Renderer(camera=camera, scene=scene, controls=[controller],
width=view_width, height=view_height)
renderer
返回此错误消息:
ValueError Traceback (most recent call last)
c:\Neuerdesk\python\threejs\tjs_first.py in <module>
31 scene = Scene(children=[sphere, cube, camera, key_light, ambient_light])
32
---> 33 controller = OrbitControls(controlling=camera)
34 renderer = Renderer(camera=camera, scene=scene, controls=[controller],width=view_width, height=view_height)
35
C:\Python39\lib\site-packages\pythreejs\controls\OrbitControls_autogen.py in __init__(self, controlling, **kwargs)
27 def __init__(self, controlling=None, **kwargs):
28 kwargs['controlling'] = controlling
---> 29 super(OrbitControls, self).__init__(**kwargs)
30
31 _model_name = Unicode('OrbitControlsModel').tag(sync=True)
C:\Python39\lib\site-packages\pythreejs\controls\Controls_autogen.py in __init__(self, **kwargs)
28
29 def __init__(self, **kwargs):
---> 30 super(Controls, self).__init__(**kwargs)
31
32 _model_name = Unicode('ControlsModel').tag(sync=True)
C:\Python39\lib\site-packages\pythreejs\_base\Three.py in __init__(self, **kwargs)
15
16 def __init__(self, **kwargs):
---> 17 super(ThreeWidget, self).__init__(**kwargs)
18 self.on_msg(self._on_potential_ret_val)
19
C:\Python39\lib\site-packages\pythreejs\_example_helper.py in new_init(self, *args, **kwargs)
11 def new_init(self, *args, **kwargs):
12 kwargs['model_id'] = next(id_gen)
---> 13 old_init(self, *args, **kwargs)
14 Widget.__init__ = new_init
C:\Python39\lib\site-packages\ipywidgets\widgets\widget.py in __init__(self, **kwargs)
413
414 Widget._call_widget_constructed(self)
--> 415 self.open()
416
417 def __del__(self):
C:\Python39\lib\site-packages\ipywidgets\widgets\widget.py in open(self)
436 args['comm_id'] = self._model_id
437
--> 438 self.comm = Comm(**args)
439
440 @observe('comm')
C:\Python39\lib\site-packages\ipykernel\comm\comm.py in __init__(self, target_name, data, metadata, buffers, **kwargs)
55 if self.primary:
56 # I am primary, open my peer.
---> 57 self.open(data=data, metadata=metadata, buffers=buffers)
58 else:
59 self._closed = False
C:\Python39\lib\site-packages\ipykernel\comm\comm.py in open(self, data, metadata, buffers)
89 comm_manager.register_comm(self)
90 try:
---> 91 self._publish_msg('comm_open',
92 data=data, metadata=metadata, buffers=buffers,
93 target_name=self.target_name,
C:\Python39\lib\site-packages\ipykernel\comm\comm.py in _publish_msg(self, msg_type, data, metadata, buffers, **keys)
64 metadata = {} if metadata is None else metadata
65 content = json_clean(dict(data=data, comm_id=self.comm_id, **keys))
---> 66 self.kernel.session.send(self.kernel.iopub_socket, msg_type,
67 content,
68 metadata=json_clean(metadata),
C:\Python39\lib\site-packages\jupyter_client\session.py in send(self, stream, msg_or_type, content, parent, ident, buffers, track, header, metadata)
828 if self.adapt_version:
829 msg = adapt(msg, self.adapt_version)
--> 830 to_send = self.serialize(msg, ident)
831 to_send.extend(buffers)
832 longest = max([len(s) for s in to_send])
C:\Python39\lib\site-packages\jupyter_client\session.py in serialize(self, msg, ident)
702 content = self.none
703 elif isinstance(content, dict):
--> 704 content = self.pack(content)
705 elif isinstance(content, bytes):
706 # content is already packed, as in a relayed message
C:\Python39\lib\site-packages\jupyter_client\session.py in json_packer(obj)
93
94 def json_packer(obj):
---> 95 return jsonapi.dumps(
96 obj,
97 default=json_default,
C:\Python39\lib\site-packages\zmq\utils\jsonapi.py in dumps(o, **kwargs)
23 Keyword arguments are passed along to :py:func:`json.dumps`.
24 """
---> 25 return json.dumps(o, **kwargs).encode("utf8")
26
27
C:\Python39\lib\json\__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
232 if cls is None:
233 cls = JSONEncoder
--> 234 return cls(
235 skipkeys=skipkeys, ensure_ascii=ensure_ascii,
236 check_circular=check_circular, allow_nan=allow_nan, indent=indent,
C:\Python39\lib\json\encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)
C:\Python39\lib\json\encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
ValueError: Out of range float values are not JSON compliant
有人熟悉这些问题吗?谢谢 :)