mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 08:42:43 +08:00
@@ -180,7 +180,7 @@ export default class LightComponent extends Component {
|
||||
} else if (this._type === LightType.Spot) {
|
||||
type = renderer.LIGHT_SPOT;
|
||||
}
|
||||
if (this.enabled)
|
||||
if (this._light)
|
||||
this._light.setType(type);
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ export default class LightComponent extends Component {
|
||||
|
||||
set color(val) {
|
||||
this._color = val;
|
||||
if (this.enabled)
|
||||
if (this._light)
|
||||
this._light.setColor(val.r / 255, val.g / 255, val.b / 255);
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ export default class LightComponent extends Component {
|
||||
|
||||
set intensity(val) {
|
||||
this._intensity = val;
|
||||
if (this.enabled)
|
||||
if (this._light)
|
||||
this._light.setIntensity(val);
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ export default class LightComponent extends Component {
|
||||
|
||||
set range(val) {
|
||||
this._range = val;
|
||||
if (this.enabled)
|
||||
if (this._light)
|
||||
this._light.setRange(val);
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ export default class LightComponent extends Component {
|
||||
|
||||
set spotAngle(val) {
|
||||
this._spotAngle = val;
|
||||
if (this.enabled)
|
||||
if (this._light)
|
||||
this._light.setSpotAngle(toRadian(val));
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ export default class LightComponent extends Component {
|
||||
|
||||
set spotExp(val) {
|
||||
this._spotExp = val;
|
||||
if (this.enabled)
|
||||
if (this._light)
|
||||
this._light.setSpotExp(val);
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ export default class LightComponent extends Component {
|
||||
} else if (val === LightShadowType.Soft) {
|
||||
type = renderer.SHADOW_SOFT;
|
||||
}
|
||||
if (this.enabled)
|
||||
if (this._light)
|
||||
this._light.setShadowType(type);
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ export default class LightComponent extends Component {
|
||||
|
||||
set shadowResolution(val) {
|
||||
this._shadowResolution = val;
|
||||
if (this.enabled)
|
||||
if (this._light)
|
||||
this._light.setShadowResolution(val);
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ export default class LightComponent extends Component {
|
||||
|
||||
set shadowDarkness(val) {
|
||||
this._shadowDarkness = val;
|
||||
if (this.enabled)
|
||||
if (this._light)
|
||||
this._light.setShadowDarkness(val);
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ export default class LightComponent extends Component {
|
||||
|
||||
set shadowMinDepth(val) {
|
||||
this._shadowMinDepth = val;
|
||||
if (this.enabled)
|
||||
if (this._light)
|
||||
this._light.setShadowMinDepth(val);
|
||||
}
|
||||
|
||||
@@ -363,7 +363,7 @@ export default class LightComponent extends Component {
|
||||
|
||||
set shadowMaxDepth(val) {
|
||||
this._shadowMaxDepth = val;
|
||||
if (this.enabled)
|
||||
if (this._light)
|
||||
this._light.setShadowMaxDepth(val);
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ export default class LightComponent extends Component {
|
||||
|
||||
set shadowDepthScale(val) {
|
||||
this._shadowDepthScale = val;
|
||||
if (this.enabled)
|
||||
if (this._light)
|
||||
this._light.setShadowDepthScale(val);
|
||||
}
|
||||
|
||||
@@ -399,7 +399,7 @@ export default class LightComponent extends Component {
|
||||
|
||||
set shadowFrustumSize(val) {
|
||||
this._shadowFrustumSize = val;
|
||||
if (this.enabled)
|
||||
if (this._light)
|
||||
this._light.setShadowFrustumSize(val);
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ export default class LightComponent extends Component {
|
||||
|
||||
set shadowBias(val) {
|
||||
this._shadowBias = val;
|
||||
if (this.enabled)
|
||||
if (this._light)
|
||||
this._light.setShadowBias(val);
|
||||
}
|
||||
|
||||
@@ -434,8 +434,8 @@ export default class LightComponent extends Component {
|
||||
}
|
||||
|
||||
onEnable() {
|
||||
this._light = this._getRenderScene().createLight(this.name);
|
||||
this._light.setNode(this.node);
|
||||
// this._light = this._getRenderScene().createLight(this.name);
|
||||
// this._light.setNode(this.node);
|
||||
this.type = this._type;
|
||||
this.color = this._color;
|
||||
this.intensity = this._intensity;
|
||||
@@ -452,7 +452,7 @@ export default class LightComponent extends Component {
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
this._getRenderScene().destroyLight(this._light);
|
||||
// this._getRenderScene().destroyLight(this._light);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
|
||||
+13
-18
@@ -5,7 +5,7 @@ import { Filter, PixelFormat, WrapMode } from '../../assets/texture-base';
|
||||
import { Vec3 } from '../../core/value-types';
|
||||
import { AttributeBaseType, AttributeType,
|
||||
IMeshStruct, IndexUnit, IPrimitive, IVertexAttribute, IVertexBundle, Mesh } from '../assets/mesh';
|
||||
import { IGeometry } from '../primitive/defines';
|
||||
import { IGeometry } from '../primitive/define';
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -104,6 +104,16 @@ export function createMesh (geometry: IGeometry) {
|
||||
primitiveMode: geometry.primitiveMode || GFXPrimitiveMode.TRIANGLE_LIST,
|
||||
vertexBundelIndices: [0],
|
||||
};
|
||||
// geometric info for raycasting
|
||||
if (primitive.primitiveMode >= GFXPrimitiveMode.TRIANGLE_LIST) {
|
||||
const geomInfo = Float32Array.from(geometry.positions);
|
||||
primitive.geometricInfo = {
|
||||
doubleSided: geometry.doubleSided,
|
||||
range: { offset: bufferBlob.getLength(), length: geomInfo.byteLength },
|
||||
};
|
||||
bufferBlob.addBuffer(geomInfo.buffer);
|
||||
}
|
||||
|
||||
if (indexBuffer) {
|
||||
primitive.indices = {
|
||||
indexUnit: targetIndexUnit,
|
||||
@@ -115,16 +125,6 @@ export function createMesh (geometry: IGeometry) {
|
||||
bufferBlob.addBuffer(indexBuffer);
|
||||
}
|
||||
|
||||
// geometric info for raycasting
|
||||
if (primitive.primitiveMode >= GFXPrimitiveMode.TRIANGLE_LIST) {
|
||||
const geomInfo = Float32Array.from(geometry.positions);
|
||||
primitive.geometricInfo = {
|
||||
doubleSided: geometry.doubleSided,
|
||||
range: { offset: bufferBlob.getLength(), length: geomInfo.byteLength },
|
||||
};
|
||||
bufferBlob.addBuffer(geomInfo.buffer);
|
||||
}
|
||||
|
||||
// Create mesh struct.
|
||||
const meshStruct: IMeshStruct = {
|
||||
vertexBundles: [vertexBundle],
|
||||
@@ -244,6 +244,8 @@ function _getComponentCount (vertexAttribute: IVertexAttribute) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const isLittleEndian = cc.sys.isLittleEndian;
|
||||
|
||||
function _getVerticesWriter (dataView: DataView, baseType: AttributeBaseType) {
|
||||
switch (baseType) {
|
||||
case AttributeBaseType.INT8:
|
||||
@@ -275,10 +277,3 @@ function _getIndicesWriter (dataView: DataView, indexUnit: IndexUnit) {
|
||||
}
|
||||
return (offset: number, value: number) => dataView.setUint8(offset, value);
|
||||
}
|
||||
|
||||
const isLittleEndian = (() => {
|
||||
const buffer = new ArrayBuffer(2);
|
||||
new DataView(buffer).setInt16(0, 256, true);
|
||||
// Int16Array uses the platform's endianness.
|
||||
return new Int16Array(buffer)[0] === 256;
|
||||
})();
|
||||
|
||||
@@ -527,6 +527,17 @@ sys.isNative = CC_JSB;
|
||||
*/
|
||||
sys.isBrowser = typeof window === 'object' && typeof document === 'object' && !CC_WECHATGAME && !CC_QQPLAY && !CC_JSB;
|
||||
|
||||
/**
|
||||
* Endianess of current platform
|
||||
* @property {boolean} isLittleEndian
|
||||
*/
|
||||
sys.isLittleEndian = (() => {
|
||||
const buffer = new ArrayBuffer(2);
|
||||
new DataView(buffer).setInt16(0, 256, true);
|
||||
// Int16Array uses the platform's endianness.
|
||||
return new Int16Array(buffer)[0] === 256;
|
||||
})();
|
||||
|
||||
if (CC_EDITOR && Editor.isMainProcess) {
|
||||
sys.isMobile = false;
|
||||
sys.platform = sys.EDITOR_CORE;
|
||||
@@ -1210,4 +1221,4 @@ sys.now = function () {
|
||||
|
||||
cc.sys = sys;
|
||||
|
||||
export default sys;
|
||||
export default sys;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { GFXBuffer, IGFXDrawInfo } from './buffer';
|
||||
import { GFXFormat, GFXObject, GFXObjectType } from './define';
|
||||
import { GFXFormat, GFXFormatInfos, GFXObject, GFXObjectType } from './define';
|
||||
import { GFXDevice } from './device';
|
||||
|
||||
export interface IGFXInputAttribute {
|
||||
@@ -18,6 +18,8 @@ export interface IGFXInputAssemblerInfo {
|
||||
indirectBuffer?: GFXBuffer;
|
||||
}
|
||||
|
||||
const isLittleEndian = cc.sys.isLittleEndian;
|
||||
|
||||
export abstract class GFXInputAssembler extends GFXObject {
|
||||
|
||||
public get vertexBuffers (): GFXBuffer[] {
|
||||
@@ -135,4 +137,32 @@ export abstract class GFXInputAssembler extends GFXObject {
|
||||
drawInfo.instanceCount = this._instanceCount;
|
||||
drawInfo.firstInstance = this._firstInstance;
|
||||
}
|
||||
|
||||
public updateVertexAttr (attr: string, data: number[]) {
|
||||
let offset = 0;
|
||||
let count = 0;
|
||||
let size = 0;
|
||||
let fn = '';
|
||||
for (const a of this._attributes) {
|
||||
const info = GFXFormatInfos[a.format];
|
||||
if (a.name === attr) {
|
||||
count = info.count;
|
||||
size = info.size / count;
|
||||
fn = `set${info.isFloating ? 'Float' : 'Int'}${size * 8}`;
|
||||
break;
|
||||
}
|
||||
offset += info.size;
|
||||
}
|
||||
const vb = this._vertexBuffers[0];
|
||||
if (!count || !vb || !vb.buffer) { return; }
|
||||
const stride = vb.stride;
|
||||
const view = new DataView(vb.buffer as ArrayBuffer);
|
||||
const len = data.length;
|
||||
for (let idx = 0, beg = offset; idx < len; idx += count, beg += stride) {
|
||||
for (let j = 0; j < count; j++) {
|
||||
view[fn](beg + j * size, data[idx + j], isLittleEndian);
|
||||
}
|
||||
}
|
||||
vb.update(vb.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ export class Model {
|
||||
* @param {vec3} minPos the min position of the model
|
||||
* @param {vec3} maxPos the max position of the model
|
||||
*/
|
||||
public createBoundingShape (minPos: Vec3, maxPos: Vec3) {
|
||||
public createBoundingShape (minPos?: Vec3, maxPos?: Vec3) {
|
||||
if (!minPos || !maxPos) { return; }
|
||||
this._modelBounds = aabb.fromPoints(aabb.create(), minPos, maxPos);
|
||||
this._worldBounds = aabb.clone(this._modelBounds);
|
||||
|
||||
+16
-6
@@ -41,11 +41,6 @@
|
||||
cc.director.root.resize(bcr.width, bcr.height);
|
||||
});
|
||||
|
||||
// window.addEventListener('resize', () => {
|
||||
// const bcr = $body.getBoundingClientRect();
|
||||
// cc.view.setCanvasSize(bcr.width, bcr.height);
|
||||
// });
|
||||
|
||||
function createTexture(imgElms) {
|
||||
const textureAsset = new cc.Texture2D();
|
||||
textureAsset.image = new cc.ImageAsset(imgElms[0]);
|
||||
@@ -69,7 +64,6 @@
|
||||
material.setDefines({ USE_COLOR: true });
|
||||
// parsed effect file is embedded in cocos/3d/builtin/effects.js
|
||||
material.effectName = 'builtin-effect-unlit';
|
||||
material.setProperty('mainTexture', texture);
|
||||
|
||||
const len = 50;
|
||||
const models = [], passes = [];
|
||||
@@ -86,6 +80,22 @@
|
||||
}
|
||||
const handle = passes[0].getHandle('color');
|
||||
|
||||
{
|
||||
const material = new cc.Material();
|
||||
material.effectName = 'builtin-effect-sprite';
|
||||
material.setProperty('mainTexture', texture);
|
||||
const modelNode = new cc.Node('test');
|
||||
modelNode.parent = scene;
|
||||
const modelCom = modelNode.addComponent('cc.ModelComponent');
|
||||
modelCom.material = material;
|
||||
const shape = cc.primitives.quad();
|
||||
shape.colors = Array(shape.uvs.length / 2).fill(0)
|
||||
.map((t) => [Math.random(), Math.random(), Math.random(), 0.8])
|
||||
.reduce((c, a) => a.concat(c), []);
|
||||
modelCom.mesh = cc.utils.createMesh(shape);
|
||||
modelNode.setPosition(0, 3, 100);
|
||||
}
|
||||
|
||||
let buttonDown = false, pos = cc.v2();
|
||||
canv.addEventListener('mousedown', (e) => buttonDown = (!e.button) ? true : buttonDown);
|
||||
canv.addEventListener('mouseup', (e) => buttonDown = (!e.button) ? false : buttonDown);
|
||||
|
||||
Reference in New Issue
Block a user