Mod: Show regressions in shape colouring

This PR demonstrates the known regressions of the recently merged material branch:
* Changing the transparency after setting color per face will reset them
* The result of boolean operations or compound doesn't inherit the colour of its input objects
* If colour is set per face to a boolean operaton object then saving and restoring the file causes weird rendering behaviour
  because material binding is set to PER_PART but only a single colour is defined
* If a shape inside a part container has set colour per face then saving and restoring as STEP file causes weird rendering
behaviour for the same reason
* Shape binder or datum objects don't show the correct default shape colour
This commit is contained in:
wmayer
2024-04-09 20:32:32 +02:00
committed by wwmayer
parent cc96f2718e
commit 3a34fe080a
5 changed files with 299 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import Part
import os
import tempfile
import unittest
from BOPTools import BOPFeatures
from pivy import coin
class ColorPerFaceTest(unittest.TestCase):
@@ -84,3 +85,123 @@ class ColorPerFaceTest(unittest.TestCase):
mat = paths.get(2).getTail()
self.assertEqual(mat.diffuseColor.getNum(), 6)
def testTransparency(self):
"""
If color per face is set then changing the transparency must not revert it
"""
box = self.doc.addObject("Part::Box","Box")
self.doc.recompute()
box.ViewObject.DiffuseColor = [(1.,0.,0.,0.),
(1.,0.,0.,0.),
(1.,0.,0.,0.),
(1.,0.,0.,0.),
(1.,1.,0.,0.),
(1.,1.,0.,0.)]
box.ViewObject.Transparency = 35
self.assertEqual(box.ViewObject.Transparency, 35)
sa = coin.SoSearchAction()
sa.setType(coin.SoMaterialBinding.getClassTypeId())
# We need an easier way to access nodes of a display mode
sa.setInterest(coin.SoSearchAction.ALL)
sa.apply(box.ViewObject.RootNode)
paths = sa.getPaths()
bind = paths.get(2).getTail()
self.assertEqual(bind.value.getValue(), bind.PER_PART)
sa = coin.SoSearchAction()
sa.setType(coin.SoMaterial.getClassTypeId())
# We need an easier way to access nodes of a display mode
sa.setInterest(coin.SoSearchAction.ALL)
sa.apply(box.ViewObject.RootNode)
paths = sa.getPaths()
mat = paths.get(2).getTail()
self.assertEqual(mat.diffuseColor.getNum(), 6)
def testMultiFuse(self):
"""
Both input objects are red. So, it's expected that the output object is red, too.
"""
box = self.doc.addObject("Part::Box","Box")
cyl = self.doc.addObject("Part::Cylinder","Cylinder")
box.ViewObject.ShapeColor = (1.,0.,0.,0.)
cyl.ViewObject.ShapeColor = (1.,0.,0.,0.)
self.doc.recompute()
bp = BOPFeatures.BOPFeatures(self.doc)
fuse = bp.make_multi_fuse([box.Name, cyl.Name])
self.assertEqual(fuse.TypeId, "Part::MultiFuse")
self.doc.recompute()
sa = coin.SoSearchAction()
sa.setType(coin.SoMaterialBinding.getClassTypeId())
# We need an easier way to access nodes of a display mode
sa.setInterest(coin.SoSearchAction.ALL)
sa.apply(fuse.ViewObject.RootNode)
paths = sa.getPaths()
bind = paths.get(2).getTail()
self.assertEqual(bind.value.getValue(), bind.PER_PART)
sa = coin.SoSearchAction()
sa.setType(coin.SoMaterial.getClassTypeId())
# We need an easier way to access nodes of a display mode
sa.setInterest(coin.SoSearchAction.ALL)
sa.apply(fuse.ViewObject.RootNode)
paths = sa.getPaths()
mat = paths.get(2).getTail()
self.assertEqual(mat.diffuseColor.getNum(), 11)
self.assertEqual(len(fuse.Shape.Faces), 11)
self.assertEqual(len(fuse.ViewObject.DiffuseColor), 11)
self.assertEqual(fuse.ViewObject.DiffuseColor[0], (1.,0.,0.,0.))
def testMultiFuseSaveRestore(self):
box = self.doc.addObject("Part::Box","Box")
cyl = self.doc.addObject("Part::Cylinder","Cylinder")
box.ViewObject.ShapeColor = (1.,0.,0.,0.)
cyl.ViewObject.ShapeColor = (1.,0.,0.,0.)
self.doc.recompute()
bp = BOPFeatures.BOPFeatures(self.doc)
fuse = bp.make_multi_fuse([box.Name, cyl.Name])
self.assertEqual(fuse.TypeId, "Part::MultiFuse")
self.doc.recompute()
fuse.ViewObject.DiffuseColor = [(1.,0.,0.,0.)] * 11
self.doc.saveAs(self.fileName)
App.closeDocument(self.doc.Name)
self.doc = App.openDocument(self.fileName)
fuse = self.doc.ActiveObject
self.assertEqual(len(fuse.Shape.Faces), 11)
self.assertEqual(len(fuse.ViewObject.DiffuseColor), 11)
self.assertEqual(fuse.ViewObject.DiffuseColor[0], (1.,0.,0.,0.))
sa = coin.SoSearchAction()
sa.setType(coin.SoMaterialBinding.getClassTypeId())
# We need an easier way to access nodes of a display mode
sa.setInterest(coin.SoSearchAction.ALL)
sa.apply(fuse.ViewObject.RootNode)
paths = sa.getPaths()
bind = paths.get(2).getTail()
self.assertEqual(bind.value.getValue(), bind.PER_PART)
sa = coin.SoSearchAction()
sa.setType(coin.SoMaterial.getClassTypeId())
# We need an easier way to access nodes of a display mode
sa.setInterest(coin.SoSearchAction.ALL)
sa.apply(fuse.ViewObject.RootNode)
paths = sa.getPaths()
mat = paths.get(2).getTail()
self.assertEqual(mat.diffuseColor.getNum(), 11)