Best JavaScript code snippet using ng-mocks
renderer.js
Source:renderer.js
1/**2 * Copyright 2016 Google Inc. All Rights Reserved.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16import $ from 'jquery';17import R from 'ramda';18import THREE from 'three';19import * as CopyShader from '../../third_party/threejs_extra/CopyShader';20import * as EffectComposer from '../../third_party/threejs_extra/EffectComposer';21import * as MaskPass from '../../third_party/threejs_extra/MaskPass';22import * as RenderPass from '../../third_party/threejs_extra/RenderPass';23import * as ShaderPass from '../../third_party/threejs_extra/ShaderPass';24import * as SSAOShader from '../../third_party/threejs_extra/SSAOShader';25import * as FXAAShader from '../../third_party/threejs_extra/FXAAShader';26import * as HorizontalBlurShader from '../../third_party/threejs_extra/HorizontalBlurShader';27import * as VerticalBlurShader from '../../third_party/threejs_extra/VerticalBlurShader';28export default function ({ width, height, antialias } = {}) {29 const renderer = new THREE.WebGLRenderer({30 antialias: antialias,31 alpha: true32 });33 renderer.setPixelRatio(1.0);34 renderer.setSize(width, height);35 renderer.setClearColor(0xffffff, 0);36 renderer.gammaInput = true;37 renderer.gammaOutput = false;38 renderer.physicallyBasedShading = true;39 $(renderer.domElement).attr('id', 'maincanvas');40 const thumbnailRenderer = new THREE.WebGLRenderer({41 antialias: true,42 alpha: true43 });44 thumbnailRenderer.setClearColor(0xffffff, 0);45 thumbnailRenderer.setPixelRatio(1.0);46 thumbnailRenderer.setSize(0, 0);47 const $group = $('<div>');48 $group.append($(renderer.domElement));49 const $thumbnail = $(thumbnailRenderer.domElement);50 //$thumbnail.css({51 // position: 'absolute',52 // zIndex: 100,53 // left: '70%',54 // top: '50%'55 //})56 //.addClass('canvas-window-sm')57 //.attr('id','povcanvas')58 //.appendTo( $group );59 const camera = createDefaultCamera();60 let specificCamera;61 let swappingCameras = false;62 updateCameras();63 function updateCameras() {64 width = window.innerWidth;65 height = window.innerHeight;66 const bigAspect = width / height;67 const smallAspect = 320 / 240;68 if (swappingCameras === false) {69 camera.aspect = bigAspect;70 if (specificCamera) {71 specificCamera.aspect = smallAspect;72 }73 }74 else {75 camera.aspect = smallAspect;76 if (specificCamera) {77 specificCamera.aspect = bigAspect;78 }79 }80 camera.updateProjectionMatrix();81 if (specificCamera) {82 specificCamera.updateProjectionMatrix();83 }84 }85 $(window).resize(function () {86 const w = window.innerWidth;87 const h = window.innerHeight;88 renderer.setSize(w, h);89 if (resizePostProcessing) {90 resizePostProcessing(w, h);91 }92 updateCameras();93 });94 const scene = new THREE.Scene();95 const { renderPostProcessed, resizePostProcessing } = initPostprocessing(scene, camera, renderer, width, height);96 function setPOVHiddenObjectsVisibility(flag) {97 scene.traverse(function (o) {98 if (o.hiddenInPOV !== undefined) {99 o.visible = flag;100 }101 });102 }103 function setPOVOnlyObjectsVisibility(flag) {104 scene.traverse(function (o) {105 if (o.POVOnly !== undefined) {106 o.visible = flag;107 }108 });109 }110 const postProcessFlags = {111 ssao: false,112 glow: false113 };114 let rendering = false;115 const that = {};116 that.start = function () {117 rendering = true;118 };119 that.stop = function () {120 rendering = false;121 };122 that.getDomElement = function () {123 return $group[0];124 };125 that.getThumbnailElement = function () {126 return $thumbnail[0];127 };128 that.render = function () {129 if (!rendering) {130 return;131 }132 if (swappingCameras === false) {133 setPOVHiddenObjectsVisibility(true);134 setPOVOnlyObjectsVisibility(false);135 renderPostProcessed(scene, camera, postProcessFlags);136 setPOVHiddenObjectsVisibility(false);137 setPOVOnlyObjectsVisibility(true);138 if (specificCamera) {139 thumbnailRenderer.render(scene, specificCamera, undefined, true);140 }141 }142 else {143 setPOVHiddenObjectsVisibility(false);144 setPOVOnlyObjectsVisibility(true);145 if (specificCamera) {146 renderPostProcessed(scene, specificCamera, postProcessFlags);147 }148 setPOVHiddenObjectsVisibility(true);149 setPOVOnlyObjectsVisibility(false);150 thumbnailRenderer.render(scene, camera, undefined, true);151 }152 };153 that.getScene = function () {154 return scene;155 };156 that.update = function (ms) {157 scene.traverse(function traverseAndUpdate(o) {158 if (o.update) {159 o.update(ms);160 }161 });162 };163 that.getRenderer = () => renderer;164 that.getThumbnailRenderer = () => thumbnailRenderer;165 that.getDefaultCamera = () => camera;166 that.setSpecificCamera = function (overridingCamera) {167 specificCamera = overridingCamera;168 updateCameras();169 };170 that.swapSpecificCamera = function (flag) {171 swappingCameras = flag;172 updateCameras();173 };174 that.setRenderFlags = function (flags) {175 // unset all176 for (let i in postProcessFlags) {177 postProcessFlags[i] = false;178 }179 // set from config180 for (let i in flags) {181 postProcessFlags[i] = flags[i];182 }183 };184 return that;185}186export function createDefaultCamera() {187 const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1 + (window.devicePixelRatio - 1) * 30.0, 20000 - ( window.devicePixelRatio - 1 ) * 50);188 camera.reset = ()=>setDefaultCameraPosition(camera);189 window.camera = camera;190 return camera;191}192function setDefaultCameraPosition(camera) {193 camera.position.set(1, 1, 1);194 camera.position.normalize().multiplyScalar(1000);195}196function initPostprocessing(scene, camera, renderer, width, height) {197 // Setup render pass198 const renderPass = new THREE.RenderPass(scene, camera);199 // Setup depth pass200 const depthShader = THREE.ShaderLib['depthRGBA'];201 const depthUniforms = THREE.UniformsUtils.clone(depthShader.uniforms);202 const depthMaterial = new THREE.ShaderMaterial({203 fragmentShader: depthShader.fragmentShader, vertexShader: depthShader.vertexShader,204 uniforms: depthUniforms, blending: THREE.NoBlending205 });206 const pars = {minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter};207 const depthRenderTarget = new THREE.WebGLRenderTarget(width, height, pars);208 // Setup SSAO pass209 const ssaoPass = new THREE.ShaderPass(THREE.SSAOShader);210 //ssaoPass.uniforms[ "tDiffuse" ].value will be set by ShaderPass211 ssaoPass.uniforms['tDepth'].value = depthRenderTarget;212 ssaoPass.uniforms['size'].value.set(width / window.devicePixelRatio, height / window.devicePixelRatio);213 ssaoPass.uniforms['cameraNear'].value = 0.01 + (window.devicePixelRatio - 1) * 60.0;214 ssaoPass.uniforms['cameraFar'].value = 60 + -( window.devicePixelRatio - 1 ) * 50;215 ssaoPass.uniforms['onlyAO'].value = 0;216 ssaoPass.uniforms['aoClamp'].value = 0.1;217 ssaoPass.uniforms['lumInfluence'].value = 1.2;218 const fxaaPass = new THREE.ShaderPass(THREE.FXAAShader);219 fxaaPass.uniforms['resolution'].value.set(1 / width, 1 / height);220 fxaaPass.renderToScreen = true;221 window.ssao = ssaoPass.uniforms;222 // GLOW223 const glowRenderTarget = new THREE.WebGLRenderTarget(width, height, pars);224 const blurPasses = 2;225 const blurPassArray = [];226 for (let i = 0; i < blurPasses; i++) {227 let hblur = new THREE.ShaderPass(THREE.HorizontalBlurShader);228 let vblur = new THREE.ShaderPass(THREE.VerticalBlurShader);229 let bluriness = 1 + i;230 hblur.uniforms.h.value = bluriness / window.innerWidth;231 vblur.uniforms.v.value = bluriness / window.innerHeight;232 blurPassArray.push(hblur, vblur);233 // vblur.renderToScreen = true;234 }235 var effectCopy = new THREE.ShaderPass(THREE.CopyShader);236 // effectCopy.renderToScreen = true;237 const glowComposer = new THREE.EffectComposer(renderer);238 glowComposer.addPass(renderPass);239 blurPassArray.forEach(function (pass) {240 glowComposer.addPass(pass);241 });242 // glowComposer.addPass( effectCopy );243 // Add pass to effect composer244 const effectComposer = new THREE.EffectComposer(renderer);245 effectComposer.addPass(renderPass);246 effectComposer.addPass(ssaoPass);247 // additive pass248 const additivePass = createAdditivePass(effectComposer.renderTarget, glowComposer.renderTarget2);249 effectComposer.addPass(additivePass);250 effectComposer.addPass(fxaaPass);251 function flagsSet(flags) {252 return R.any(R.values(flags))253 }254 function onlyGlow(flag) {255 scene.traverse(function (o) {256 if (o.POVOnly !== undefined || o.hiddenInPOV !== undefined) {257 return;258 }259 const material = o.material;260 if (material && ( material.glow === undefined || material.glow === false )) {261 o.visible = flag;262 }263 ;264 })265 }266 function renderPostProcessed(scene, camera, flags) {267 const usePostProcessing = flagsSet(flags);268 if (usePostProcessing === false) {269 renderer.render(scene, camera);270 return;271 }272 ssaoPass.enabled = flags.ssao;273 additivePass.enabled = flags.glow;274 // ssaoPass.uniforms[ 'cameraNear' ].value = 0.02;275 // ssaoPass.uniforms[ 'cameraFar' ].value = 40;276 if (flags.glow) {277 onlyGlow(false);278 glowComposer.render();279 onlyGlow(true);280 }281 scene.traverse(function (o) {282 if (o.POVOnly !== undefined || o.hiddenInPOV !== undefined) {283 return;284 }285 const material = o.material;286 if (material && material.ssao !== undefined && material.ssao === false) {287 o.visible = false;288 }289 ;290 });291 renderPass.camera = camera;292 scene.overrideMaterial = depthMaterial;293 renderer.render(scene, camera, depthRenderTarget, true);294 scene.overrideMaterial = null;295 scene.traverse(function (o) {296 if (o.POVOnly !== undefined || o.hiddenInPOV !== undefined) {297 return;298 }299 const material = o.material;300 if (material && o.material.ssao !== undefined && material.ssao === false) {301 o.visible = true;302 }303 ;304 });305 effectComposer.render();306 }307 function resizePostProcessing(width, height) {308 effectComposer.reset();309 // glowComposer.reset();310 depthRenderTarget.setSize(width, height);311 glowRenderTarget.setSize(width, height);312 ssaoPass.uniforms['size'].value.set(width / window.devicePixelRatio, height / window.devicePixelRatio);313 fxaaPass.uniforms['resolution'].value.set(1 / width, 1 / height);314 }315 return {316 renderPostProcessed,317 resizePostProcessing318 };319}320function createAdditiveBlendShader() {321 return {322 uniforms: {323 tDiffuse: {type: 't', value: undefined}, // The base scene buffer324 tGlow: {type: 't', value: undefined}, // The glow scene buffer325 tEmissive: {type: 't', value: undefined}326 },327 vertexShader: [328 'varying vec2 vUv;',329 'void main() {',330 'vUv = vec2( uv.x, uv.y );',331 'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',332 '}'333 ].join('\n'),334 fragmentShader: [335 'uniform sampler2D tDiffuse;',336 'uniform sampler2D tGlow;',337 'uniform sampler2D tEmissive;',338 'varying vec2 vUv;',339 'void main() {',340 'vec4 texel = texture2D( tDiffuse, vUv );',341 'vec4 glow = texture2D( tGlow, vUv );',342 'vec4 emissive = texture2D( tEmissive, vUv );',343 'gl_FragColor = texel + emissive + vec4(0.7, 0.7, 0.7, 1.0) * glow * 2.0;',344 '}'345 ].join('\n')346 };347};348function createAdditivePass(a, b) {349 const additiveBlendShader = createAdditiveBlendShader();350 additiveBlendShader.uniforms.tGlow.value = b;351 additiveBlendShader.uniforms.tEmissive.value = a;352 var additivePass = new THREE.ShaderPass(additiveBlendShader);353 additivePass.needsSwap = true;354 additivePass.renderToScreen = false;355 return additivePass;...
variables_d.js
Source:variables_d.js
1var searchData=2[3 ['path',['path',['../structTexture.html#a0829bef4e9cd4d34fbcd08a436ed68c7',1,'Texture']]],4 ['pdeltatime',['pdeltaTime',['../simplepbr2_8cpp.html#a60ad9051b2a0b3b601329efb707c3099',1,'simplepbr2.cpp']]],5 ['pitch',['pitch',['../classCamera.html#ab56fcb39f580e8d2159cf2c9c6d9a65a',1,'Camera::pitch()'],['../camera_8hpp.html#ab32939bf039c742431f67a815575ed21',1,'PITCH(): camera.hpp']]],6 ['plasttime',['plastTime',['../simplepbr2_8cpp.html#acfc1ca7a9e33346c9ab7b0ae63f0b035',1,'simplepbr2.cpp']]],7 ['plypath',['plyPath',['../singulars_8hpp.html#a8ef499e384a1f38265f5aa6afb36252e',1,'singulars.hpp']]],8 ['pos',['pos',['../classCamera.html#ae54915cea5c8741a9cc38b8f9b6849ff',1,'Camera::pos()'],['../structVertex.html#a858242dc7b40c034c5e13c589b30cfb4',1,'Vertex::pos()']]],9 ['position',['position',['../classPointLight.html#a6dc6e70f9a91e8a6bbecf08707143cad',1,'PointLight']]],10 ['postprocessflags',['postProcessFlags',['../classModel.html#ad047d0946d1334a20a69ffb80b7928bd',1,'Model']]],11 ['programid',['programId',['../classShader.html#a76da81e0222f4e5115f1b67e5ee5cca4',1,'Shader']]]...
Using AI Code Generation
1const postProcessFlags = require('ng-mocks').postProcessFlags;2postProcessFlags();3const postProcessFlags = require('ng-mocks').postProcessFlags;4postProcessFlags();5const postProcessFlags = require('ng-mocks').postProcessFlags;6postProcessFlags();7const postProcessFlags = require('ng-mocks').postProcessFlags;8postProcessFlags();9const postProcessFlags = require('ng-mocks').postProcessFlags;10postProcessFlags();11const postProcessFlags = require('ng-mocks').postProcessFlags;12postProcessFlags();13const postProcessFlags = require('ng-mocks').postProcessFlags;14postProcessFlags();15const postProcessFlags = require('ng-mocks').postProcessFlags;16postProcessFlags();17const postProcessFlags = require('ng-mocks').postProcessFlags;18postProcessFlags();19const postProcessFlags = require('ng-mocks').postProcessFlags;20postProcessFlags();21const postProcessFlags = require('ng-mocks').postProcessFlags;22postProcessFlags();23const postProcessFlags = require('ng-mocks').postProcessFlags;24postProcessFlags();25const postProcessFlags = require('ng-mocks').postProcessFlags;26postProcessFlags();
Using AI Code Generation
1import { postProcessFlags } from '@angular/compiler-cli';2import { CompilerOptions } from '@angular/compiler-cli/src/transformers/api';3import { CompilerHost, CompilerOptions as NgCompilerOptions, createCompilerHost } from '@angular/compiler-cli/src/transformers/compiler_host';4import { readConfiguration } from '@angular/compiler-cli/src/perform_compile';5import { getSystemPath, normalize, virtualFs } from '@angular-devkit/core';6import { NodeJsSyncHost } from '@angular-devkit/core/node';7import { createProgram } from 'typescript';8const tsConfigPath = normalize('/path/to/tsconfig.json');9const basePath = tsConfigPath;10const host = new NodeJsSyncHost();11const config = readConfiguration(tsConfigPath, host);12const options: NgCompilerOptions = config.options;13const rootNames = config.rootNames;14const tsConfigDir = normalize(getSystemPath(basePath));15const compilerHost = createCompilerHost({ options, tsHost: host });16const program = createProgram({ rootNames, options, host: compilerHost });17const ngHost = new CompilerHost(program, options, compilerHost);18const { options: finalOptions } = postProcessFlags(options);19const { rootNames: finalRootNames } = postProcessFlags({ rootNames }, finalOptions);20import { readConfiguration } from '@angular/compiler-cli';21import { CompilerOptions } from '@angular/compiler-cli/src/transformers/api';22import { CompilerHost, CompilerOptions as NgCompilerOptions, createCompilerHost } from '@angular/compiler-cli/src/transformers/compiler_host';23import { readConfiguration } from '@angular/compiler-cli/src/perform_compile';24import { getSystemPath, normalize, virtualFs } from '@angular-devkit/core';25import { NodeJsSyncHost } from '@angular-devkit/core/node';26import { createProgram } from 'typescript';27const tsConfigPath = normalize('/path/to/tsconfig.json');28const basePath = tsConfigPath;29const host = new NodeJsSyncHost();30const config = readConfiguration(tsConfigPath, host);31const options: NgCompilerOptions = config.options;32const rootNames = config.rootNames;33const tsConfigDir = normalize(getSystemPath(basePath));34const compilerHost = createCompilerHost({ options, tsHost: host });35const program = createProgram({ rootNames, options, host: compilerHost });
Using AI Code Generation
1import { postProcessFlags } from 'ng-mocks';2describe('test', () => {3 it('test', () => {4 postProcessFlags({5 });6 });7});8import { postProcessFlags } from 'ng-mocks';9describe('test', () => {10 it('test', () => {11 postProcessFlags({12 });13 });14});
Using AI Code Generation
1import {2} from 'ng-mocks';3import { AppComponent } from './app.component';4import { AppModule } from './app.module';5import { HeaderComponent } from './components/header/header.component';6import { FooterComponent } from './components/footer/footer.component';7import { RouterTestingModule } from '@angular/router/testing';8import { HttpClientTestingModule } from '@angular/common/http/testing';9import { of } from 'rxjs';10import { AuthService } from './services/auth.service';11describe('AppComponent', () => {12 postProcessFlags({13 });14 beforeEach(() => {15 MockProvider(AuthService, {16 isAuthenticated: () => of(true),17 });18 MockComponent(HeaderComponent);19 MockComponent(FooterComponent);20 MockRender(
Using AI Code Generation
1import { postProcessFlags } from 'ng-mocks';2const flags = postProcessFlags({3});4import { postProcessFlags } from 'ng-mocks';5const flags = postProcessFlags({6});7import { postProcessFlags } from 'ng-mocks';8const flags = postProcessFlags({9});10import { postProcessFlags } from 'ng-mocks';11const flags = postProcessFlags({12});13import { postProcessFlags } from 'ng-mocks';14const flags = postProcessFlags({15});16import { postProcessFlags } from 'ng-mocks';17const flags = postProcessFlags({18});19import { postProcessFlags } from 'ng-mocks';20const flags = postProcessFlags({21});22import { postProcessFlags } from 'ng-mocks';23const flags = postProcessFlags({24});25import { postProcessFlags } from 'ng-mocks';26const flags = postProcessFlags({27});28import { postProcessFlags } from 'ng-mocks';
Using AI Code Generation
1import { postProcessFlags } from 'ng-mocks';2postProcessFlags({3});4import { TestBed } from '@angular/core/testing';5import { MockProvider } from 'ng-mocks';6TestBed.overrideProvider(7 MockProvider(MyService),8);9import { TestBed } from '@angular/core/testing';10import { MockProvider } from 'ng-mocks';11TestBed.overrideProvider(12 MockProvider(MyService, {13 myMethod: () => 'mocked value',14 }),15);16import { TestBed } from '@angular/core/testing';17import { MockProvider } from 'ng-mocks';18TestBed.overrideProvider(19 MockProvider(MyService, {20 myMethod: () => 'mocked value',21 myMethod2: () => 'mocked value',22 }),23);24import { TestBed } from '@angular/core/testing';25import { MockProvider } from 'ng-mocks';26TestBed.overrideProvider(27 MockProvider(MyService, {28 myMethod: () => 'mocked value',29 myMethod2: () => 'mocked value',30 }),31);32import { TestBed } from '@angular/core/testing';33import { MockProvider } from 'ng-mocks';
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!