﻿// Copyright 2002-2009.  Adobe Systems, Incorporated.  All rights reserved.// This script will  take a 3d model  and invert the transparency of each material// This was needed to fix some COLLADA models that have bad transparency settings// enable double clicking from the Macintosh Finder or the Windows Explorer#target photoshop// in case we double clicked the fileapp.bringToFront();// debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)// $.level = 0;// debugger; // launch debugger on next linevar layer3DStrID 			= stringIDToTypeID( "layer3D" );var sceneID 				= stringIDToTypeID( "key3DScene");var setMaterialPropertyID 	= stringIDToTypeID( "set3DMaterialScalar" );var idkeythreeDName 		= stringIDToTypeID( "key3DName" );var propertyID 				= charIDToTypeID( 'Prpr' );var layerID 				= charIDToTypeID( 'Lyr ' );var targetID 				= charIDToTypeID( 'Trgt' );var ordinalID 				= charIDToTypeID( 'Ordn' );var materialID 				= charIDToTypeID( 'mtll');var transparencyID 			= charIDToTypeID( 'Trns');var nameID 					= charIDToTypeID( 'Nm  ');var idType 					= charIDToTypeID( "Type" );var idOpacity 				= charIDToTypeID( "Vl  " );var opacityType 			= 1;var strAlert = localize( "$$$/Alert/3D/layernotselected=You must have a 3D layer selected." );//Execute a current layer data commandvar get3DLayerAction = new ActionReference();get3DLayerAction.putProperty( propertyID , layer3DStrID );get3DLayerAction.putEnumerated( layerID, ordinalID, targetID );//Get the 3D layer data out of the currently selected layervar layerDescriptor = executeActionGet( get3DLayerAction );if ( layerDescriptor.hasKey( layer3DStrID ) )	{	//Get the scene	var sceneDescriptor = layerDescriptor.getObjectValue( layer3DStrID );	var sceneObject = sceneDescriptor.getObjectValue( sceneID );		//Get the material list	var materialList = sceneObject.getList(materialID);	for(var i=0;i<materialList.count;i++)		{		//For each material get the name and transparency		var materialObject = materialList.getObjectValue(i);		var transparency = materialObject.getDouble(transparencyID);		var materialName = materialObject.getString(nameID);				//Create a new material descriptor and put in the type (opacity), new opacity value, and the name of the material		var newMaterialDescriptor = new ActionDescriptor();		newMaterialDescriptor.putInteger( idType, opacityType );		newMaterialDescriptor.putDouble( idOpacity, 1-transparency );		newMaterialDescriptor.putString( idkeythreeDName, materialName );				//Send the setMateiralProperty action with the new material descriptor		executeAction( setMaterialPropertyID, newMaterialDescriptor, DialogModes.NO );		}	}else	alert(strAlert);