mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 16:52:43 +08:00
texture cube from texture2d (#3624)
* texture cube from texture2d * fix format
This commit is contained in:
@@ -29,6 +29,7 @@ import { ccclass, property } from '../../core/data/class-decorator';
|
||||
import ImageAsset from '../../assets/image-asset';
|
||||
|
||||
/**
|
||||
* @typedef {import("../../assets/CCTexture2D")} Texture2D
|
||||
* @typedef {import("../../assets/texture-base").ImageSource} ImageSource
|
||||
* @typedef {import("../../assets/texture-base").TextureUpdateOpts} TextureUpdateOpts
|
||||
* @typedef {import("../../assets/texture-base").HTMLImageSource} HTMLImageSource
|
||||
@@ -39,14 +40,14 @@ import ImageAsset from '../../assets/image-asset';
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
const FaceIndex = {
|
||||
front: 5,
|
||||
back: 4,
|
||||
left: 1,
|
||||
const FaceIndex = cc.Enum({
|
||||
right: 0,
|
||||
left: 1,
|
||||
top: 2,
|
||||
bottom: 3,
|
||||
};
|
||||
back: 4,
|
||||
front: 5
|
||||
});
|
||||
|
||||
@ccclass('cc.TextureCube')
|
||||
export default class TextureCube extends TextureBase {
|
||||
@@ -58,7 +59,7 @@ export default class TextureCube extends TextureBase {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
|
||||
/**
|
||||
* @type {GFXTextureCube}
|
||||
*/
|
||||
@@ -138,7 +139,7 @@ export default class TextureCube extends TextureBase {
|
||||
/**
|
||||
* Sets the _mipmaps to specified value, and updates the width and height accordingly.
|
||||
* If available, synchronize the mipmap data to underlying texture.
|
||||
* @param {Mipmap[]} mipmaps
|
||||
* @param {Mipmap[]} mipmaps
|
||||
*/
|
||||
_setMipmaps(mipmaps) {
|
||||
this._mipmaps = mipmaps;
|
||||
@@ -159,11 +160,11 @@ export default class TextureCube extends TextureBase {
|
||||
const inc = () => {
|
||||
++counter;
|
||||
if (counter === this._mipmaps.length * 6) {
|
||||
this._updateMipmaps(this._mipmaps.map(mipmap => TextureCube._getMipmapSource(mipmap)));
|
||||
this._updateMipmaps(this._mipmaps.map(mipmap => TextureCube._toMipmapArray(mipmap)));
|
||||
}
|
||||
};
|
||||
mipmaps.forEach(mipmap => {
|
||||
TextureCube._foreachFace(mipmap, face => {
|
||||
TextureCube._forEachFace(mipmap, face => {
|
||||
if (face.loaded) {
|
||||
inc();
|
||||
} else {
|
||||
@@ -177,7 +178,7 @@ export default class TextureCube extends TextureBase {
|
||||
|
||||
/**
|
||||
* Updates mipmaps of the underlying texture.
|
||||
* @param {ImageSource[][]} mipmapSources
|
||||
* @param {ImageSource[][]} mipmapSources
|
||||
*/
|
||||
_updateMipmaps(mipmapSources) {
|
||||
const opts = this._getOpts();
|
||||
@@ -190,11 +191,10 @@ export default class TextureCube extends TextureBase {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Mipmap} mipmap
|
||||
* @param {Mipmap} mipmap
|
||||
* @return {ImageSource[]}
|
||||
*/
|
||||
static _getMipmapSource(mipmap) {
|
||||
static _toMipmapArray(mipmap) {
|
||||
/** @type {ImageSource[]} */
|
||||
const result = new Array();
|
||||
result[FaceIndex.front] = mipmap.front.data;
|
||||
@@ -210,11 +210,27 @@ export default class TextureCube extends TextureBase {
|
||||
* @param {Mipmap} mipmap
|
||||
* @param {(face: ImageAsset) => void} callback
|
||||
*/
|
||||
static _foreachFace(mipmap, callback) {
|
||||
static _forEachFace(mipmap, callback) {
|
||||
for (let face in mipmap) {
|
||||
callback(mipmap[face]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Texture2D[]} textures
|
||||
*/
|
||||
static fromTexture2DArray(textures) {
|
||||
let res = [], mips = textures.length / 6;
|
||||
for (let i = 0; i < mips; i++) {
|
||||
res.push(textures.splice(0, 6).reduce((acc, img, i) => {
|
||||
acc[FaceIndex[i]] = img.image;
|
||||
return acc;
|
||||
}, {}));
|
||||
}
|
||||
let cube = new TextureCube();
|
||||
cube.mipmaps = res;
|
||||
return cube;
|
||||
}
|
||||
}
|
||||
|
||||
cc.TextureCube = TextureCube;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
import ValueType from './value-type';
|
||||
import CCClass from '../data/class';
|
||||
import quat from '../vmath/quat';
|
||||
|
||||
/**
|
||||
* !#en Representation of 2D vectors and points.
|
||||
@@ -109,32 +110,9 @@ export default class Quat extends ValueType {
|
||||
return other && this.x === other.x && this.y === other.y && this.z === other.z && this.w === other.w;
|
||||
}
|
||||
|
||||
getRoll () {
|
||||
var sinr = 2.0 * (this.w * this.x + this.y * this.z);
|
||||
var cosr = 1.0 - 2.0 * (this.x * this.x + this.y * this.y);
|
||||
return 180 * Math.atan2(sinr, cosr) / Math.PI;
|
||||
}
|
||||
|
||||
getPitch () {
|
||||
var sinp = 2.0 * (this.w * this.y - this.z * this.x);
|
||||
var pitch = sinp > 1 ? 1 : sinp;
|
||||
pitch = sinp < -1 ? -1 : sinp;
|
||||
pitch = 180 * Math.asin(pitch) / Math.PI;
|
||||
return pitch;
|
||||
}
|
||||
|
||||
getYaw () {
|
||||
var siny = 2.0 * (this.w * this.z + this.x * this.y);
|
||||
var cosy = 1.0 - 2.0 * (this.y * this.y + this.z * this.z);
|
||||
return 180 * Math.atan2(siny, cosy) / Math.PI;
|
||||
}
|
||||
|
||||
getEulerAngles (out) {
|
||||
out = out || cc.v3();
|
||||
out.x = this.getRoll();
|
||||
out.y = this.getPitch();
|
||||
out.z = this.getYaw();
|
||||
return out;
|
||||
return quat.toEuler(out, this);
|
||||
}
|
||||
|
||||
lerp (to, ratio, out) {
|
||||
@@ -160,8 +138,8 @@ CCClass.fastDefine('cc.Quat', Quat, { x: 0, y: 0, z: 0, w: 1 });
|
||||
* @param {Number} [w=1]
|
||||
* @return {Quat}
|
||||
*/
|
||||
cc.quat = function quat (x, y, z, w) {
|
||||
cc.quat = function(x, y, z, w) {
|
||||
return new Quat(x, y, z, w);
|
||||
};
|
||||
|
||||
cc.Quat = Quat;
|
||||
cc.Quat = Quat;
|
||||
|
||||
@@ -251,13 +251,13 @@ export default class ForwardRenderer extends BaseRenderer {
|
||||
_drawSkinning(item) {
|
||||
let { model, defines } = item;
|
||||
|
||||
defines.USE_SKINNING = true;
|
||||
defines['USE_SKINNING'] = true;
|
||||
if (model._jointsTexture != null) {
|
||||
defines.USE_JOINTS_TEXTURE = true;
|
||||
defines['USE_JOINTS_TEXTURE'] = true;
|
||||
this._device.setTexture('_u_jointsTexture', model._jointsTexture, this._allocTextureUnit());
|
||||
this._device.setUniform('_u_jointsTextureSize', model._jointsTexture._width);
|
||||
} else if (model._jointsMatrixArray != null) {
|
||||
defines.USE_JOINTS_TEXTURE = false;
|
||||
defines['USE_JOINTS_TEXTURE'] = false;
|
||||
this._device.setUniform("_u_jointMatrices", model._jointsMatrixArray);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user