PHP 7.4.33
Preview: MeshPhongNodeMaterial.js Size: 3.33 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/three/src/materials/nodes/MeshPhongNodeMaterial.js
import NodeMaterial from './NodeMaterial.js';
import { shininess, specularColor } from '../../nodes/core/PropertyNode.js';
import { materialShininess, materialSpecular } from '../../nodes/accessors/MaterialNode.js';
import { float } from '../../nodes/tsl/TSLBase.js';
import BasicEnvironmentNode from '../../nodes/lighting/BasicEnvironmentNode.js';
import PhongLightingModel from '../../nodes/functions/PhongLightingModel.js';

import { MeshPhongMaterial } from '../MeshPhongMaterial.js';

const _defaultValues = /*@__PURE__*/ new MeshPhongMaterial();

/**
 * Node material version of `MeshPhongMaterial`.
 *
 * @augments NodeMaterial
 */
class MeshPhongNodeMaterial extends NodeMaterial {

	static get type() {

		return 'MeshPhongNodeMaterial';

	}

	/**
	 * Constructs a new mesh lambert node material.
	 *
	 * @param {?Object} parameters - The configuration parameter.
	 */
	constructor( parameters ) {

		super();

		/**
		 * This flag can be used for type testing.
		 *
		 * @type {boolean}
		 * @readonly
		 * @default true
		 */
		this.isMeshPhongNodeMaterial = true;

		/**
		 * Set to `true` because phong materials react on lights.
		 *
		 * @type {boolean}
		 * @default true
		 */
		this.lights = true;

		/**
		 * The shininess of phong materials is by default inferred from the `shininess`
		 * property. This node property allows to overwrite the default
		 * and define the shininess with a node instead.
		 *
		 * If you don't want to overwrite the shininess but modify the existing
		 * value instead, use {@link materialShininess}.
		 *
		 * @type {?Node<float>}
		 * @default null
		 */
		this.shininessNode = null;

		/**
		 * The specular color of phong materials is by default inferred from the
		 * `specular` property. This node property allows to overwrite the default
		 * and define the specular color with a node instead.
		 *
		 * If you don't want to overwrite the specular color but modify the existing
		 * value instead, use {@link materialSpecular}.
		 *
		 * @type {?Node<vec3>}
		 * @default null
		 */
		this.specularNode = null;

		this.setDefaultValues( _defaultValues );

		this.setValues( parameters );

	}

	/**
	 * Overwritten since this type of material uses {@link BasicEnvironmentNode}
	 * to implement the default environment mapping.
	 *
	 * @param {NodeBuilder} builder - The current node builder.
	 * @return {?BasicEnvironmentNode<vec3>} The environment node.
	 */
	setupEnvironment( builder ) {

		const envNode = super.setupEnvironment( builder );

		return envNode ? new BasicEnvironmentNode( envNode ) : null;

	}

	/**
	 * Setups the lighting model.
	 *
	 * @return {PhongLightingModel} The lighting model.
	 */
	setupLightingModel( /*builder*/ ) {

		return new PhongLightingModel();

	}

	/**
	 * Setups the phong specific node variables.
	 *
	 * @param {NodeBuilder} builder - The current node builder.
	 */
	setupVariants( /*builder*/ ) {

		// SHININESS

		const shininessNode = ( this.shininessNode ? float( this.shininessNode ) : materialShininess ).max( 1e-4 ); // to prevent pow( 0.0, 0.0 )

		shininess.assign( shininessNode );

		// SPECULAR COLOR

		const specularNode = this.specularNode || materialSpecular;

		specularColor.assign( specularNode );

	}

	copy( source ) {

		this.shininessNode = source.shininessNode;
		this.specularNode = source.specularNode;

		return super.copy( source );

	}

}

export default MeshPhongNodeMaterial;

Directory Contents

Dirs: 1 × Files: 18
Name Size Perms Modified Actions
manager DIR
- drwxr-xr-x 2025-03-28 11:04:38
Edit Download
13.53 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
816 B lrw-r--r-- 2025-03-28 11:04:38
Edit Download
3.69 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
2.94 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
1.73 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
1.58 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
1.71 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
3.33 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
15.96 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
4.89 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
4.65 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
1.17 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
28.35 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
1.51 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
3.05 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.17 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
4.78 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.18 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).