createCamera method

dynamic createCamera(
  1. dynamic relationships
)

Implementation

createCamera( relationships ) {

	var model;
	var cameraAttribute;

	relationships.children.forEach( ( child ) {

		var attr = fbxTree.Objects["NodeAttribute"][ child["ID"] ];

		if ( attr != null ) {

			cameraAttribute = attr;

		}

	} );

	if ( cameraAttribute == null ) {

		model = new Object3D();

	} else {

		var type = 0;
		if ( cameraAttribute.CameraProjectionType != null && cameraAttribute.CameraProjectionType.value == 1 ) {

			type = 1;

		}

		var nearClippingPlane = 1;
		if ( cameraAttribute.NearPlane != null ) {

			nearClippingPlane = cameraAttribute.NearPlane.value / 1000;

		}

		var farClippingPlane = 1000;
		if ( cameraAttribute.FarPlane != null ) {

			farClippingPlane = cameraAttribute.FarPlane.value / 1000;

		}


		var width = innerWidth;
		var height = innerHeight;

		if ( cameraAttribute.AspectWidth != null && cameraAttribute.AspectHeight != null ) {

			width = cameraAttribute.AspectWidth.value;
			height = cameraAttribute.AspectHeight.value;

		}

		var aspect = width / height;

		var fov = 45;
		if ( cameraAttribute.FieldOfView != null ) {

			fov = cameraAttribute.FieldOfView.value;

		}

		var focalLength = cameraAttribute.FocalLength ? cameraAttribute.FocalLength.value : null;

		switch ( type ) {

			case 0: // Perspective
				model = new PerspectiveCamera( fov, aspect, nearClippingPlane, farClippingPlane );
				if ( focalLength != null ) model.setFocalLength( focalLength );
				break;

			case 1: // Orthographic
				model = new OrthographicCamera( - width / 2, width / 2, height / 2, - height / 2, nearClippingPlane, farClippingPlane );
				break;

			default:
				print( 'THREE.FBXLoader: Unknown camera type ${type}.' );
				model = new Object3D();
				break;

		}

	}

	return model;

}