Jump to content

Recommended Posts

Posted

I am planning something like this:

DraftableBakedModel implements IFlexibleBakedModel{

   private List<BakedQuad> quads = new ArrayList<BakedQuad>();

   public DraftableBakedModel(IDraftable draft){
      HashMap<String, IPartType> parts = draft.getParts();
      for(int i = x; x < 16; x++)
         for(int y = 0; y < 16; y++)
            for(int z = 0; z < 16; z++)
               if(parts.contain(x + "," + y + "," z))
                  quads.addAll(getQuadFrom(parts.get(x + "," + y + "," z), x, y, z);

   }

   //x, y, z specify the relative top, left, front, for the part to base it's vertices from.
   private List<BakedQuad> getQuadFrom(IPartType part,int x, int y, int z){
      // part has relative vertex information and RGBA for the color and transparency
      // that this part should render with.
      // each part can be thought of as a semi transparent, single color cube
      // although they may not actually be cubes
   }
   
}

 

1. is this the correct place to be specifying a color to render with?

2. it seems like each vertex of Baked Quad only has 1 variable for color, so how do I store the color?

3. if this isn't the way to generate a texture how should I be doing it?

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Posted

1. What do you mean? If you are doing everything according to vanilla code (you use model system) then you don't color stuff on your own. You colorize Quads.

2. Well, without looking at internals (can't now) - if that "one variable" is "int" then I don't understand your problem. int =(bits)= 0xRRGGBBAA (I am unsure as to the color ordering). BakedQuad can have texture and color, texture can be applied as u,v coords and use e.g grayscale image, while colorization is one value (to my understanding).

3. What way do you mean? You are doing nothing that actually generates any image OR quads. Also - are you sure about what you are asking - "to generate a texture". From what I understand you want to make 16x16x16 cubical model that can be rendered from ItemStack, e.g:

 

width=204 height=248https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcRbr6VYHu1JTJXVLEB93D_6j1I3DwnU0HetRlou4Wp9BRnXBbGq[/img]

 

You want to (based on ItemStack) make those cubes (like on img) and colorize them (also based on ItemStack). Is this correct?

 

Well, you can either make 4096 grayscale model files that cover every mini-cube, name them cube_x_y_z and then in your smart item combine them. But that we all know is stupid.

 

What you want is generate them on your own - which is simple. Without learning BakedQuad format you can't do shit. You need to create 6 BakedQuads for evey cubical. and place them in proper position of model. Which you probably alredy know - yet still, I have no idea what you are asking of us.

 

Side note: (optimization) When you generate your ItemStack's model for the 1st time - while 4096 (considering worst case) of BakedQUads can be handled, you can easily track and remove some of Quads that are not visible (remove each side of mini-box that contancs other).

 

1.7.10 is no longer supported by forge, you are on your own.

Posted

That was actually helpful, this is what I have come up with since then:

IFlexibleBakedModel

 

public class DraftableBakedModel implements IFlexibleBakedModel{

 private List<BakedQuad> quads = new ArrayList<BakedQuad>();

 public DraftableBakedModel(IDraftable draft){
	 DraftableMap parts = draft.GetPartArray();
	 for(int xPos = 0; xPos < 16; xPos++){
		 for(int yPos = 0; yPos < 16; yPos++){
            for(int zPos = 0; zPos < 16; zPos++){
               if(parts.GetPart(xPos + "," + yPos + "," + zPos) != null)
                  quads.addAll(getQuadFrom(parts.GetPart(xPos + "," + yPos + "," + zPos), xPos, yPos, zPos));
            }
         }
      }
   }

private List<BakedQuad> getQuadFrom(IPartType getPart, int x, int y, int z) {
	List<BakedQuad> list = new ArrayList<BakedQuad>();
	BakedQuad quad;
	//North
	quad = new BakedQuad(applyOffset(getPart.GetVertices(EnumFacing.NORTH),x,y,z), 0, EnumFacing.NORTH);
	list.add(quad);
	//Up
	quad = new BakedQuad(getPart.GetVertices(EnumFacing.UP), z, EnumFacing.UP);
	list.add(quad);
	//East
	quad = new BakedQuad(getPart.GetVertices(EnumFacing.EAST), z, EnumFacing.EAST);
	list.add(quad);
	//South
	quad = new BakedQuad(getPart.GetVertices(EnumFacing.SOUTH), z, EnumFacing.SOUTH);
	list.add(quad);
	//Down
	quad = new BakedQuad(getPart.GetVertices(EnumFacing.DOWN), z, EnumFacing.DOWN);
	list.add(quad);
	//West
	quad = new BakedQuad(getPart.GetVertices(EnumFacing.WEST), z, EnumFacing.WEST);
	list.add(quad);
	return list;
}

private int[] applyOffset(int[] vertices, int x, int y, int z) {
	for(int i = 0; i < 7; i++)//7 elements per vertex
	{
		for(int j = 1; j < 5; j++)// 4 vertices
		{
			switch(i){
			case 0: vertices[i*j] = vertices[i*j] + (x*Refs.OFFSET);//xpos
				break;
			case 1: vertices[i*j] = vertices[i*j] + (y*Refs.OFFSET);//ypos
				break;
			case 2: vertices[i*j] = vertices[i*j] + (z*Refs.OFFSET);//zpos
				break;
			default:
				break;
			}
		}
	}
	return vertices;
}
}

 

Vertices

 

        public int[] GetVertices(EnumFacing face) {
	switch(face){
	case NORTH:
		return north();
	case EAST:
		return east();
	case WEST:
		return west();
	case SOUTH:
		return south();
	case UP:
		return up();
	case DOWN:
		return down();
	default:
		return null;
	}
}

private int[] north() {
	int[] vertices = new int[28];
	//top left
	vertices[0] = 0; //x
	vertices[1] = 0; //y
	vertices[2] = 0; //z
	vertices[3] = asInt(luxin.GetColor()); // rrggbbaa
	vertices[4] = 0; //u 
	vertices[5] = 0; //v
	vertices[6] = 0; //unused
	//top right
	vertices[7] = 1; //x
	vertices[8] = 0; //y
	vertices[9] = 0; //z
	vertices[10] = asInt(luxin.GetColor()); // rrggbbaa
	vertices[11] = 0; //u 
	vertices[12] = 0; //v
	vertices[13] = 0; //unused
	//bottom right
	vertices[14] = 1; //x
	vertices[15] = 0; //y
	vertices[16] = 1; //z
	vertices[17] = asInt(luxin.GetColor()); // rrggbbaa
	vertices[18] = 0; //u 
	vertices[19] = 0; //v
	vertices[20] = 0; //unused
	//bottom left
	vertices[21] = 0; //x
	vertices[22] = 0; //y
	vertices[23] = 1; //z
	vertices[24] = asInt(luxin.GetColor()); // rrggbbaa
	vertices[25] = 0; //u 
	vertices[26] = 0; //v
	vertices[27] = 0; //unused
	return vertices;
}

        private int asInt(int[] color) {
	return (color[0]&0x0ff)<<24|(color[1]&0x0ff)<<16|(color[2]&0x0ff)<<8|(color[3]&0x0ff);//0 is r, 1 is g, 2 is b, 3 is a, &0x0ff limits each to 1 byte
}

with similar code for the other faces

 

 

 

I know this would still generate every quad, even unnecessary ones but I'll optimize that after I get it working.

 

1. Is it ok to leave u,v as 0 since I don't need anything from an actual texture file?

2. What is the scale of a block? Will 16 quads like I have reach up to a full block height?

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.