Skip to main content
1-Visitor
March 5, 2019
Solved

ApplyOccludeOpacity() doesn't work in Hololens

  • March 5, 2019
  • 1 reply
  • 3838 views

I was trying to figure out an automated way to make punch of parts assembly of my model to be transparent. My model consist of 150 parts and it makes no sense to drag and drop modelitem widget for every part.

 

I used the following code

 

 modelitem="model-1-/0/"+i;
 tml3dRenderer.GetObject(modelitem).GetWidget().ApplyOccludeOpacity(0,0);

Everything works good in preview mode, but surprisingly it doesn't work at all in HoloLens. Waste much my time on preview while not all function are supported.

 

Any help of alternative way to make this work this out?

Best answer by RolandRaytchev

Hi @SteveGhee 

Thanks for the correction and pointing of the correct usage!

The way I suggested there was found by trial-and-error (because there is no documentation)  and where I tested and shared here as  the only option I did know. 

Mostly it was used to set the opacity but also it did have the effedt that it will hide an component mostly temporary , where I do not think that it have to much negative effect. Ok I agree is bad usage for permanent hiding of components. 

So I will correct the code in my post regarding to the dev recommendation

I think the correct expression should be:

tml3dRenderer.setProperties($scope.currentSelection, { hidden:true } ); 

 

1 reply

21-Topaz I
March 11, 2019

Hi @nqwifly,

 

when I am looking on this description , I believe the main intent there is to try ot hide some component dynamically.

Yes I could confirm that this does not work on HoloLens but work on preview.

So this is because there are some differences in the implementation on the HoloLens so that the code will lead to exception.

But actually, the code on the HoloLens is more easily to implement because the display follow the rgba alpha channel parameter and we do not need to set explicitly the opacity (it also will not work) but we need to do this in preview mode.

So the following code:

 

var PICK_COLOR_OPACITY1 = "rgba(,,,0.0)";

$rootScope.$on('modelLoaded', function() {
 //do some code here
 
angular.forEach($element.find('twx-dt-model'), function(value, key) {
 // search all twx-td-model's -> means all model widgets
 angular.element(value).scope().$on('userpick',function(event,target,parent,edata) {
 //for each model widget will set a userpick listener 
 console.log('edata');console.warn(edata);
	 console.log("JSON.parse(edata)");console.warn(JSON.parse(edata)); 
 	 	var pathid = JSON.parse(edata).occurrence;
	 $scope.currentSelection = target + "-" + pathid;
// this is the current selection - the selected component occurence
// you can use it for example as shown below
 console.log("=>>"+$scope.currentSelection);
 try{ 
 if(twx.app.isPreview() == true) //will hide it in preview
 tml3dRenderer.GetObject($scope.currentSelection).GetWidget().ApplyOccludeOpacity(0.0,0.0);
 else
 tml3dRenderer.setColor($scope.currentSelection, PICK_COLOR_OPACITY1); 
} catch (e1234) {$scope.view.wdg['3DLabel-1']['text']= "e="+e1234; }

	 } ) //end of the userpick defintion	 
		 } ) //end of for each funciton
 
 } )

Will work on both in preview and on HoloLens:

2019-03-11_18-07-29.gif

here on the HoloLense:2019-03-11_18-02-41.gif

 

So here the opacity -> tha alpha channel /  is defined but the color should not be changed:

 

 

var PICK_COLOR_OPACITY1 = "rgba(,,,0.0)";

 

to change the rgba expression by setting another value of transparency you can use some construct like this:

 

 

 

var PICK_COLOR_OPACITY1 = "rgba(,,,0.0)";
var OPACITY_VAL=0.2;
var PICK_COLOR_OPACITY2= PICK_COLOR_OPACITY1.replace( "0.0)",OPACITY_VAL+")");

which will set transperancy value of  0.2

The code above is more than intended for setting colors and transparency  . According a recommendation from development for hiding of components is better to use  the hidden property

The code is then more simplified:

 

angular.forEach($element.find('twx-dt-model'), function(value, key) {
 // search all twx-td-model's -> means all model widgets
 angular.element(value).scope().$on('userpick',function(event,target,parent,edata) {
 //for each model widget will set a userpick listener 
 try{
 console.log('edata');console.warn(edata);
	 console.log("JSON.parse(edata)");console.warn(JSON.parse(edata)); 
 	 	var pathid = JSON.parse(edata).occurrence;
	 $scope.currentSelection = target + "-" + pathid;
 console.log("=>>"+$scope.currentSelection);
 } catch (ea) {console.error("not twx-model is clicked but still fired")}
 try{ 
 // here below the change recommended from R&D
 tml3dRenderer.setProperties($scope.currentSelection, { hidden:true } ); 
 
} catch (e1234) {console.error( "e="+e1234); }

 

12-Amethyst
April 3, 2019

to hide a specific item :-

tml3dRenderer.setColor($scope.currentSelection, { hidden : true } );

 

do NOT use color/opacity settings - this is VERY inefficient and bad practice.  Experiences doing things this way will get rejected.

21-Topaz I
April 4, 2019

Hi @SteveGhee 

Thanks for the correction and pointing of the correct usage!

The way I suggested there was found by trial-and-error (because there is no documentation)  and where I tested and shared here as  the only option I did know. 

Mostly it was used to set the opacity but also it did have the effedt that it will hide an component mostly temporary , where I do not think that it have to much negative effect. Ok I agree is bad usage for permanent hiding of components. 

So I will correct the code in my post regarding to the dev recommendation

I think the correct expression should be:

tml3dRenderer.setProperties($scope.currentSelection, { hidden:true } );