大神们,编辑器如何导入第三方库?如 liquidfun导入出错

下面的代码是我 重写的DrawParticles 其中就是在设置shader的一些信息,
b2.Draw.prototype.DrawParticles = function( positionBuffer, radius, colorBuffer, particleCount){
//console.log(‘DrawParticles start’);
let particle_size_multiplier = 8; // no falloff
let global_alpha = 0.35; // instead of texture
g_material.setU_pointSize(radius * PTM_RATIO * particle_size_multiplier);
let centers = new Array();
for(var i=0; i < particleCount; i++) {
let vec2 = b2.Vec2(positionBuffer[i].x *PTM_RATIO,positionBuffer[i].y *PTM_RATIO);
centers[i] = vec2;
g_material.setA_position(centers[i]);
}
//g_material.setA_texCoord();
let temp_vec2 = cc.v2( 0, 0)
let drawer = this._drawer;
//g_material.setU_color(0, 0, 0, global_alpha);

if(colorBuffer != null){
	g_material.setU_color(colorBuffer[0].r, colorBuffer[0].g, colorBuffer[0].b, global_alpha);
}else{
	g_material.setU_color(0.1, 0.2, 0.3, global_alpha);
}

};

官方的demo中 有一些参考,上面的实现也是参考这个函数来的,但是 结果 没有出现,而且对官方中的一些函数也是一知半解,比如这个glVertexAttribPointer 是不是也是在设置shader的信息。不知道大佬可不可以给参谋一下!!
void GLESDebugDraw::DrawParticles(const b2Vec2 *centers_old, float32 radius, const b2ParticleColor colors, int32 count)
{
/

// normally this is how we’d enable them on desktop OpenGL,
// but for some reason this is not applying textures, so we use alpha instead
glEnable(GL_POINT_SPRITE);
glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
*/
const float particle_size_multiplier = 8; // no falloff
const float global_alpha = 0.35f; // instead of texture

mShaderProgram->setUniformLocationWith1f(mPointSizeLocation, radius * mRatio * particle_size_multiplier);

GL::blendFunc(GL_SRC_ALPHA, GL_ONE);

b2Vec2 *centers = (b2Vec2 *) alloca(sizeof(b2Vec2) * count);
for(int i=0; i<count; i++) {
    centers[i].x = centers_old[i].x *mRatio;
    centers[i].y = centers_old[i].y *mRatio;
}

glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, centers);
glVertexAttrib4f(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 0, 0, 1, 1);

if (0 /*colors*/)
{
    // hack to render with proper alpha on desktop for Testbed
    b2ParticleColor * mcolors = const_cast<b2ParticleColor *>(colors);
    for (int i = 0; i < count; i++)
    {
        mcolors[i].a = static_cast<uint8>(global_alpha * 255);
    }
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, &colors[0].r);
}
else
{
    glVertexAttrib4f(GLProgram::VERTEX_ATTRIB_COLOR, 1, 1, 1, global_alpha);
    mShaderProgram->setUniformLocationWith4f(mColorLocation, 1, 1, 1, global_alpha);
}

glDrawArrays(GL_POINTS, 0, count);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,count);

}

大佬,为什么我写了个继续与new b2.Draw();的debugDraw类然后重写了些画粒子的方法比如 DrawParticles等
然后在Update里掉用
this.m_world.Step(dt,8,3,3);
this.m_world.DrawDebugData();
但是他并没有进debugDraw里定义的方法

你开启了这个嘛?

这个问题弄好了,但我想webgl画粒子,但画的蛋疼有没有什么cocos自带的画粒子的方法

shader 就行了

shader怎么画啊

你的官方demo在哪里下的 我的是老版的OpenGL

用PT_POINTS模式画点,然后把各个点传进去就好了

你成功了没 有没有发帖呢。。 官方demo在哪啊。。

如何实现那个接口呢。。。

兄弟 有demo嘛了 搞了一天,还是一脸萌逼。

bro,做出来了嘛?

mark

shader可以参考: Cocos流体之 LiquidFun流体纹理shader的编写(二)

gl绘制时使用gl_point模式

我做的怎么不可以。。。

按照你的方式做的

2.2.x版本改了

所以你应该改成b2.World , b2.Vec2

git : CCPhysicsManager

我吧对应的b2*都改成了b2.
是正确的,成功执行了,
但是实际上并没有执行

这个 手写的方法,所以在执行


的时候这个this._world 报空了,,,,,,,,,

最近github上发现了ccc流体demo:liuwenkai1023/ccc-fluid-demo

1赞

这个 你可以根据 自己构建出的项目 看一下 基本就看明白了

报错环境: 微信小游戏

在web 上面是正常的

首先 我们看一下 项目结构

liquidfun.js 这个文件 最后添加 这样 代码引入即可
(说明 根据你 项目的引用 直接 window.xxxx = xxxx )这样 即可
文字缩进4格`` window.b2Vec2 = b2Vec2;
window.b2BodyDef = b2BodyDef;
window.b2World = b2World;
window.b2PolygonShape = b2PolygonShape;
window.b2ParticleSystemDef = b2ParticleSystemDef;
window.b2ParticleGroupDef = b2ParticleGroupDef;

以上 就是解决方案

你好,这个demo能支持多个不同的预设体来渲染吗?