Skip to content

Commit

Permalink
WebGLRenderer constructor params #117
Browse files Browse the repository at this point in the history
  • Loading branch information
klevron committed Jan 24, 2022
1 parent da6396c commit bb63587
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/core/Renderer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-use-before-define */
import { Camera, Scene, WebGLRenderer } from 'three'
import { Camera, Scene, WebGLRenderer, WebGLRendererParameters } from 'three'
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer'
import { ComponentPublicInstance, defineComponent, InjectionKey, PropType } from 'vue'
import { bindObjectProp } from '../tools'
Expand Down Expand Up @@ -98,6 +98,7 @@ export const RendererInjectionKey: InjectionKey<RendererPublicInterface> = Symbo
export default defineComponent({
name: 'Renderer',
props: {
params: { type: Object as PropType<WebGLRendererParameters>, default: () => ({}) },
antialias: Boolean,
alpha: Boolean,
autoClear: { type: Boolean, default: true },
Expand Down Expand Up @@ -131,6 +132,7 @@ export default defineComponent({

const config: ThreeConfigInterface = {
canvas,
params: props.params,
antialias: props.antialias,
alpha: props.alpha,
autoClear: props.autoClear,
Expand Down
5 changes: 3 additions & 2 deletions src/core/useThree.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Camera, Object3D, OrthographicCamera, PerspectiveCamera, Scene, WebGLRenderer } from 'three'
import { Camera, Object3D, OrthographicCamera, PerspectiveCamera, Scene, WebGLRenderer, WebGLRendererParameters } from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js'
import usePointer, { PointerConfigInterface, PointerPublicConfigInterface, PointerInterface } from './usePointer'
Expand All @@ -12,6 +12,7 @@ export interface SizeInterface {
}

export interface ThreeConfigInterface {
params?: WebGLRendererParameters
canvas?: HTMLCanvasElement
antialias: boolean
alpha: boolean
Expand Down Expand Up @@ -97,7 +98,7 @@ export default function useThree(params: ThreeConfigInterface): ThreeInterface {
* create WebGLRenderer
*/
function createRenderer(): WebGLRenderer {
const renderer = new WebGLRenderer({ canvas: config.canvas, antialias: config.antialias, alpha: config.alpha })
const renderer = new WebGLRenderer({ canvas: config.canvas, antialias: config.antialias, alpha: config.alpha, ...config.params })
renderer.autoClear = config.autoClear
return renderer
}
Expand Down

0 comments on commit bb63587

Please sign in to comment.