Skip to content

Instantly share code, notes, and snippets.

@fragmuffin
Last active December 30, 2018 01:14
Show Gist options
  • Save fragmuffin/040b725e42fe4f95f2d221b06d6f25a4 to your computer and use it in GitHub Desktop.
Save fragmuffin/040b725e42fe4f95f2d221b06d6f25a4 to your computer and use it in GitHub Desktop.
cqparts _render color prop
./test.sh

output is:

FreeCAD 0.17, Libs: 0.17R13522 (Git)
Fasteners workbench Loaded
[
  {
    "alphaCutoff": 1,
    "alphaMode": "BLEND",
    "pbrMetallicRoughness": {
      "baseColorFactor": [
        0,
        0,
        1,
        1
      ],
      "metallicFactor": 0.1,
      "roughnessFactor": 0.7
    }
  }
]
[
  {
    "alphaCutoff": 1,
    "alphaMode": "BLEND",
    "pbrMetallicRoughness": {
      "baseColorFactor": [
        0,
        0,
        1,
        1
      ],
      "metallicFactor": 0.1,
      "roughnessFactor": 0.7
    }
  }
]

Note: both are blue, but c1 should be green

from cqparts_misc.basic.primatives import Box
from cqparts.params import *
from cqparts.display.material import COLOR
class Case(Box):
color = String('red')
def initialize_parameters(self):
self._render.color = COLOR[self.color]
# Create Objects
c1 = Case(color='green')
c2 = Case(color='blue')
# Export
c1.exporter('gltf')('c1.gltf')
c2.exporter('gltf')('c2.gltf')
#!/usr/bin/env bash
python test.py
cat c1.gltf | jq '.materials'
cat c2.gltf | jq '.materials'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment