Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Announcements and Showcase
Texture Terrains via surface angle

Robbo
Guest
Quote
2023-09-16 06:25:25

After a lot of trial and error, I got the auto texturing terrains to work via the surface angle and its almost done.

I have had inconsistent results calculating the surface normal angle however from possibly using this formula which may not be correct:

cellAngle = atan2(Normal.X, Normal.Y) * 57.296;

The vertex Normal is a vector3d with x, y & z so can anyone help me get the correct formula using all 3 ?


giving it a try
Guest
Quote
2023-09-16 17:42:36

// Calculate the angle in degrees
Vector3D Normal;
double cellAngle = atan2(Normal.Y, Normal.X) * 57.296;

// Assuming Normal.Z contains the third component
Normal = Vector3D(cos(cellAngle), sin(cellAngle), Normal.Z);

maybe this will at least give you an idea of how to move forward...


okeoke
Registered User
Quote
2023-09-16 20:26:09

Hello Robbo and mister chatgpt user,

I believe, my last attempt to calculate face normal was based on position of 3 vertex, which define it:

function triangleNormal(x0, y0, z0, x1, y1, z1, x2, y2, z2) {
var p1x = x1 - x0;
var p1y = y1 - y0;
var p1z = z1 - z0;

var p2x = x2 - x0;
var p2y = y2 - y0;
var p2z = z2 - z0;

var p3x = p1y * p2z - p1z * p2y;
var p3y = p1z * p2x - p1x * p2z;
var p3z = p1x * p2y - p1y * p2x;

var mag = Math.sqrt(p3x * p3x + p3y * p3y + p3z * p3z);
if (mag === 0) {
return { x: 0, y: 0, z: 0 };
} else {
return { x: p3x / mag, y: p3y / mag, z: p3z / mag };
}
};

I'm not sure if it's working or not. I believe, I stole it from some github page.

The Internet says that you can calculate the normal of surface by calculating cross product, of two vectors which lay on this surface. Let's say your vertex names are A,B, and C, you can calculate vectors AC and AB by substracting C - A and C - B correspondingly, and then calculating these two vectors cross product. Also no clue if this works or not.

function crossProduct(vector1, vector2) {
return new vector3d(
vector1.y * vector2.z - vector1.z * vector2.y,
vector1.z * vector2.x - vector1.x * vector2.z,
vector1.x * vector2.y - vector1.y * vector2.x
);
}



giving it a try
Guest
Quote
2023-09-17 01:51:51

... actually, this was pulled up using Codeium...
so that's Mr. codeium if you don't mind!


Robbo
Guest
Quote
2023-09-17 04:48:27

Thanks for the input guys, I will add this and test it out.

For now, In am getting something useable at least and hopefully more accurate with this better formula above.

New API's are now working during runtime:
(not available in editor as CC source code doesn't include it)

ccbUpdateTerrain(terrainNode); (run once first)

ccbSetTerrainTexAngle(terrainNode, low, med); (0 - 90 degrees)

ccbSetTerrainTexHeight(terrainNode, low, med); (0 - 1)


Grab an updated version from itchio and test it out:
https://robo25.itch.io/coppercube-new-apis


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internatio?al" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact