three 基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
871 B

2 years ago
import Node from '../core/Node.js';
import CameraNode from '../accessors/CameraNode.js';
import ModelNode from '../accessors/ModelNode.js';
import OperatorNode from '../math/OperatorNode.js';
import PositionNode from '../accessors/PositionNode.js';
class ModelViewProjectionNode extends Node {
constructor( position = new PositionNode() ) {
super( 'vec4' );
this.position = position;
this._mvpMatrix = new OperatorNode( '*', new CameraNode( CameraNode.PROJECTION_MATRIX ), new ModelNode( ModelNode.VIEW_MATRIX ) );
}
generate( builder, output ) {
const type = this.getType( builder );
const mvpSnipped = this._mvpMatrix.build( builder );
const positionSnipped = this.position.build( builder, 'vec3' );
return builder.format( `( ${mvpSnipped} * vec4( ${positionSnipped}, 1.0 ) )`, type, output );
}
}
export default ModelViewProjectionNode;