From 489269b17fb717e441aaae89d476165d2506c8c2 Mon Sep 17 00:00:00 2001 From: Viktor Kovacs Date: Thu, 15 Apr 2021 20:47:30 +0200 Subject: [PATCH] Make material color win over display color. --- source/external/rhino.importer.js | 34 +++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/source/external/rhino.importer.js b/source/external/rhino.importer.js index 29dfe2c..b662e6e 100644 --- a/source/external/rhino.importer.js +++ b/source/external/rhino.importer.js @@ -168,19 +168,41 @@ OV.Importer3dm = class extends OV.ImporterBase } let rhinoColor = null; - if (rhinoAttributes.colorSource === this.rhino.ObjectColorSource.ColorFromObject) { - rhinoColor = rhinoAttributes.objectColor; - } else if (rhinoAttributes.colorSource === this.rhino.ObjectColorSource.ColorFromLayer) { + if (rhinoAttributes.materialSource === this.rhino.ObjectMaterialSource.MaterialFromObject) { + let materialIndex = rhinoAttributes.materialIndex; + if (materialIndex > -1) { + let material = rhinoDoc.materials ().get (materialIndex); + rhinoColor = material.diffuseColor; + } + } else if (rhinoAttributes.materialSource === this.rhino.ObjectMaterialSource.MaterialFromLayer) { let layerIndex = rhinoAttributes.layerIndex; if (layerIndex > 0) { let layer = rhinoDoc.layers ().get (layerIndex); - rhinoColor = layer.color; + let layerMaterialIndex = layer.renderMaterialIndex; + if (layerMaterialIndex > -1) { + let material = rhinoDoc.materials ().get (layerMaterialIndex); + rhinoColor = material.diffuseColor; + } } - } else if (rhinoAttributes.colorSource === this.rhino.ObjectColorSource.ColorFromParent) { + } else if (rhinoAttributes.materialSource === this.rhino.ObjectMaterialSource.MaterialFromParent) { // TODO: handle instances } + + if (rhinoColor === null) { + if (rhinoAttributes.colorSource === this.rhino.ObjectColorSource.ColorFromObject) { + rhinoColor = rhinoAttributes.objectColor; + } else if (rhinoAttributes.colorSource === this.rhino.ObjectColorSource.ColorFromLayer) { + let layerIndex = rhinoAttributes.layerIndex; + if (layerIndex > 0) { + let layer = rhinoDoc.layers ().get (layerIndex); + rhinoColor = layer.color; + } + } else if (rhinoAttributes.colorSource === this.rhino.ObjectColorSource.ColorFromParent) { + // TODO: handle instances + } + } - let color = new OV.Color (250, 250, 250); + let color = new OV.Color (255, 255, 255); if (rhinoColor !== null) { color = new OV.Color (rhinoColor.r, rhinoColor.g, rhinoColor.b); }