美文网首页
Three.js光源梳理1——光照基类(Light)

Three.js光源梳理1——光照基类(Light)

作者: ShawnWeasley | 来源:发表于2022-02-08 14:16 被阅读0次

Three.js光源系统基本上与Unity没有太大差别,下图是当前Three.js版本提供的全部光源,本系列梳理一下各种光源类型和使用方法。


当前Three.js版本提供的全部光源

所有的光源均基于光照基类Light,而Light本身作为其他光源的父类,不能被直接调用。

Light类构造:
color(颜色)
intensity(强度)

Light类属性:
color(颜色)
intensity(强度)

Light类方法:
copy(复制color和intensity)
toJson(将光照信息转为json格式)

Light.js如下,继承于Object3D,仅实现了上述的属性和方法和标记Light.prototype.isLight为true;:

import { Object3D } from '../core/Object3D.js';
import { Color } from '../math/Color.js';

class Light extends Object3D {

    constructor( color, intensity = 1 ) {

        super();

        this.type = 'Light';

        this.color = new Color( color );
        this.intensity = intensity;

    }

    dispose() {

        // Empty here in base class; some subclasses override.

    }

    copy( source ) {

        super.copy( source );

        this.color.copy( source.color );
        this.intensity = source.intensity;

        return this;

    }

    toJSON( meta ) {

        const data = super.toJSON( meta );

        data.object.color = this.color.getHex();
        data.object.intensity = this.intensity;

        if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();

        if ( this.distance !== undefined ) data.object.distance = this.distance;
        if ( this.angle !== undefined ) data.object.angle = this.angle;
        if ( this.decay !== undefined ) data.object.decay = this.decay;
        if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;

        if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();

        return data;

    }

}

Light.prototype.isLight = true;

export { Light };

源码的内容很简单,但并不重要,会用就行了,这里把源码放在这里便于大家理解。

相关文章

  • Three.js光源梳理1——光照基类(Light)

    Three.js光源系统基本上与Unity没有太大差别,下图是当前Three.js版本提供的全部光源,本系列梳理一...

  • 光照及渲染

    光照 光源类型 光源类型可分为:Realtime,Mixed,Baked Realtime light - 实时光...

  • 基础篇-光照

    Light(光照) 在真实场景中,一般存在两种类型的光照效果:直接光源和间接光源。 直接光源:顾名思义,就是光直接...

  • Three.js 核心 五步

    1.设置three.js渲染器 2.设置摄像机camera 3.设置场景scene 4.设置光源light 5.设...

  • THREE.JS中的光源

    Three.js中有很多各式各样的光源,不同的光源可以产生不同的光照效果。这篇文章主要介绍他们的区别,以及各自的应...

  • webgl 22.为正方体添加光照

    下面来看一下光照先来看一下光源的类型 光源大体可分为 Directional light (平行光),Point ...

  • 灯光与刚体

    一、光照系统 Unity中提供了四种光源:Directional light: 方向光,类似太阳的日照效果。Poi...

  • 写在前面——光照与材质

    一、四大光照类型1.环境光(Ambient Light) 一个物体即使没有直接被光源照射,但是只要有光线通过其他物...

  • Unity3d灯光与渲染

    Unity灯光分类 ①Directional Light 平行光 用于:太阳光 ②Point Light 点光源...

  • 阴影映射/贴图Shadow Mapping

    又叫光照贴图Light Mapping在三维计算机图形中加入阴影的过程。特点:体积大,不减少帧速率。 从光源的位置...

网友评论

      本文标题:Three.js光源梳理1——光照基类(Light)

      本文链接:https://www.haomeiwen.com/subject/xtjbkrtx.html