Skip to content

Instantly share code, notes, and snippets.

@fragmuffin
Last active February 9, 2018 11:42
Show Gist options
  • Save fragmuffin/b81859ded23941d9e8c4c0bf5b7077b4 to your computer and use it in GitHub Desktop.
Save fragmuffin/b81859ded23941d9e8c4c0bf5b7077b4 to your computer and use it in GitHub Desktop.
cqparts exported glTF examples
{
"accessors": [
{
"bufferView": 0,
"byteOffset": 0,
"componentType": 5126,
"count": 8,
"max": [
0.6,
0.6,
0.6
],
"min": [
-0.6,
-0.6,
-0.6
],
"type": "VEC3"
},
{
"bufferView": 1,
"byteOffset": 0,
"componentType": 5121,
"count": 36,
"type": "SCALAR"
}
],
"asset": {
"generator": "cqparts_0.1.0",
"version": "2.0"
},
"bufferViews": [
{
"buffer": 0,
"byteLength": 96,
"byteOffset": 0,
"byteStride": 12,
"target": 34962
},
{
"buffer": 0,
"byteLength": 36,
"byteOffset": 96,
"target": 34963
}
],
"buffers": [
{
"byteLength": 132,
"uri": "cube.bin"
}
],
"materials": [
{
"alphaCutoff": 1.0,
"alphaMode": "MASK",
"pbrMetallicRoughness": {
"baseColorFactor": [
0.7529,
0.7529,
0.7529,
1.0
],
"metallicFactor": 0.1,
"roughnessFactor": 0.7
}
}
],
"meshes": [
{
"name": "cube",
"primitives": [
{
"attributes": {
"POSITION": 0
},
"indices": 1,
"material": 0,
"mode": 4
}
]
}
],
"nodes": [
{
"children": [
1
],
"matrix": [
0.001,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.001,
0.0,
0.0,
0.001,
0.0,
0.0,
0.0,
0.0,
0.0,
1.0
]
},
{
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0
],
"mesh": 0,
"name": "cube"
}
],
"scene": 0,
"scenes": [
{
"nodes": [
0
]
}
]
}
#!/usr/bin/env python
import cqparts
from cqparts.display import display
# --- Cube
from cqparts_misc.basic.primatives import Cube
cube = Cube()
display(cube)
cube.exporter('gltf')('cube.gltf')
# --- Cylinder with a CoordSysIndicator on top
from cqparts import constraint
from cqparts_misc.basic.primatives import Cylinder
from cqparts_misc.basic.indicators import CoordSysIndicator
class Thing(cqparts.Assembly):
def make_components(self):
return {
'cylinder': Cylinder(radius=10, length=20),
'indicator': CoordSysIndicator(),
}
def make_constraints(self):
return [
constraint.Fixed(self.components['cylinder'].mate_origin),
constraint.Coincident(
self.components['indicator'].mate_origin,
self.components['cylinder'].mate_top,
),
]
thing = Thing()
display(thing)
thing.exporter('gltf')('thing.gltf')
{
"accessors": [
{
"bufferView": 0,
"byteOffset": 0,
"componentType": 5126,
"count": 396,
"max": [
10.1,
10.09874127673875,
20.1
],
"min": [
-10.1,
-10.09874127673875,
-0.1
],
"type": "VEC3"
},
{
"bufferView": 1,
"byteOffset": 0,
"componentType": 5123,
"count": 2364,
"type": "SCALAR"
},
{
"bufferView": 2,
"byteOffset": 0,
"componentType": 5126,
"count": 8,
"max": [
0.6,
10.1,
0.6
],
"min": [
-0.6,
-0.1,
-0.6
],
"type": "VEC3"
},
{
"bufferView": 3,
"byteOffset": 0,
"componentType": 5121,
"count": 36,
"type": "SCALAR"
},
{
"bufferView": 4,
"byteOffset": 0,
"componentType": 5126,
"count": 8,
"max": [
10.1,
0.6,
0.6
],
"min": [
-0.1,
-0.6,
-0.6
],
"type": "VEC3"
},
{
"bufferView": 5,
"byteOffset": 0,
"componentType": 5121,
"count": 36,
"type": "SCALAR"
},
{
"bufferView": 6,
"byteOffset": 0,
"componentType": 5126,
"count": 8,
"max": [
0.6,
0.6,
10.1
],
"min": [
-0.6,
-0.6,
-0.1
],
"type": "VEC3"
},
{
"bufferView": 7,
"byteOffset": 0,
"componentType": 5121,
"count": 36,
"type": "SCALAR"
}
],
"asset": {
"generator": "cqparts_0.1.0",
"version": "2.0"
},
"bufferViews": [
{
"buffer": 0,
"byteLength": 4752,
"byteOffset": 0,
"byteStride": 12,
"target": 34962
},
{
"buffer": 0,
"byteLength": 4728,
"byteOffset": 4752,
"target": 34963
},
{
"buffer": 1,
"byteLength": 96,
"byteOffset": 0,
"byteStride": 12,
"target": 34962
},
{
"buffer": 1,
"byteLength": 36,
"byteOffset": 96,
"target": 34963
},
{
"buffer": 2,
"byteLength": 96,
"byteOffset": 0,
"byteStride": 12,
"target": 34962
},
{
"buffer": 2,
"byteLength": 36,
"byteOffset": 96,
"target": 34963
},
{
"buffer": 3,
"byteLength": 96,
"byteOffset": 0,
"byteStride": 12,
"target": 34962
},
{
"buffer": 3,
"byteLength": 36,
"byteOffset": 96,
"target": 34963
}
],
"buffers": [
{
"byteLength": 9480,
"uri": "thing.cylinder.bin"
},
{
"byteLength": 132,
"uri": "thing.indicator.y.bin"
},
{
"byteLength": 132,
"uri": "thing.indicator.x.bin"
},
{
"byteLength": 132,
"uri": "thing.indicator.z.bin"
}
],
"materials": [
{
"alphaCutoff": 1.0,
"alphaMode": "MASK",
"pbrMetallicRoughness": {
"baseColorFactor": [
0.7529,
0.7529,
0.7529,
1.0
],
"metallicFactor": 0.1,
"roughnessFactor": 0.7
}
},
{
"alphaCutoff": 1.0,
"alphaMode": "MASK",
"pbrMetallicRoughness": {
"baseColorFactor": [
0.0,
1.0,
0.0,
1.0
],
"metallicFactor": 0.1,
"roughnessFactor": 0.7
}
},
{
"alphaCutoff": 1.0,
"alphaMode": "MASK",
"pbrMetallicRoughness": {
"baseColorFactor": [
1.0,
0.0,
0.0,
1.0
],
"metallicFactor": 0.1,
"roughnessFactor": 0.7
}
},
{
"alphaCutoff": 1.0,
"alphaMode": "MASK",
"pbrMetallicRoughness": {
"baseColorFactor": [
0.0,
0.0,
1.0,
1.0
],
"metallicFactor": 0.1,
"roughnessFactor": 0.7
}
}
],
"meshes": [
{
"name": "thing.cylinder",
"primitives": [
{
"attributes": {
"POSITION": 0
},
"indices": 1,
"material": 0,
"mode": 4
}
]
},
{
"name": "thing.indicator.y",
"primitives": [
{
"attributes": {
"POSITION": 2
},
"indices": 3,
"material": 1,
"mode": 4
}
]
},
{
"name": "thing.indicator.x",
"primitives": [
{
"attributes": {
"POSITION": 4
},
"indices": 5,
"material": 2,
"mode": 4
}
]
},
{
"name": "thing.indicator.z",
"primitives": [
{
"attributes": {
"POSITION": 6
},
"indices": 7,
"material": 3,
"mode": 4
}
]
}
],
"nodes": [
{
"children": [
1
],
"matrix": [
0.001,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.001,
0.0,
0.0,
0.001,
0.0,
0.0,
0.0,
0.0,
0.0,
1.0
]
},
{
"children": [
2,
3
],
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0
],
"name": "thing"
},
{
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0
],
"mesh": 0,
"name": "thing.cylinder"
},
{
"children": [
4,
5,
6
],
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
20.0,
1.0
],
"name": "thing.indicator"
},
{
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0
],
"mesh": 1,
"name": "thing.indicator.y"
},
{
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0
],
"mesh": 2,
"name": "thing.indicator.x"
},
{
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0
],
"mesh": 3,
"name": "thing.indicator.z"
}
],
"scene": 0,
"scenes": [
{
"nodes": [
0
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment