New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize 2d particle #6236
optimize 2d particle #6236
Conversation
cocos2d/particle/CCParticleSystem.js
Outdated
* Living particles are attached to the world but will follow the emitter repositioning.<br/> | ||
* Use case: Attach an emitter to an sprite, and you want that the emitter follows the sprite. | ||
* In the relative mode, the particle will move with the parent node, but not with the node where the particle is. | ||
* For example, in a moving train, the coffee in the cup lifts the fog, and the cup moves, the whole fog will not move with the cup, but from the point of view of the train, the whole fog will move with the train. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the coffee in the cup is steaming. Then the steam moves (forward) with the train, rather than moves with the cup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your English is awesome.
const PositionType = cc.ParticleSystem.PositionType; | ||
let pt = comp.positionType; | ||
let node = comp.node; | ||
if (pt == PositionType.RELATIVE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我没太看出这里定义 pt 的意义,感觉直接写 if (comp.positionType === PositionType.RELATIVE) 更清晰
尽可能用 === 吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pt没意义,刚开始是因为要取多次,所以用变量保存了,后来改了,就忘记删了。
修复relative模式,当前节点旋转时,粒子会跟随的bug
优化free算法,每个节点worldrotation每帧只需计算一次,之前的算法有漏洞,每个发射出去粒子都去算一次,有100个,就计算100次。。。。
优化relative算法,传递父节点的世界矩阵,然后用当前节点的local rotation和local position,去初始化粒子,这样就不用cpu计算当前节点的逆矩阵,也不用挨个粒子去乘以逆矩阵,不仅效率低,还有误差。
关联pr:cocos/engine-native#2196
cocos-creator-packages/jsb-adapter#253