Discuss Scratch
- Discussion Forums
- » Show and Tell
- » Instructions on how to use my 3D engine (glitchless sorting and intersecting triangles!)
- Vadik1
-
Scratcher
500+ posts
Instructions on how to use my 3D engine (glitchless sorting and intersecting triangles!)
About 1.5 a years ago I've made my second 3D engine.
The best thing about this engine compared to other is that it displays everything in the correct order and even can deal with intersecting triangles.
It uses Binary Space Partioning to sort triangles and sprites.
This topic is a tutorial for using it.
Everything in this 3d engine is based on 3d objects.
You can control objects from Game sprite.
In Engine sprite the only thing you should change is
Game sprite contains lots of custom blocks for interacting with 3d:
The best thing about this engine compared to other is that it displays everything in the correct order and even can deal with intersecting triangles.
It uses Binary Space Partioning to sort triangles and sprites.
This topic is a tutorial for using it.
Everything in this 3d engine is based on 3d objects.
You can control objects from Game sprite.
In Engine sprite the only thing you should change is
define Controls
Game sprite contains lots of custom blocks for interacting with 3d:
Custom block definitions:broadcast [activate engine v]
broadcast [stop engine v]Clear all::category customDoes exactly what you expectNewObject [type]at(0)(0)(0)visible(1)::category customtype x y z visibility:
type - is actually an object type. Objects of the same type have the same behavior.
x,y,z - position of the object
visibility - 0-invisible 1-visibleAdd triangle(0)(0)(0)(0)(0)(0)(0)(0)(0)color(0)(0)(0)(0)face(0)object(0)::category customx1 y1 z1 x2 y2 z2 x3 y3 z3 red green blue transparency face object
x1 y1 z1 x2 y2 z2 x3 y3 z3 - position of the triangle corner
red green blue - color (value from 0 to 255)
transparency - 255-solid 0-invisible
face - 0-visible from both sides 1,-1-visible from one side, everything else-invisible
object - number of element(not a name) containing needed object in the GroupNameHide(0)::category customobject - number of element(not a name) containing needed object in the GroupName
Show(0)::category customClear model(0)::category customremoves all triangles of entered object
object - number of element(not a name) containing needed object in the GroupNameDeleate(0)::category customremoves object and all triangles of it
object - number of element(not a name) containing needed object in the GroupNameSprite(0)costume[costume name]::category customobject costume
object - number of element(not a name) containing needed object in the GroupName
costume - name or id of a costume that is placed inside Engine sprite
puts your costume at the center of an object
does exactly the same thing as:replace item (object v) of [GroupDisp v] with [costume]replace item (object v) of [GroupX v] with [0]object position
replace item (object v) of [GroupY v] with [0]
replace item (object v) of [GroupZ v] with [0]
moves objectreplace item (object v) of [GroupVX v] with [0]object velocity
replace item (object v) of [GroupVY v] with [0]
replace item (object v) of [GroupVZ v] with [0]
sets velocity
purpose can be changedreplace item (object v) of [GroupTmp v] with [costume]object value
value - has no purpose, you can use it for anything
Variables(Pheight)- Height of the player(meters)(CamX) (CamY) (CamZ)- position of the feet(Quality-Speed)- 1-max quality 10-low quality(AngleX)- pitch(AngleY)- yaw(AngleZ)- roll(Max walking speed)(StandOn)reports a triangle(not an object)
to get object number, you should use(item ((StandOn) * (3)) of [FO v] :: list)
to get object type, you should use(item (item ((StandOn) * (3)) of [FO v] :: list) of [GroupName v] :: list)(Look_Tri)works the same but can also report looking at sprite, by giving negative value(and in that case it would be group number)(Look_Dist)Distance to the place which you are looking at(Look_X)(Look_Y)(Look_Z)Coordinates of place which you are looking at
Behavior
Making animated objects.define Game tickIn Your code 1 you describe what would happen with every object in every frame.
set [item v] to [0]
repeat (length of [GroupName v] :: list)
change [item v] by (1)
your code 1::color #aaaaaa
replace item (item) of [GroupX v] with ((item (item) of [GroupX v] :: list) + (item (item) of [GroupVX v] :: list))
replace item (item) of [GroupY v] with ((item (item) of [GroupY v] :: list) + (item (item) of [GroupVY v] :: list))
replace item (item) of [GroupZ v] with ((item (item) of [GroupZ v] :: list) + (item (item) of [GroupVZ v] :: list))
end
your code 2::color #aaaaaa
Example:if <(item (item) of [GroupName v]::list)=[samll_tree]> thenIn Your code 2 you describe what would happen every frame(something you don't need to run for every object).
replace item (item) of [GroupTmp v] with ((item (item) of [GroupTmp v] :: list) + (1))
if<(item (item) of [GroupTmp v] :: list)=(1000)> then
replace item (item) of [GroupName v] with [tree]
replace item (item) of [GroupDisp v] with [tree_costume]
end
end
Last edited by Vadik1 (July 1, 2020 13:17:56)
- jslashcraft
-
Scratcher
3 posts
Instructions on how to use my 3D engine (glitchless sorting and intersecting triangles!)
Thanks I get it a little more now
- jslashcraft
-
Scratcher
3 posts
Instructions on how to use my 3D engine (glitchless sorting and intersecting triangles!)
Each time I read something I understand something different
- -RlSEN-
-
Scratcher
1 post
Instructions on how to use my 3D engine (glitchless sorting and intersecting triangles!)
This is truly incredible!
- ugfvb
-
Scratcher
1 post
Instructions on how to use my 3D engine (glitchless sorting and intersecting triangles!)
[/i][/b]
move () steps
pen up
- zefiriu
-
Scratcher
22 posts
Instructions on how to use my 3D engine (glitchless sorting and intersecting triangles!)
I really dont understand
- DavidStar53
-
Scratcher
60 posts
Instructions on how to use my 3D engine (glitchless sorting and intersecting triangles!)
Still confused
- Discussion Forums
- » Show and Tell
-
» Instructions on how to use my 3D engine (glitchless sorting and intersecting triangles!)





