Set color of object (Autodesk forge) - autodesk-forge

This works on model which don't have any color:
this.viewer.setThemingColor(node, red, this.model);
But not on model with objects which have a color.
In the docs you can read:
Highlight an object with a theming color that is blended with the
original object’s material.
Blended? What does it mean? How do I set a color to an object if it already has a color?
P.S:
Typescript typedefinition to the Viewer would really be helpfull.
Update
Think it has something to do with the type of object.
I have run both isolate and setThemingColor (red) on the same items.
In the screenshot below, the red door in lower right corner is selected:
It has a "material" heading.
In this screenshot the door next to it (turquoise) is selected. It's missing the material heading.
Do I need to "apply" material or something to make it change color?

Did you supply a THREE.Vector4 object as color or the second argument? Just dug into the code and it wasn't any type check logic and would lead to your error if the wrong type is given. Also make sure you put in the right model object as the third argument, otherwise the render won't know which model to apply the colors when you have multiple models.
You can details about the usage of this method below:
https://forge.autodesk.com/en/docs/viewer/v6/reference/javascript/viewer3d/#setthemingcolor-dbid-color-model
Edit:
If the component is lacking a material pls see here on how to add a custom one: https://forge.autodesk.com/blog/using-dynamic-texture-inside-custom-shaders
PS: We are working on TypeScript definitions for Viewer and Forge SDK and they could be released soon. Stay tuned!

Related

Dynamically change line color dcc.Graph Plotly Dash between annotations

I'm writing a 'template creation' app using the dcc.Graph image annotation features in Plotly Dash.
The user adds multiple rectangles for specific features in the image (an invoice) and my callback captures the coordinates of each rectangle via the relayoutData variable. I want to use a different color for each rectangle, but can't figure out how to do it.
It seems like the only way to change the newshapes fillcolor
property is to replace the whole figure, but then I lose all previous shapes
All and any help appreciated.
Andrew
I have just found the following demo that does exactly what I am trying to do:
https://dash-gallery.plotly.host/dash-image-annotation/
Now to unpack the logic and adapt it to my context ... Happy 2021!
Andrew

How can you change the Viewer's selection color?

I see that the viewer has a MeshPhongMaterial that it looks like it applies to scene objects that you click, but when I try to change the RGB values of this, it does nothing. So, how do you change the selection color in the viewer?
I think the code is what you are looking for. Please check if it helps.
viewer.impl.setSelectionColor(new THREE.Color(1,0,0))
In addition, another SO post might be also interesting to you:
Autodesk Forge - How to stop recoloring of object when selected

How to use Material.fromType in Cesium

I am having trouble using the Cesium.Material.fromType function to create a material using a type and uniforms.
I am referring to the docs here: link
I have the following example I am trying to get to work, however I would like to next use the Dot dynamic type not color. Color seems easier for the moment.
Sandcastle example
This works:
material : Cesium.Color.GREEN
This does not:
material : Cesium.Material.fromType('Color', {
color : new Cesium.Color(1.0, 0.0, 0.0, 1.0)
})
I am getting this error:
Uncaught DeveloperError: Unable to infer material type: [object Object]
It seems like the material property on entities cannot be an object, am I missing a step to convert the material into a primitive type?
So I don't have great news here, but I can at least explain what's wrong. As you know Cesium has two separate API layers, the "Entity" layer (for complex objects like moving vehicles), and the "Primitive" layer (for graphics primitives, like collections of billboards or meshes). What you're doing here is directly constructing a material from the Primitive layer and trying to assign it to an Entity, which will not work.
At the Entity layer, materials are described by a class derived from the abstract base class of MaterialProperty. The derived classes are all Entity-layer classes listed in that doc link, for example there's a ColorMaterialProperty class for solid colors. Being at the entity layer makes these things time-dynamic, so for example your solid color could be blue when the simulation time is at 04:00 and change to red at 06:00, etc. Primitive materials do not have a concept of time baked in and are much lighter-weight as a result.
And now the bad news: There doesn't appear to be a DotMaterialProperty class in Cesium currently. This means the Dot material exists only at the primitive layer API and is not hooked up to the entity layer. The team likes to say "contributions welcome" at this point, and if you were so inclined you could probably get this hooked up by copying either StripeMaterialProperty or GridMaterialProperty and editing it to hook up to Dot.
But in the short term, if you need the Dot material more than you need the Entity layer, you could transition your code over to graphics primitives. You can find sample code for this in the Material Sandcastle Demo under the Procedural Textures drop-down box.

Custom Control Code Behind (winRT XAML C++)?

I am creating a custom control. The idea is to use 4 sliders to set the RGBA values and a rectangle to display the resulting color. I have created a Dependency Property for the color result so I can bind to it. That is working so far. What I don't understand is how to combine the 4 slider results into a single color value. I know how to do this, just not where to do it. There doesn't seem to be any code behind for custom controls. Where do I implement the logic for my custom controls? What am I missing here? Thanks.
You need to override OnApplyTemplate method and call GetTemplatePart for each template part control and store these in private fields. Then add dependency properties for each of the RGBA channels and maybe use TemplateBinding to bind slider values to the properties. Finally in the callbacks of your dependency properties set the Color property value.

Triangle edges in CanvasRenderer

I am a newbie regarding three.js and I have a problem with imported geometry (js-file from 3dsmax inclusive all material and textures) and the CanvasRenderer. The CanvasRenderer displays the triangle edges of imported geometry, the WebGLRenderer works well.
Canvas example:
http://der-n.square7.ch/threejs/examples/teapot_canvas.html
WebGL example:
http://der-n.square7.ch/threejs/examples/teapot_webgl.html
In the three.js library I have found the option "overdraw: true" for a material to fix this behaviour but obviously the material+textures are defined by the above mentioned exported 3dsmax js-file.
For the tests I use the "misc_camera_trackball" example with small changes (I have added a JSONLoader, changed some camera and trackball parameters, changed some light colors, added a CanvasRenderer)
Any hints how to solve this?
Thanks for your help.
Best regards
Oggy
In the loader callback, you have all of the loaded materials in an array geometry.materials. You could loop over those materials and set the overdraw property to true for each.
As far as I know, THREE.MeshFaceMaterial is just a pass-through material that indicates "faces have an index that points to a material instance to use from the geometry's materials array", so setting properties for MeshFaceMaterial won't have any effect.