本帖最后由 zkm00323 于 2017-1-24 13:13 编辑
其实我完全没学过openGL
所以这个教程可能不全面
但是基本会用到的功能,这里会讲
一般实体生物会有自己的model文件
但是RenderArrow并没有(package net.minecraft.client.renderer.entity;)
由于解释RenderArrow太麻烦,我直接来解释自己做的Render
通过研究RenderArrow里的doRender方法,我们来自定义一个模型
我们修改一下之前写的RenderIcebullet
public class RenderIcebullet extends Render<EntityIcebullet>{
public RenderIcebullet(RenderManager renderManagerIn) {
super(renderManagerIn);
}
@Override
protected ResourceLocation getEntityTexture(EntityIcebullet entity) {
return new ResourceLocation(Name.MOD_ID, "textures/entity/ice.png");//获取贴图路径,
←贴图顺便给了
}
@Override
public void doRender(EntityIcebullet entity, double x, double y, double z, float entityYaw, float partialTicks) {
this.bindEntityTexture(entity);//绑定贴图
//GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);//渲染颜色RPG偏移
GlStateManager.pushMatrix();//压入当前矩阵堆栈
//GlStateManager.disableCull();//開啟雙面顯示(默认情况下渲染一个平面只有单面可显示,绕道后面看就没了)
GlStateManager.disableLighting();//關閉自帶光源,这样才能让mc用环境光去算他的亮度
GlStateManager.enableBlend();//開啟不透明度(因为这个是冰弹,所以给他读取贴图透明度的能力)
GlStateManager.translate((float)x, (float)y, (float)z);//坐標
//下面的GlStateManager.rotate第一个参数为转动的角度,后面3个参数分别为x,y,z轴,0则不作用,大于0则作用
//角度-------------------------------------------------------------------------------------------------------------------------------------------------↓只对y轴作用
GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks - 90.0F, 0.0F, 1.0F, 0.0F);
//角度-------------------------------------------------------------------------------------------------------------------------------------------------↓只对z轴作用
GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, 0.0F, 0.0F, 1.0F)
Tessellator tessellator = Tessellator.getInstance();//由于3D绘图的实例?
VertexBuffer vertexbuffer = tessellator.getBuffer();//顶点计算???....反正抄就对了
GlStateManager.enableRescaleNormal();//重新规范化法向量???
GlStateManager.scale(0.05625F, 0.05625F, 0.05625F);//设置大小
GlStateManager.translate(-3.0F, 0.0F, 0.0F);//把渲染图形往箭尾移动一,图0
// if (this.renderOutlines){//似乎是一种renderOutlines防护措施可不写
// GlStateManager.enableColorMaterial();
// GlStateManager.enableOutlineMode(this.getTeamColor(entity));
// }
for (int j = 0; j < 4; ++j){//循环4次
GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);//x轴旋转90度(下次执行会在这次90度的基础下再转90度)
//GlStateManager.glNormal3f(0.0F, 0.0F, 0.05625F);//不懂什么意义,不写也无妨
vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);//开始绘制
//pos(0,0,0)为游戏中实体中心坐标,tex(0,0)为贴图上的坐标,一格像素为0.03125,可以看图1参考
vertexbuffer.pos(-3.0D, -3.0D, 3.0D).tex(0.0D,0.0D).endVertex();//点1
vertexbuffer.pos(3.0D, -3.0D, 3.0D).tex(0.1875D, 0.0D).endVertex();//点2
vertexbuffer.pos(3.0D, 3.0D, 3.0D).tex(0.1875D, 0.1875D).endVertex();//点3
vertexbuffer.pos(-3.0D, 3.0D, 3.0D).tex(0.0D, 0.1875D).endVertex();//点4
//4个点绘制一个四边形
tessellator.draw();//此次绘制结束,图2状态
//下面以此类推总共画了3个面,for4次,每次增加90度,这样就可以绘制一个完整12面体
vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
vertexbuffer.pos(-9.0D, 0.0D, 0.0D).tex(0.0D, 0.0D).endVertex();
vertexbuffer.pos(-3.0D, -3.0D, 3.0D).tex(0.1875D, 0.0D).endVertex();
vertexbuffer.pos(-3.0D, 3.0D, 3.0D).tex(0.1875D, 0.1875D).endVertex();
vertexbuffer.pos(-9.0D, 0.0D, 0.0D).tex(0.0D, 0.1875D).endVertex();
tessellator.draw();//此次绘制结束,图3状态
vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
vertexbuffer.pos(9.0D, 0.0D, 0.0D).tex(0.0D, 0.0D).endVertex();
vertexbuffer.pos(3.0D, 3.0D, 3.0D).tex(0.1875D, 0.0D).endVertex();
vertexbuffer.pos(3.0D, -3.0D, 3.0D).tex(0.1875D, 0.1875D).endVertex();
vertexbuffer.pos(9.0D, 0.0D, 0.0D).tex(0.0D, 0.1875D).endVertex();
tessellator.draw();//此次绘制结束,图4状态
}//for(1),图5状态
//for(2),图6状态
//for(3),图7状态
// if (this.renderOutlines)
// {
// GlStateManager.disableOutlineMode();
// GlStateManager.disableColorMaterial();
// }
//openGL有很多渲染开关.需要在渲染完后恢复原状
GlStateManager.disableRescaleNormal();//关闭规范化法向量???
GlStateManager.enableLighting();//開啟自帶光源
//GlStateManager.enableCull();//關閉雙面顯示
GlStateManager.disableBlend();//關閉不透明度
GlStateManager.popMatrix();//弹出当前矩阵堆栈
super.doRender(entity, x, y, z, entityYaw, partialTicks);
}
}
//////////////////////////////////////////////////////////////////////
图0
图5
图6
图7
最后他应该会长这样
一个正方体,前后都加个四角锥
正方体 上,下,左,右 4个面
+前四角锥 的4个斜面
+后四角锥 的4个斜面
总共12个面
虽然可以实现自定义模型,不过原理没法解释很清楚
http://www.mcbbs.net/thread-204115-1-1.html
贴上这个教程想了解的可以去看看
源代码
src_教程10.rar
(28.18 KB, 下载次数: 32)
其实我完全没学过openGL
所以这个教程可能不全面
但是基本会用到的功能,这里会讲
一般实体生物会有自己的model文件
但是RenderArrow并没有(package net.minecraft.client.renderer.entity;)
由于解释RenderArrow太麻烦,我直接来解释自己做的Render
通过研究RenderArrow里的doRender方法,我们来自定义一个模型
我们修改一下之前写的RenderIcebullet
public class RenderIcebullet extends Render<EntityIcebullet>{
public RenderIcebullet(RenderManager renderManagerIn) {
super(renderManagerIn);
}
@Override
protected ResourceLocation getEntityTexture(EntityIcebullet entity) {
return new ResourceLocation(Name.MOD_ID, "textures/entity/ice.png");//获取贴图路径,

}
@Override
public void doRender(EntityIcebullet entity, double x, double y, double z, float entityYaw, float partialTicks) {
this.bindEntityTexture(entity);//绑定贴图
//GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);//渲染颜色RPG偏移
GlStateManager.pushMatrix();//压入当前矩阵堆栈
//GlStateManager.disableCull();//開啟雙面顯示(默认情况下渲染一个平面只有单面可显示,绕道后面看就没了)
GlStateManager.disableLighting();//關閉自帶光源,这样才能让mc用环境光去算他的亮度
GlStateManager.enableBlend();//開啟不透明度(因为这个是冰弹,所以给他读取贴图透明度的能力)
GlStateManager.translate((float)x, (float)y, (float)z);//坐標
//下面的GlStateManager.rotate第一个参数为转动的角度,后面3个参数分别为x,y,z轴,0则不作用,大于0则作用
//角度-------------------------------------------------------------------------------------------------------------------------------------------------↓只对y轴作用
GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks - 90.0F, 0.0F, 1.0F, 0.0F);
//角度-------------------------------------------------------------------------------------------------------------------------------------------------↓只对z轴作用
GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, 0.0F, 0.0F, 1.0F)
Tessellator tessellator = Tessellator.getInstance();//由于3D绘图的实例?
VertexBuffer vertexbuffer = tessellator.getBuffer();//顶点计算???....反正抄就对了
GlStateManager.enableRescaleNormal();//重新规范化法向量???
GlStateManager.scale(0.05625F, 0.05625F, 0.05625F);//设置大小
GlStateManager.translate(-3.0F, 0.0F, 0.0F);//把渲染图形往箭尾移动一,图0
// if (this.renderOutlines){//似乎是一种renderOutlines防护措施可不写
// GlStateManager.enableColorMaterial();
// GlStateManager.enableOutlineMode(this.getTeamColor(entity));
// }
for (int j = 0; j < 4; ++j){//循环4次
GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);//x轴旋转90度(下次执行会在这次90度的基础下再转90度)
//GlStateManager.glNormal3f(0.0F, 0.0F, 0.05625F);//不懂什么意义,不写也无妨
vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);//开始绘制
//pos(0,0,0)为游戏中实体中心坐标,tex(0,0)为贴图上的坐标,一格像素为0.03125,可以看图1参考
vertexbuffer.pos(-3.0D, -3.0D, 3.0D).tex(0.0D,0.0D).endVertex();//点1
vertexbuffer.pos(3.0D, -3.0D, 3.0D).tex(0.1875D, 0.0D).endVertex();//点2
vertexbuffer.pos(3.0D, 3.0D, 3.0D).tex(0.1875D, 0.1875D).endVertex();//点3
vertexbuffer.pos(-3.0D, 3.0D, 3.0D).tex(0.0D, 0.1875D).endVertex();//点4
//4个点绘制一个四边形
tessellator.draw();//此次绘制结束,图2状态
//下面以此类推总共画了3个面,for4次,每次增加90度,这样就可以绘制一个完整12面体
vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
vertexbuffer.pos(-9.0D, 0.0D, 0.0D).tex(0.0D, 0.0D).endVertex();
vertexbuffer.pos(-3.0D, -3.0D, 3.0D).tex(0.1875D, 0.0D).endVertex();
vertexbuffer.pos(-3.0D, 3.0D, 3.0D).tex(0.1875D, 0.1875D).endVertex();
vertexbuffer.pos(-9.0D, 0.0D, 0.0D).tex(0.0D, 0.1875D).endVertex();
tessellator.draw();//此次绘制结束,图3状态
vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
vertexbuffer.pos(9.0D, 0.0D, 0.0D).tex(0.0D, 0.0D).endVertex();
vertexbuffer.pos(3.0D, 3.0D, 3.0D).tex(0.1875D, 0.0D).endVertex();
vertexbuffer.pos(3.0D, -3.0D, 3.0D).tex(0.1875D, 0.1875D).endVertex();
vertexbuffer.pos(9.0D, 0.0D, 0.0D).tex(0.0D, 0.1875D).endVertex();
tessellator.draw();//此次绘制结束,图4状态
}//for(1),图5状态
//for(2),图6状态
//for(3),图7状态
// if (this.renderOutlines)
// {
// GlStateManager.disableOutlineMode();
// GlStateManager.disableColorMaterial();
// }
//openGL有很多渲染开关.需要在渲染完后恢复原状
GlStateManager.disableRescaleNormal();//关闭规范化法向量???
GlStateManager.enableLighting();//開啟自帶光源
//GlStateManager.enableCull();//關閉雙面顯示
GlStateManager.disableBlend();//關閉不透明度
GlStateManager.popMatrix();//弹出当前矩阵堆栈
super.doRender(entity, x, y, z, entityYaw, partialTicks);
}
}
//////////////////////////////////////////////////////////////////////
图0





图5

图6

图7

最后他应该会长这样

一个正方体,前后都加个四角锥
正方体 上,下,左,右 4个面
+前四角锥 的4个斜面
+后四角锥 的4个斜面
总共12个面
虽然可以实现自定义模型,不过原理没法解释很清楚
http://www.mcbbs.net/thread-204115-1-1.html
贴上这个教程想了解的可以去看看
源代码
