Files
cocos4/cocos/renderer/scene/model.js
T
Leslie Leigh 913c9013eb mesh rendering and skinning mesh rendering (#3362)
* Modify part of asset classes

* Update import

* Update

* mesh-loader

* Update the import statement of JsonAsset as default import

* Rename files

* Remove old asset and asset-mng

* Copyrights

* Fix some bugs

* Fix imports of vmath classes; Fix errors of decorator property's ts comment notation;Adjust the order of member declarations for better IDE intelligense

* Transplant loader of animation clip; Unify export statement style according rules

* Skeleton asset and SkeletonInstance class

* Rename

* Fix material annotation

* fix import path

* fix annotation error

* Rename update to flush, fix index.js files.

* support original gltf animation;use creator's texture2d instead

* Fix build issues

* Avoid system absent issue caused by ecs import

* add renderer to ccgame, add camera component

* apply stash

* fix predefine.js

* add renderable and rendersystem

* fix format

* Fix core/utils module

* Rename file and fix issues

* add renderer to ccgame, add camera component

* apply stash

* fix predefine.js

* add renderable and rendersystem

* fix format

* fix debug

* fix run errors

* Fix MutableForwardIterator not found issue

* Fix editor runtime issues

* Update 3d node API usage (need merge API in future)

* Temporarily comment out rendering code (need revert)

* add renderer to ccgame, add camera component

* apply stash

* fix predefine.js

* add renderable and rendersystem

* fix format

* fix debug

* fix run errors

* renderer can clear now

* misc fixes in vmath

better vector random sampling
custom w in vec3.transformMat4

* prepare geometry data in editor mode

* per-primitive raycast for editor

* fix dependencies

* fix cctouch error

* fix error, can not rendering

* model can be rendered

* fix for node api changing

* class rename

* clean up code

* add name to ccclass decorators; temporarily comment out vb/ib buffer creation in gltf-loader;temporarily modification of base-node.js

* Open commented vb/ib creation

* make gltf-asset itself a variant of json

* fix import bugs

* update

* import fix

* node transform api

* mesh renderer and skinning mesh renderer

* bug fix

* bug fix
2018-10-10 13:05:31 +08:00

96 lines
2.3 KiB
JavaScript

// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
import { aabb } from '../../3d/geom-utils';
/**
* A representation of a model
*/
export default class Model {
/**
* Setup a default empty model
*/
constructor() {
this._type = 'default';
this._poolID = -1;
this._node = null;
this._inputAssembler = null;
this._effect = null;
this._defines = {};
this._dependencies = {};
this._viewID = -1;
this._cameraID = -1;
this._userKey = -1;
this._castShadow = false;
this._boundingShape = null;
}
_updateTransform() {
if (!this._node._hasChanged || !this._boundingShape) return;
this._node.updateWorldTransformFull();
this._bsModelSpace.transform(this._node._mat, this._node._pos,
this._node._rot, this._node._scale, this._boundingShape);
}
/**
* Create the bounding shape of this model
* @param {vec3} minPos the min position of the model
* @param {vec3} maxPos the max position of the model
*/
createBoundingShape(minPos, maxPos) {
if (!minPos || !maxPos) return;
this._bsModelSpace = aabb.fromPoints(aabb.create(), minPos, maxPos);
this._boundingShape = aabb.clone(this._bsModelSpace);
}
/**
* Set the hosting node of this model
* @param {Node} node the hosting node
*/
setNode(node) {
this._node = node;
}
/**
* Set the input assembler
* @param {InputAssembler} ia
*/
setInputAssembler(ia) {
this._inputAssembler = ia;
}
/**
* Set the model effect
* @param {?Effect} effect the effect to use
*/
setEffect(effect) {
if (effect) {
this._effect = effect;
this._defines = effect.extractDefines(Object.create(null));
this._dependencies = effect.extractDependencies(Object.create(null));
} else {
this._effect = null;
this._defines = Object.create(null);
this._dependencies = Object.create(null);
}
}
/**
* Set the user key
* @param {number} key
*/
setUserKey(key) {
this._userKey = key;
}
/**
* Extract a drawing item
* @param {Object} out the receiving item
*/
extractDrawItem(out) {
out.model = this;
out.node = this._node;
out.ia = this._inputAssembler;
out.effect = this._effect;
out.defines = this._effect.extractDefines(this._defines);
out.dependencies = this._effect.extractDependencies(this._dependencies);
}
}