Skip to content
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

Merged
merged 6 commits into from Mar 26, 2020

Conversation

sunnylanwanjun
Copy link
Contributor

@sunnylanwanjun sunnylanwanjun commented Feb 26, 2020

修复relative模式,当前节点旋转时,粒子会跟随的bug
优化free算法,每个节点worldrotation每帧只需计算一次,之前的算法有漏洞,每个发射出去粒子都去算一次,有100个,就计算100次。。。。
优化relative算法,传递父节点的世界矩阵,然后用当前节点的local rotation和local position,去初始化粒子,这样就不用cpu计算当前节点的逆矩阵,也不用挨个粒子去乘以逆矩阵,不仅效率低,还有误差。

关联pr:cocos/engine-native#2196
cocos-creator-packages/jsb-adapter#253

* 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.
Copy link
Member

@jareguo jareguo Mar 3, 2020

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.

Copy link
Contributor Author

@sunnylanwanjun sunnylanwanjun Mar 4, 2020

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) {
Copy link
Member

@jareguo jareguo Mar 3, 2020

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) 更清晰
尽可能用 === 吧

Copy link
Contributor Author

@sunnylanwanjun sunnylanwanjun Mar 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pt没意义,刚开始是因为要取多次,所以用变量保存了,后来改了,就忘记删了。

cocos2d/particle/particle-system-assembler.js Outdated Show resolved Hide resolved
jareguo
jareguo approved these changes Mar 6, 2020
@holycanvas holycanvas merged commit 28f9f22 into cocos:v2.4.0 Mar 26, 2020
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants