This commit is contained in:
cjw
2026-02-12 23:22:11 +08:00
parent 7b09eb3d89
commit 89660bba4e
5988 changed files with 2517516 additions and 0 deletions
@@ -0,0 +1,119 @@
import gzip
import json
import os
from io import BytesIO
from ..typed import Dict
# find the current absolute path to this directory
_pwd = os.path.expanduser(os.path.abspath(os.path.dirname(__file__)))
# once resources are loaded cache them
_cache = {}
def get_schema(name: str) -> Dict:
"""
Load a schema and evaluate the referenced files.
Parameters
------------
name : str
Filename of schema.
Returns
----------
schema
Loaded and resolved schema.
"""
from ..resolvers import FilePathResolver
from ..schemas import resolve
# get a resolver for our base path
resolver = FilePathResolver(os.path.join(_pwd, "schema", name))
# recursively load `$ref` keys
return resolve(json.loads(resolver.get(name).decode("utf-8")), resolver=resolver)
def get_json(name: str) -> Dict:
"""
Get a resource from the `trimesh/resources` folder as a decoded string.
Parameters
-------------
name : str
File path relative to `trimesh/resources/{name}`
Returns
-------------
resource
File data decoded from JSON.
"""
raw = get_bytes(name)
if name.endswith(".gzip"):
raw = gzip.decompress(raw)
else:
raw = raw.decode("utf-8")
return json.loads(raw)
def get_string(name: str) -> str:
"""
Get a resource from the `trimesh/resources` folder as a decoded string.
Parameters
-------------
name
File path relative to `trimesh/resources`
Returns
-------------
resource
File data as a string.
"""
return get_bytes(name).decode("utf-8")
def get_bytes(name: str) -> bytes:
"""
Get a resource from the `trimesh/resources` folder as binary data.
Parameters
-------------
name
File path relative to `trimesh/resources`
Returns
-------------
resource
File data as raw bytes.
"""
cached = _cache.get(name, None)
if cached is not None:
return cached
# get the resource using relative names
# all templates are using POSIX relative paths
# so fix them to be platform-specific
with open(os.path.join(_pwd, *name.split("/")), "rb") as f:
resource = f.read()
_cache[name] = resource
return resource
def get_stream(name: str) -> BytesIO:
"""
Get a resource from the `trimesh/resources` folder as a binary stream.
Parameters
-------------
name : str
File path relative to `trimesh/resources`
Returns
-------------
resource
File data as a binary stream.
"""
return BytesIO(get_bytes(name))
@@ -0,0 +1 @@
{"box":{"vertices":[[0.0,0.0,0.0],[0.0,0.0,1.0],[0.0,1.0,0.0],[0.0,1.0,1.0],[1.0,0.0,0.0],[1.0,0.0,1.0],[1.0,1.0,0.0],[1.0,1.0,1.0]],"faces":[[1,3,0],[4,1,0],[0,3,2],[2,4,0],[1,7,3],[5,1,4],[5,7,1],[3,7,2],[6,4,2],[2,7,6],[6,5,4],[7,5,6]],"face_normals":[[-1,0,0],[0,-1,0],[-1,0,0],[0,0,-1],[0,0,1],[0,-1,0],[0,0,1],[0,1,0],[0,0,-1],[0,1,0],[1,0,0],[1,0,0]]},"icosahedron":{"vertices":[[-0.5257311121191336,0.85065080835204,0.0],[0.5257311121191336,0.85065080835204,0.0],[-0.5257311121191336,-0.85065080835204,0.0],[0.5257311121191336,-0.85065080835204,0.0],[0.0,-0.5257311121191336,0.85065080835204],[0.0,0.5257311121191336,0.85065080835204],[0.0,-0.5257311121191336,-0.85065080835204],[0.0,0.5257311121191336,-0.85065080835204],[0.85065080835204,0.0,-0.5257311121191336],[0.85065080835204,0.0,0.5257311121191336],[-0.85065080835204,0.0,-0.5257311121191336],[-0.85065080835204,0.0,0.5257311121191336]],"faces":[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]]}}
@@ -0,0 +1,5 @@
# trimesh/resources/schemas
Contain schemas for formats when available. They are currently mostly [JSON schema](https://json-schema.org/) although if formats have an XSD, DTD, or other schema format we are happy to include it here.
The `primitive` schema directory is a [JSON schema](https://json-schema.org/) for `trimesh` exports. The goal is if we implement a `to_dict` method to have a well-defined schema we can validate in unit tests.
@@ -0,0 +1,29 @@
{
"$id": "https://github.com/mikedh/trimesh/blob/main/trimesh/resources/schema/primitive/box.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"description": "A 3D box primitive.",
"properties": {
"extents": {
"description": "The length of each side of the 3D box. The center of mass will be at the origin, and the minimum values will be at (-extents / 2) and the maximum values will be at (extents / 2).",
"items": {
"maxItems": 3,
"minItems": 3,
"type": "number"
},
"type": "array"
},
"kind": {
"pattern": "(^box$)",
"type": "string"
},
"transform": {
"$ref": "transform.schema.json"
}
},
"required": [
"extents",
"kind"
],
"type": "object"
}
@@ -0,0 +1,29 @@
{
"$id": "https://github.com/mikedh/trimesh/blob/main/trimesh/resources/schema/primitive/capsule.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"description": "A 3D capsule primitive: a cylinder capped by tangent hemispheres.",
"properties": {
"height": {
"description": "The total height of the capsule including caps.",
"type": "number"
},
"kind": {
"pattern": "(^capsule$)",
"type": "string"
},
"radius": {
"description": "The radius of the cylinder and hemispherical caps.",
"type": "number"
},
"transform": {
"$ref": "transform.schema.json"
}
},
"required": [
"radius",
"height",
"kind"
],
"type": "object"
}
@@ -0,0 +1,29 @@
{
"$id": "https://github.com/mikedh/trimesh/blob/main/trimesh/resources/schema/primitive/cylinder.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"description": "A 3D cylinder primitive.",
"properties": {
"height": {
"description": "The height of the cylinder along Z. The maximum Z value will be at (height / 2) and the minimum will be at (-height / 2)",
"type": "number"
},
"kind": {
"pattern": "(^cylinder$)",
"type": "string"
},
"radius": {
"description": "The radius of the cylinder.",
"type": "number"
},
"transform": {
"$ref": "transform.schema.json"
}
},
"required": [
"radius",
"height",
"kind"
],
"type": "object"
}
@@ -0,0 +1,27 @@
{
"$id": "https://github.com/mikedh/trimesh/blob/main/trimesh/resources/schema/primitive/extrusion.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"description": "A 2D polygon extruded from Z=0 along positive Z by `height` then transformed by the `transform` matrix.",
"properties": {
"height": {
"type": "number"
},
"kind": {
"pattern": "(^extrusion$)",
"type": "string"
},
"polygon": {
"$ref": "wkt.polygon.schema.json"
},
"transform": {
"$ref": "transform.schema.json"
}
},
"required": [
"kind",
"polygon",
"height"
],
"type": "object"
}
@@ -0,0 +1,22 @@
{
"$id": "https://github.com/mikedh/trimesh/blob/main/trimesh/resources/schema/primitive/primitive.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"anyOf": [
{
"$ref": "box.schema.json"
},
{
"$ref": "sphere.schema.json"
},
{
"$ref": "capsule.schema.json"
},
{
"$ref": "cylinder.schema.json"
},
{
"$ref": "extrusion.schema.json"
}
],
"description": "A geometric primitive."
}
@@ -0,0 +1,25 @@
{
"$id": "https://github.com/mikedh/trimesh/blob/main/trimesh/resources/schema/primitive/scenegraph.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "A scene graph in the simplest possible JSON format.",
"type": "array",
"items": {
"type": "array",
"prefixItems": [
{ "type": "string", "description": "Node name of frame from." },
{ "type": "string", "description": "Node name of frame to." },
{
"type": "object",
"additionalProperties": false,
"properties": {
"geometry": {
"type": "string",
"description": "Name of the geometry transformed to this frame."
},
"matrix": { "$ref": "transform.schema.json" }
}
}
]
}
}
@@ -0,0 +1,23 @@
{
"$id": "https://github.com/mikedh/trimesh/blob/main/trimesh/resources/schema/primitive/sphere.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"description": "A 3D sphere primitive.",
"properties": {
"kind": {
"pattern": "(^sphere$)",
"type": "string"
},
"radius": {
"type": "number"
},
"transform": {
"$ref": "transform.schema.json"
}
},
"required": [
"radius",
"kind"
],
"type": "object"
}
@@ -0,0 +1,16 @@
{
"$id": "https://github.com/mikedh/trimesh/blob/main/trimesh/resources/schema/primitive/transform.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "A homogeneous transformation matrix. If not passed it is assumed to be an identity matrix ",
"items": {
"items": {
"maxItems": 4,
"minItems": 4,
"type": "number"
},
"maxItems": 4,
"minItems": 4,
"type": "array"
},
"type": "array"
}
@@ -0,0 +1,39 @@
{
"$id": "https://github.com/mikedh/trimesh/blob/main/trimesh/resources/schema/primitive/trimesh.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"description": "A 3D triangular mesh in the simplest possible JSON format.",
"properties": {
"faces": {
"items": {
"items": {
"maxItems": 3,
"minItems": 3,
"type": "integer"
},
"type": "array"
},
"type": "array"
},
"kind": {
"pattern": "(^trimesh$)",
"type": "string"
},
"vertices": {
"items": {
"items": {
"maxItems": 3,
"minItems": 3,
"type": "number"
},
"type": "array"
},
"type": "array"
}
},
"required": [
"vertices",
"faces"
],
"type": "object"
}
@@ -0,0 +1,7 @@
{
"$id": "https://github.com/mikedh/trimesh/blob/main/trimesh/resources/schema/primitive/wkt.polygon.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "A single polygon in the Well Known Text format (WKT).",
"pattern": " *POLYGON *\\( *\\( *([+-]?([0-9]*[.])?[0-9]+ *[+-]?([0-9]*[.])?[0-9]+ *,* *)*\\) *\\) *",
"type": "string"
}
@@ -0,0 +1,324 @@
<?xml version="1.0" ?>
<!--
XML Schema for URDF v1.0
This is a proposal XML Schema to validate the original URDF file
format. It supports PR2 extensions (transmission) but not the
Gazebo ones.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.ros.org"
xmlns="http://www.ros.org"
elementFormDefault="qualified">
<!-- pose node type -->
<xs:complexType name="pose">
<xs:attribute name="xyz" type="xs:string" default="0 0 0" />
<xs:attribute name="rpy" type="xs:string" default="0 0 0" />
</xs:complexType>
<!-- pose node type -->
<xs:complexType name="color">
<xs:attribute name="rgba" type="xs:string" default="0 0 0 0" />
</xs:complexType>
<!-- verbose node type -->
<xs:complexType name="verbose">
<xs:attribute name="value" type="xs:string" />
</xs:complexType>
<!-- name only node type -->
<xs:complexType name="name">
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
<!-- mass node type -->
<xs:complexType name="mass">
<!-- FIXME: is value optional? -->
<xs:attribute name="value" type="xs:double" default="0" />
</xs:complexType>
<!-- inertia node type -->
<xs:complexType name="inertia">
<!-- FIXME: is it optional? default value? -->
<xs:attribute name="ixx" type="xs:double" default="0" />
<xs:attribute name="ixy" type="xs:double" default="0" />
<xs:attribute name="ixz" type="xs:double" default="0" />
<xs:attribute name="iyy" type="xs:double" default="0" />
<xs:attribute name="iyz" type="xs:double" default="0" />
<xs:attribute name="izz" type="xs:double" default="0" />
</xs:complexType>
<!-- inertial node type -->
<xs:complexType name="inertial">
<xs:all>
<xs:element name="origin"
type="pose" minOccurs="0" maxOccurs="1" />
<xs:element name="mass"
type="mass" minOccurs="0" maxOccurs="1" />
<xs:element name="inertia"
type="inertia" minOccurs="0" maxOccurs="1" />
</xs:all>
</xs:complexType>
<!-- box node type -->
<xs:complexType name="box">
<xs:attribute name="size" type="xs:string" default="0 0 0" />
</xs:complexType>
<!-- cylinder node type -->
<xs:complexType name="cylinder">
<xs:attribute name="radius" type="xs:double" use="required" />
<xs:attribute name="length" type="xs:double" use="required" />
</xs:complexType>
<!-- sphere node type -->
<xs:complexType name="sphere">
<xs:attribute name="radius" type="xs:double" use="required" />
</xs:complexType>
<!-- mesh node type -->
<xs:complexType name="mesh">
<xs:attribute name="filename" type="xs:anyURI" use="required" />
<xs:attribute name="scale" type="xs:string" default="1 1 1" />
</xs:complexType>
<!-- geometry node type -->
<xs:complexType name="geometry">
<xs:choice>
<xs:element name="box" type="box" />
<xs:element name="cylinder" type="cylinder" />
<xs:element name="sphere" type="sphere" />
<xs:element name="mesh" type="mesh" />
</xs:choice>
</xs:complexType>
<!-- texture node type -->
<xs:complexType name="texture">
<xs:attribute name="filename" type="xs:anyURI" />
</xs:complexType>
<!-- material node type -->
<xs:complexType name="material">
<xs:sequence>
<xs:element name="color" type="color" minOccurs="0" maxOccurs="1" />
<xs:element name="texture" type="texture" minOccurs="0" maxOccurs="1" />
</xs:sequence>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
<!-- material (global) node type -->
<xs:complexType name="material_global">
<xs:sequence>
<xs:element name="color" type="color" minOccurs="0" maxOccurs="1" />
<xs:element name="texture" type="texture" minOccurs="0" maxOccurs="1" />
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
<!-- visual node type -->
<xs:complexType name="visual">
<xs:sequence>
<xs:element name="origin"
type="pose" minOccurs="0" maxOccurs="1" />
<xs:element name="geometry"
type="geometry" minOccurs="1" maxOccurs="1" />
<xs:element name="material"
type="material" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<!-- collision node type -->
<xs:complexType name="collision">
<xs:sequence>
<xs:element name="origin"
type="pose" minOccurs="0" maxOccurs="1" />
<xs:element name="geometry"
type="geometry" minOccurs="1" maxOccurs="1" />
<xs:element name="verbose"
type="verbose" minOccurs="0" maxOccurs="1" />
</xs:sequence>
<!-- FIXME: used but not documented -->
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
<!-- link node type -->
<xs:complexType name="link">
<xs:all>
<xs:element name="inertial"
type="inertial" minOccurs="0" maxOccurs="1" />
<xs:element name="visual"
type="visual" minOccurs="0"/>
<xs:element name="collision"
type="collision" minOccurs="0"/>
</xs:all>
<xs:attribute name="name" type="xs:string" use="required" />
<!-- FIXME: undocumented but used by PR2 -->
<xs:attribute name="type" type="xs:string" />
</xs:complexType>
<!-- parent node type -->
<xs:complexType name="parent">
<xs:attribute name="link" type="xs:string" use="required" />
</xs:complexType>
<!-- child node type -->
<xs:complexType name="child">
<xs:attribute name="link" type="xs:string" use="required" />
</xs:complexType>
<!-- axis node type -->
<xs:complexType name="axis">
<xs:attribute name="xyz" type="xs:string" default="1 0 0" />
</xs:complexType>
<!-- calibration node type -->
<xs:complexType name="calibration">
<xs:attribute name="reference_position" type="xs:double"/>
<xs:attribute name="rising" type="xs:double"/>
<xs:attribute name="falling" type="xs:double"/>
</xs:complexType>
<!-- dynamics node type -->
<xs:complexType name="dynamics">
<xs:attribute name="damping" type="xs:double" default="0" />
<xs:attribute name="friction" type="xs:double" default="0" />
</xs:complexType>
<!-- limit node type -->
<xs:complexType name="limit">
<xs:attribute name="lower" type="xs:double" default="0" />
<xs:attribute name="upper" type="xs:double" default="0" />
<xs:attribute name="effort" type="xs:double" default="0" />
<xs:attribute name="velocity" type="xs:double" default="0" />
</xs:complexType>
<!-- safety controller node type -->
<xs:complexType name="safety_controller">
<xs:attribute name="soft_lower_limit" type="xs:double" default="0" />
<xs:attribute name="soft_upper_limit" type="xs:double" default="0" />
<xs:attribute name="k_position" type="xs:double" default="0" />
<xs:attribute name="k_velocity" type="xs:double" use="required" />
</xs:complexType>
<!-- mimic node type -->
<xs:complexType name="mimic">
<xs:attribute name="joint" type="xs:string" use="required" />
<xs:attribute name="multiplier" type="xs:double" default="1" />
<xs:attribute name="offset" type="xs:double" default="0" />
</xs:complexType>
<!-- actuator transmission node type -->
<xs:complexType name="actuator_transmission">
<xs:attribute name="mechanicalReduction" type="xs:double" use="required" />
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
<!-- gap joint transmission node type -->
<xs:complexType name="gap_joint_transmission">
<xs:attribute name="L0" type="xs:double" use="required" />
<xs:attribute name="a" type="xs:double" use="required" />
<xs:attribute name="b" type="xs:double" use="required" />
<xs:attribute name="gear_ratio" type="xs:double" use="required" />
<xs:attribute name="h" type="xs:double" use="required" />
<xs:attribute name="mechanical_reduction" type="xs:double" use="required" />
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="phi0" type="xs:double" use="required" />
<xs:attribute name="r" type="xs:double" use="required" />
<xs:attribute name="screw_reduction" type="xs:double" use="required" />
<xs:attribute name="t0" type="xs:double" use="required" />
<xs:attribute name="theta0" type="xs:double" use="required" />
</xs:complexType>
<!-- passive joint transmission node type -->
<xs:complexType name="passive_joint_transmission">
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
<!-- transmission node type -->
<xs:complexType name="transmission">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="leftActuator"
type="actuator_transmission" minOccurs="0" maxOccurs="1" />
<xs:element name="rightActuator"
type="actuator_transmission" minOccurs="0" maxOccurs="1" />
<xs:element name="flexJoint"
type="actuator_transmission" minOccurs="0" maxOccurs="1" />
<xs:element name="rollJoint"
type="actuator_transmission" minOccurs="0" maxOccurs="1" />
<xs:element name="gap_joint"
type="gap_joint_transmission" minOccurs="0" maxOccurs="1" />
<xs:element name="passive_joint"
type="passive_joint_transmission" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="use_simulated_gripper_joint" minOccurs="0" maxOccurs="1">
<xs:complexType>
</xs:complexType>
</xs:element>
<xs:element name="mechanicalReduction" type="xs:double"
minOccurs="0" maxOccurs="1" />
<xs:element name="actuator" type="name" minOccurs="0" maxOccurs="1" />
<xs:element name="joint" type="name" minOccurs="0" maxOccurs="1" />
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="type" type="xs:string" use="required" />
</xs:complexType>
<!-- joint node type -->
<xs:complexType name="joint">
<xs:all>
<xs:element name="origin"
type="pose" minOccurs="0" maxOccurs="1" />
<xs:element name="parent"
type="parent" minOccurs="1" maxOccurs="1" />
<xs:element name="child"
type="child" minOccurs="1" maxOccurs="1" />
<xs:element name="axis"
type="axis" minOccurs="0" maxOccurs="1" />
<xs:element name="calibration"
type="calibration" minOccurs="0" maxOccurs="1" />
<xs:element name="dynamics"
type="dynamics" minOccurs="0" maxOccurs="1" />
<xs:element name="limit"
type="limit" minOccurs="0" maxOccurs="1" />
<xs:element name="safety_controller"
type="safety_controller" minOccurs="0" maxOccurs="1" />
<xs:element name="mimic"
type="mimic" minOccurs="0" maxOccurs="1" />
</xs:all>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="type" type="xs:string" use="required" />
</xs:complexType>
<!-- root node is always robot -->
<xs:element name="robot">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="joint"
type="joint" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="link"
type="link" minOccurs="0" maxOccurs="unbounded" />
<!-- FIXME: this is used but undocumented -->
<xs:element name="material"
type="material_global" minOccurs="0" maxOccurs="unbounded" />
<!-- FIXME: this is used but undocumented -->
<xs:element name="transmission"
type="transmission" minOccurs="0" maxOccurs="unbounded" />
<!-- FIXME: gazebo extension not supported -->
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
<!-- TM: I suggest adding the following attribute. -->
<xs:attribute name="version" type="xs:string" default="1.0" />
</xs:complexType>
</xs:element>
</xs:schema>
@@ -0,0 +1,10 @@
<svg
width="100%"
height="100%"
viewBox="{min_x} {min_y} {width} {height}"
xmlns="http://www.w3.org/2000/svg"
xmlns:trimesh="https://github.com/mikedh/trimesh"
{attribs}
>
{elements}
</svg>

After

Width:  |  Height:  |  Size: 190 B

@@ -0,0 +1,67 @@
# flake8: noqa
import bpy
import os
def delete_nonresult(bpy):
objects = bpy.data.objects # use data.objects instead of context.scene.objects
if len(objects) <= 1:
return
try:
# earlier than blender <2.8
objects[0].select = False # keep the first object
for other in objects[1:]: # remove all other objects
other.select = True
bpy.ops.object.delete()
objects[0].select = True
except AttributeError:
# blender 2.8 changed this
objects[0].select_set(False)
for other in objects[1:]:
other.select_set(True)
bpy.ops.object.delete()
objects[0].select_set(True)
if __name__ == '__main__':
# clear scene of default box
bpy.ops.wm.read_homefile()
try:
bpy.ops.object.mode_set(mode='OBJECT')
except BaseException:
pass
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=True)
# get temporary files from templated locations
mesh_pre = $MESH_PRE
mesh_post = os.path.abspath(r'$MESH_POST')
for filename in mesh_pre: # use data.objects instead of context.scene.objects
bpy.ops.wm.stl_import(filepath=os.path.abspath(filename))
mesh = bpy.data.objects[0]
# Make sure mesh is the active object
try:
# earlier than blender <2.8
bpy.context.scene.objects.active = mesh
except AttributeError:
# blender 2.8 changed this
bpy.context.view_layer.objects.active = mesh
for other in bpy.data.objects[1:]:
# add boolean modifier
mod = mesh.modifiers.new('boolean', 'BOOLEAN')
mod.object = other
mod.operation = '$OPERATION'
mod.solver = '$SOLVER_OPTIONS'
mod.use_self = $USE_SELF
# used mod.name instead of hard-coded "boolean"
bpy.ops.object.modifier_apply(modifier=mod.name)
delete_nonresult(bpy)
bpy.ops.wm.stl_export(
filepath=mesh_post,
apply_modifiers=True)
@@ -0,0 +1,40 @@
# flake8: noqa
import bpy
from bl_operators.uvcalc_smart_project import main as smart_proj
import os
if __name__ == '__main__':
# clear scene of default box
bpy.ops.wm.read_homefile()
try:
bpy.ops.object.mode_set(mode='OBJECT')
except BaseException:
pass
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=True)
# get temporary files from templated locations
mesh_pre = $MESH_PRE
mesh_post = os.path.abspath(r'$MESH_POST')
# use data.objects instead of context.scene.objects
bpy.ops.import_scene.obj(filepath=os.path.abspath(mesh_pre[0]))
bpy.ops.object.select_all(action='SELECT')
mesh = bpy.data.objects[0]
# Make sure mesh is the active object
try:
# earlier than blender <2.8
bpy.context.scene.objects.active = mesh
except AttributeError:
# blender 2.8 changed this
bpy.context.view_layer.objects.active = mesh
smart_proj(bpy.context, $ISLAND_MARGIN, $ANGLE_LIMIT, 0, True, True)
bpy.ops.export_scene.obj(
filepath=mesh_post,
use_mesh_modifiers=False,
use_uvs=True)
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
<path d="{path_string}" {attribs}/>
@@ -0,0 +1,9 @@
{
"face": "element face $face_count\nproperty list uchar int vertex_indices\n",
"vertex": "element vertex $vertex_count\nproperty float x\nproperty float y\nproperty float z\n",
"vertex_normal": "property float nx\nproperty float ny\nproperty float nz\n",
"color": "property uchar red\nproperty uchar green\nproperty uchar blue\nproperty uchar alpha\n",
"edge": "element edge $edge_count\nproperty int vertex1\nproperty int vertex2\n",
"intro": "ply\nformat $encoding 1.0\ncomment https://github.com/mikedh/trimesh\n",
"outro": "end_header\n"
}
@@ -0,0 +1,47 @@
{
"microinches": 0.001,
"mils": 0.001,
"inches": 1.0,
"feet": 12.0,
"foot": 12.0,
"yards": 36.0,
"miles": 63360,
"angstroms": 3.937007874015748e-9,
"nanometers": 3.937007874015748e-8,
"microns": 3.937007874015748e-5,
"millimeters": 0.03937007874015748,
"centimeters": 0.39370078740157477,
"cm": 0.39370078740157477,
"meters": 39.37007874015748,
"kilometers": 39370.07874015748,
"decimeters": 3.937007874015748,
"decameters": 393.70078740157476,
"hectometers": 3937.0078740157483,
"gigameters": 39370078740.15748,
"au": 5889679948818.897,
"light years": 3.72461748e17,
"parsecs": 1.21483369e18,
"mm": 0.03937007874015748,
"millimeter": 0.03937007874015748,
"in": 1.0,
"\"": 1.0,
"inch": 1.0,
"'": 12.0,
"m": 39.37007874015748,
"meter": 39.37007874015748,
"microinch": 0.001,
"mil": 0.001,
"yard": 36.0,
"mile": 63360,
"angstrom": 3.937007874015748e-9,
"nanometer": 3.937007874015748e-8,
"micron": 3.937007874015748e-5,
"centimeter": 0.39370078740157477,
"kilometer": 39370.07874015748,
"decimeter": 3.937007874015748,
"decameter": 393.70078740157476,
"hectometer": 3937.0078740157483,
"gigameter": 39370078740.15748,
"light year": 3.72461748e17,
"parsec": 1.21483369e18
}