simple-3d
(en) This is the English README.
(ja) 日本語版はこちらです。
Overview
This package is a Python port of the simple_3d Dart/Flutter package. It is a working Python implementation of Simple 3D Format.
Simple 3D Format is a file format that makes it easy for non-experts to handle 3D objects.
Files output in this format have the extension .sp3d, and the internal classes are converted to JSON.
All data about one object is contained in one file.
This specification aims to minimize complexity, make it easier to read in a text editor, and make it versatile. Made for science, it can be difficult to use in other genres. For the development of science, the goal is to be able to use it without being affected by interests and conflicts.
The JSON serialization is fully compatible with the Dart version, so .sp3d files can be exchanged between Python and Dart/Flutter environments.
Installation
pip install simple-3d
Usage
Quick Start
from simple_3d import Sp3dObj, Sp3dV3D, Sp3dFragment, Sp3dFace, Sp3dMaterial, Sp3dColor
import math
sp3d_obj = Sp3dObj(
[Sp3dV3D(0, 0, 0)],
[
Sp3dFragment(
[Sp3dFace([0], 0)],
is_particle=True,
r=1.0,
)
],
[
Sp3dMaterial(
Sp3dColor.from_argb_int(255, 0, 255, 0),
True,
1.0,
Sp3dColor.from_argb_int(255, 0, 255, 0),
)
],
[],
)
Object Operations
# Move
sp3d_obj.move(Sp3dV3D(1, 0, 0))
# Rotate
sp3d_obj.rotate(Sp3dV3D(0, 1, 0), 45 * math.pi / 180)
# Vertex manipulation
# You can do many other things with the Sp3dV3D features.
sp3d_obj.vertices[0] += Sp3dV3D(1, 0, 0)
Convert to Dictionary (for JSON serialization)
import json
sp3d_obj_dict = sp3d_obj.to_dict()
json_str = json.dumps(sp3d_obj_dict)
Restore from Dictionary
restored_dict = json.loads(json_str)
restored = Sp3dObj.from_dict(restored_dict)
Color
Unlike the Dart version which uses Flutter's Color class, this package provides Sp3dColor.
Colors are stored as ARGB float values in the range [0.0, 1.0].
from simple_3d import Sp3dColor
# From integer ARGB values (0-255)
color = Sp3dColor.from_argb_int(255, 0, 255, 0) # opaque green
# From float ARGB values (0.0-1.0)
color = Sp3dColor(1.0, 0.0, 1.0, 0.0)
# Convert back to integer ARGB
a, r, g, b = color.to_argb_int()
Sp3dV3D — 3D Vector
from simple_3d import Sp3dV3D
import math
v1 = Sp3dV3D(1.0, 0.0, 0.0)
v2 = Sp3dV3D(0.0, 1.0, 0.0)
# Arithmetic
v3 = v1 + v2
v4 = v1 * 2.0
v5 = v3 / 2.0
# Length and normalization
length = v1.len()
unit = v1.nor()
# Dot and cross products
d = Sp3dV3D.dot(v1, v2)
c = Sp3dV3D.cross(v1, v2)
# Rotation (around a normalized axis)
z_axis = Sp3dV3D(0, 0, 1)
rotated = v1.rotated(z_axis, math.pi / 2) # returns new vector
v1.rotate(z_axis, math.pi / 2) # mutates in place
# Signed angle
angle = Sp3dV3D.signed_angle(v1, v2, z_axis) # radians, with sign
Format Name
Simple 3D Format
File Extension
.sp3d
MIME Type (Temporary)
model/x.sp3d
Suitable
Science (e.g., physics calculations), simple games, etc.
Not Suitable
Advanced graphics.
Structure (Decoded Object)
Sp3dObjvertices: list ofSp3dV3Dfragments: list ofSp3dFragmentfaces: list ofSp3dFacevertex_index_list: list of int — counterclockwise from upper-leftmaterial_index: int or None
is_particle: boolr: float — radius for particle typephysics:Sp3dPhysicsor None - An object with multiple variables used in physical calculations.is_touchable: bool — if False, excluded from touch calculationsname: str or Noneoption: dict or None — app-specific optional attributes (must be JSON-serializable)
materials: list ofSp3dMaterialbg:Sp3dColor— ARGB background coloris_fill: bool — if False, stroke line onlystroke_width: floatstroke_color:Sp3dColor— ARGB stroke colorimage_index: int or None — fills the face with the specified image when not Nonetexture_coordinates: list of(float, float)or None — 3 or 6 points (square = two triangles)name: str or Noneoption: dict or None
images: list ofbytes— PNG dataid: str or Nonename: str or Noneauthor: str or Nonephysics:Sp3dPhysicsor None - An object with multiple variables used in physical calculations.option: dict or Nonelayer_num: int — drawing priority in the depth directiondraw_mode:EnumSp3dDrawMode— drawing mode for renderers
Parameter Note
If you use Sp3dObj to calculate a large number of atoms, consider using the is_particle flag and r (radius).
Each atom has one vertex when calculated or saved, and you can draw a sphere only when rendering.
JSON Compatibility with Dart Version
to_dict() / from_dict() produce output compatible with Dart version 21 and later (camelCase keys).
For compatibility with older versions (≤ v20, snake_case keys), use to_dict_v14().
from_dict() automatically detects the version and calls the appropriate loader.
License
This software is released under the MIT License. See the LICENSE file for details.
Trademarks
-
“Dart” and “Flutter” are trademarks of Google LLC.
This package is not developed or endorsed by Google LLC. -
“Python” is a trademark of the Python Software Foundation.
This package is not affiliated with the Python Software Foundation. -
GitHub and the GitHub logo are trademarks of GitHub, Inc.
This package is not affiliated with GitHub, Inc.
Metadata
Release files for simple-3d 17.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simple_3d-17.3.1.tar.gz | 27.2 kB | Without provenance | Details for simple_3d-17.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simple_3d-17.3.1-py3-none-any.whl | Python 3 | none | any | Details for simple_3d-17.3.1-py3-none-any.whl |
Total release size: 54.4 kB
Release files / simple_3d-17.3.1.tar.gz
| Download URL | simple_3d-17.3.1.tar.gz |
|---|---|
| Size | 27.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
803f4263fa51c73dc65256c6c202526f3254a29d921028c4abe0b58834187916
|
|
BLAKE2b-256 checksum How to use checksums |
56d682e1b1e8a49d7aa3c303136818df8156d9d1befc43f7e742d6c13a71d7da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / simple_3d-17.3.1-py3-none-any.whl
| Download URL | simple_3d-17.3.1-py3-none-any.whl |
|---|---|
| Size | 27.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4270964b40d01d430876888fc82f3a2d4dcf8fb68ef495341758c8b48c32481b
|
|
BLAKE2b-256 checksum How to use checksums |
010ee17386bac9032318ec9febb1acf77bd97e3e89db9d1fe157e15711828603
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for simple-3d 17.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.