Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textures for OpenSCAD Preview mode #4551

Open
wants to merge 172 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
8f67dc7
started with parent_parameter
gusohler Dec 22, 2022
afcd15a
parent_param module appears to work
gusohler Dec 22, 2022
ae5654c
hierarchy traversal works, too now
gusohler Dec 23, 2022
92181d6
just parent counting does not yet work
gusohler Dec 23, 2022
0e4f74a
finally evalstring is what i want
gusohler Dec 26, 2022
06c2312
Merge branch 'openscad:master' into master
gsohler Dec 26, 2022
9f6cf31
added python just for fun right now
gusohler Dec 27, 2022
deb1bb5
evaluates python code from openscad editor now
gusohler Dec 27, 2022
d2e4221
first own python function cube
gusohler Dec 28, 2022
387cd4f
cube is parsed and put to database
gusohler Dec 28, 2022
cc9506f
custrom OpenSCAD type in python
gusohler Dec 28, 2022
e418255
own cube is displayed
gusohler Dec 28, 2022
46084f4
parameter parsing works
gusohler Dec 28, 2022
b159ef8
cube 3 dimension parsing working
gusohler Dec 30, 2022
c5e1bf3
started with stack and translate
gusohler Dec 30, 2022
4efb237
stack works now
gusohler Dec 31, 2022
3f8adaa
translate working
gusohler Dec 31, 2022
e9a2e24
rotate and union working
gusohler Jan 1, 2023
e6dc71d
reorganized, add diff and intersection
gusohler Jan 1, 2023
15954e5
cylinder and sphere added
gusohler Jan 1, 2023
0c4daaa
Merge branch 'openscad:master' into master
gsohler Jan 1, 2023
4bc0d15
Merge branch 'master' into python
gusohler Jan 4, 2023
92293c2
parameter passing works
gusohler Jan 7, 2023
b519f7b
completely removed stack
gusohler Jan 7, 2023
6750c54
Merge branch 'openscad:master' into master
gsohler Jan 9, 2023
0b728f8
Merge branch 'master' into python
gusohler Jan 9, 2023
59af5f5
added circle and square
gusohler Jan 9, 2023
d56b4f3
linear_extrude works
gusohler Jan 9, 2023
f459d86
added rotate_extrude
gusohler Jan 9, 2023
b49cb39
added scale and mirror
gusohler Jan 11, 2023
0ba6d0d
Merge branch 'openscad:master' into master
gsohler Jan 11, 2023
bdb5533
Merge branch 'master' into python
gusohler Jan 11, 2023
68507f1
polygon works
gusohler Jan 11, 2023
85fbae8
polyhedron and multmatrix added
gusohler Jan 11, 2023
267d86f
python errors appear in openscad console window now
gusohler Jan 11, 2023
d3b8ddc
created nice member methods for most of the functions
gusohler Jan 11, 2023
ee42bf3
put some more list checks
gusohler Jan 11, 2023
bf5ba7b
rerdered fnctions
gusohler Jan 12, 2023
2996a4b
commit, minkowski, hull and resize done
gusohler Jan 12, 2023
f89b510
offset and roof also working
gusohler Jan 12, 2023
40b1e0d
text and textmetrics working
gusohler Jan 12, 2023
003f204
automatically switches between scad and python mode
gusohler Jan 12, 2023
66a962d
Merge branch 'openscad:master' into master
gsohler Jan 12, 2023
b38df68
Merge branch 'master' into python
gusohler Jan 12, 2023
1f43951
more syntax checks, fa, fn and fs are used
gusohler Jan 12, 2023
ce7d012
forgot one file
gusohler Jan 12, 2023
20595d5
added Feature box
gusohler Jan 13, 2023
482e145
import, surface and project are working. fixed linear_extrude
gusohler Jan 13, 2023
5bf8364
Merge branch 'openscad:master' into master
gsohler Jan 13, 2023
c293ee5
added colornode
gusohler Jan 13, 2023
ed24caf
added version functions
gusohler Jan 13, 2023
205a108
added group and render
gusohler Jan 13, 2023
8b01b6b
Merge branch 'openscad:master' into python
gsohler Jan 13, 2023
3e01e06
started moving pytrhon functions to a separate file
gusohler Jan 14, 2023
b876270
hopefully all functions moved
gusohler Jan 14, 2023
d36e4da
miniimzed impact of python changed files
gusohler Jan 14, 2023
570746f
Merge branch 'python' of https://github.com/gsohler/openscad into python
gusohler Jan 14, 2023
d9c92fc
undone evalstring in master
gusohler Jan 15, 2023
cd04869
Merge branch 'master' into python
gusohler Jan 15, 2023
61d4b5c
python_enable does not need to be static
gusohler Jan 15, 2023
2bb23b9
Merge branch 'openscad:master' into master
gsohler Jan 15, 2023
8e8b8ed
was able to rename back files
gusohler Jan 15, 2023
a35ec18
Merge branch 'master' of https://github.com/gsohler/openscad
gusohler Jan 15, 2023
dc5a017
Merge branch 'master' into python
gusohler Jan 15, 2023
7ffb126
Merge branch 'openscad:master' into master
gsohler Jan 16, 2023
a9e2e49
combined ci for today;s work
gusohler Jan 16, 2023
f336151
saving interesting file
gusohler Jan 18, 2023
e76c9d8
resolved another naming conflice with python: node.h
gusohler Jan 18, 2023
6681f37
Merge branch 'openscad:master' into master
gsohler Jan 18, 2023
f9ab6c8
Merge branch 'openscad:master' into python
gsohler Jan 18, 2023
0501ce4
openscad objects are not subscriptable
gusohler Jan 19, 2023
4685018
added binary operators for python-openscad
gusohler Jan 19, 2023
a569620
* operator can be used with number for scaling, other cleanup and gen…
gusohler Jan 20, 2023
0eb67d6
forgot to check in this file
gusohler Jan 20, 2023
4a17fd0
improved incref and decref
gusohler Jan 20, 2023
fff78a0
correct INCREF and DECREF in place
gusohler Jan 20, 2023
95fe9a6
created a compile-time option ENABLE_PYTHON
gusohler Jan 21, 2023
5836128
added command line option enable-python
gusohler Jan 21, 2023
61575f0
forgot one line
gusohler Jan 21, 2023
f748e60
requested changes by teepee
gusohler Jan 21, 2023
784d7b5
OpenSCAD with a Python Engine (#4498)
gsohler Jan 22, 2023
1b2459e
Run scripts/beautify.sh.
t-paul Jan 22, 2023
50c88a9
linear_extrude added
gusohler Jan 23, 2023
8f74c69
linear_extrude profile cleanup
gusohler Jan 23, 2023
5ae2f8b
started with rotate_extrude profile function
gusohler Jan 23, 2023
4688856
support scale and rotateion argument for linear_extrude with profiling
gusohler Jan 23, 2023
c83abba
first rotate_extrude work
gusohler Jan 23, 2023
c28136e
save today's work
gusohler Jan 23, 2023
6dd2b03
Merge branch 'openscad:master' into master
gsohler Jan 23, 2023
080c6ad
save files
gusohler Jan 24, 2023
ab69445
Merge branch 'master' into python
gusohler Jan 24, 2023
71cd46c
added command line python support
gusohler Jan 24, 2023
a32aaa3
rotate_extrude object closed, twist and origin work like a charm
gusohler Jan 24, 2023
6491468
first success wth path_extrude, copy formatted version
gusohler Jan 25, 2023
c64aef6
gratly restructured it. ready for the tricky stuff
gusohler Jan 25, 2023
94356cb
fixed my name, next step path extrude
gusohler Jan 25, 2023
b392c76
finally top and bot faces are correct
gusohler Jan 26, 2023
a19fed8
still on track
gusohler Jan 26, 2023
d7b5ab8
first success with xdir rotation
gusohler Jan 26, 2023
6cc11b5
update
gusohler Jan 26, 2023
14849d4
importing $t variable to allow for animations
gusohler Jan 26, 2023
6a3ffe8
python interface in commandline mode, pass time variable "t" , fix typos
gusohler Jan 27, 2023
d1853ed
forgot to check in file
gusohler Jan 27, 2023
6e50501
need to cleanup now
gusohler Jan 27, 2023
95c4b95
cleanup
gusohler Jan 27, 2023
583baad
added closed parameter
gusohler Jan 28, 2023
a1ed4c2
own PathExtrudeNode now
gusohler Jan 28, 2023
3030d3a
rotate enabled
gusohler Jan 29, 2023
50ea005
rotate works for closed pathes, also fs is used now
gusohler Jan 29, 2023
1d45973
replaced "true" by True for parsing
gusohler Jan 29, 2023
acceeb3
custom profiles working with path_extrude
gusohler Jan 29, 2023
701edc2
path_extrude module implemented
gusohler Jan 29, 2023
835a3e9
added missing ifdef
gusohler Jan 30, 2023
38d459e
using Python True instead of "true"
gusohler Jan 30, 2023
f16265c
copied over path_extrude additions
gusohler Jan 30, 2023
027cab7
added missing files
gusohler Jan 30, 2023
b338f87
path_extrude now works in its own branch
gusohler Jan 30, 2023
830a6dd
1st corner rounding works, but arbritary rounds look ugly
gusohler Jan 30, 2023
104118c
all smooth bends are possiblenow
gusohler Jan 30, 2023
d28fc95
round edges also for closed pathes
gusohler Jan 31, 2023
6b5afca
added intersection check
gusohler Jan 31, 2023
2158faf
ready for presentation:w
gusohler Jan 31, 2023
72f24b7
fixed M_PI issue
gusohler Jan 31, 2023
9c1a000
fixed M_PI
gusohler Jan 31, 2023
3a6f2d8
cleanup
gusohler Jan 31, 2023
87c5fbc
fixed formula for parallel scale and rotate
gusohler Feb 1, 2023
bf2a255
Merge branch 'path_extrude' into python
gusohler Feb 1, 2023
dc6be95
firstr success in offset3d
gusohler Feb 1, 2023
ca553f1
offset3d works, need to cleanup and debug
gusohler Feb 2, 2023
e05ccb5
added fallback error handling
gusohler Feb 2, 2023
c442bfc
removed artefacts
gusohler Feb 2, 2023
2dbbd39
removed evalstring
gusohler Feb 2, 2023
7004f4e
Merge branch 'offset' into python
gusohler Feb 2, 2023
def5b97
added high dependant twist function for all extruding functions
gusohler Feb 5, 2023
30a7db2
lambda functions possible now
gusohler Feb 5, 2023
a332a80
added 1st primitive python test
gusohler Feb 5, 2023
c14d8e9
offset visit understands also nefpolyhedron now, other small improvm…
gusohler Feb 6, 2023
d3185e2
small cleanup
gusohler Feb 6, 2023
0afe790
Merge branch 'master' into python-pr
gusohler Feb 6, 2023
9b3e3e6
cleanups
gusohler Feb 6, 2023
78854d0
added 1st tests
gusohler Feb 6, 2023
90f01c1
added many checks to offset3D, ported triangle combiner to openSCAD e…
gusohler Feb 8, 2023
f303a11
udpate
gusohler Feb 8, 2023
10791a8
checking before making more thoughts
gusohler Feb 9, 2023
f38aa55
added primitives test with basic functions
gusohler Feb 9, 2023
d3d81e0
enabled python only for linux, added python tests only for linux,
gusohler Feb 12, 2023
3abda8d
minimized changes to python-support especially not using venv
gusohler Feb 12, 2023
7e39b16
simplified structure initialisation syntax
gusohler Feb 12, 2023
03b061d
fixed order or arguments
gusohler Feb 12, 2023
2d3043c
merged changes from python-pr
gusohler Feb 13, 2023
0ca91af
Merge branch 'python-pr' into python
gusohler Feb 13, 2023
2b26715
frirst success with textures, need to cleanup now
gusohler Feb 21, 2023
2c15813
cleanup created nice parameter chain for textureind
gusohler Feb 21, 2023
2066370
more cleanup
gusohler Feb 21, 2023
e1caf5a
rendering better again
gusohler Feb 22, 2023
00dc9a5
color and texture works together now
gusohler Feb 22, 2023
6238f20
textures are working already
gusohler Feb 22, 2023
3ad00dd
switching textures works, added in some improvements from jvbnint
gusohler Feb 23, 2023
fad413b
can switch on and off texture already, added more textures
gusohler Feb 23, 2023
6695272
2 different textures chooseable, need to cleanup
gusohler Feb 23, 2023
181baaf
select from 6 of 7 patterns
gusohler Feb 23, 2023
f3b24b4
finished for now, scenery next
gusohler Feb 24, 2023
f115718
Merge branch 'openscad:master' into master
gsohler Mar 8, 2023
45d2a29
undone all evalstring changes
gusohler Mar 8, 2023
8ce3501
Merge branch 'openscad:master' into master
gsohler Mar 9, 2023
c0f4018
rebased to latest master
gusohler Mar 12, 2023
85ca5b5
added texture command
gusohler Mar 12, 2023
f916d22
Merge branch 'master' of https://github.com/gsohler/openscad
gusohler Mar 12, 2023
18eb2fc
kitten shows in cube
gusohler Mar 14, 2023
20e1395
Merge branch 'master' into textures
gusohler Mar 14, 2023
3e3ce2b
cleanup
gusohler Mar 14, 2023
ca2cc59
uv parameter working for textures
gusohler Mar 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ message(STATUS "Flex: ${FLEX_VERSION}")
find_package(BISON REQUIRED QUIET)
message(STATUS "Bison: ${BISON_VERSION}")

find_package(JPEG REQUIRED QUIET)
target_include_directories(OpenSCAD SYSTEM PRIVATE ${JPEG_INCLUDE_DIRS})
target_link_libraries(OpenSCAD PRIVATE ${JPEG_LIBRARIES})

if(NOT MSVC)
find_package(Lib3MF QUIET)
if (LIB3MF_FOUND)
Expand Down Expand Up @@ -571,6 +575,7 @@ set(CORE_SOURCES
src/core/CgalAdvNode.cc
src/core/Children.cc
src/core/ColorNode.cc
src/core/TextureNode.cc
src/core/Context.cc
src/core/ContextFrame.cc
src/core/ContextMemoryManager.cc
Expand Down Expand Up @@ -889,6 +894,7 @@ if(APPLE AND NOT APPLE_UNIX)
file(COPY ${CMAKE_SOURCE_DIR}/libraries DESTINATION ${BUNDLE_RESOURCES_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/locale DESTINATION ${BUNDLE_RESOURCES_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/shaders DESTINATION ${BUNDLE_RESOURCES_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/textures DESTINATION ${BUNDLE_RESOURCES_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/templates DESTINATION ${BUNDLE_RESOURCES_DIR})
elseif(MINGW)
set_target_properties(OpenSCAD PROPERTIES
Expand Down Expand Up @@ -954,6 +960,7 @@ if(NOT APPLE OR APPLE_UNIX)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/libraries DESTINATION "${OPENSCAD_INSTALL_RESOURCEDIR}" PATTERN ".git*" EXCLUDE)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/locale DESTINATION "${OPENSCAD_INSTALL_RESOURCEDIR}" FILES_MATCHING PATTERN "*/LC_MESSAGES/openscad.mo")
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/shaders DESTINATION "${OPENSCAD_INSTALL_RESOURCEDIR}")
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/textures DESTINATION "${OPENSCAD_INSTALL_RESOURCEDIR}")
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/templates DESTINATION "${OPENSCAD_INSTALL_RESOURCEDIR}" FILES_MATCHING PATTERN "*.json")
endif()

Expand Down
141 changes: 141 additions & 0 deletions cmake/Modules/FindJPEG.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

#[=======================================================================[.rst:
FindJPEG
--------

Find the Joint Photographic Experts Group (JPEG) library (``libjpeg``)

Imported targets
^^^^^^^^^^^^^^^^

.. versionadded:: 3.12

This module defines the following :prop_tgt:`IMPORTED` targets:

``JPEG::JPEG``
The JPEG library, if found.

Result variables
^^^^^^^^^^^^^^^^

This module will set the following variables in your project:

``JPEG_FOUND``
If false, do not try to use JPEG.
``JPEG_INCLUDE_DIRS``
where to find jpeglib.h, etc.
``JPEG_LIBRARIES``
the libraries needed to use JPEG.
``JPEG_VERSION``
.. versionadded:: 3.12
the version of the JPEG library found

Cache variables
^^^^^^^^^^^^^^^

The following cache variables may also be set:

``JPEG_INCLUDE_DIRS``
where to find jpeglib.h, etc.
``JPEG_LIBRARY_RELEASE``
where to find the JPEG library (optimized).
``JPEG_LIBRARY_DEBUG``
where to find the JPEG library (debug).

.. versionadded:: 3.12
Debug and Release variand are found separately.

Obsolete variables
^^^^^^^^^^^^^^^^^^

``JPEG_INCLUDE_DIR``
where to find jpeglib.h, etc. (same as JPEG_INCLUDE_DIRS)
``JPEG_LIBRARY``
where to find the JPEG library.
#]=======================================================================]

find_path(JPEG_INCLUDE_DIR jpeglib.h)

set(jpeg_names ${JPEG_NAMES} jpeg jpeg-static libjpeg libjpeg-static)
foreach(name ${jpeg_names})
list(APPEND jpeg_names_debug "${name}d")
endforeach()

if(NOT JPEG_LIBRARY)
find_library(JPEG_LIBRARY_RELEASE NAMES ${jpeg_names} NAMES_PER_DIR)
find_library(JPEG_LIBRARY_DEBUG NAMES ${jpeg_names_debug} NAMES_PER_DIR)
select_library_configurations(JPEG)
mark_as_advanced(JPEG_LIBRARY_RELEASE JPEG_LIBRARY_DEBUG)
endif()
unset(jpeg_names)
unset(jpeg_names_debug)

if(JPEG_INCLUDE_DIR)
file(GLOB _JPEG_CONFIG_HEADERS_FEDORA "${JPEG_INCLUDE_DIR}/jconfig*.h")
file(GLOB _JPEG_CONFIG_HEADERS_DEBIAN "${JPEG_INCLUDE_DIR}/*/jconfig.h")
set(_JPEG_CONFIG_HEADERS
"${JPEG_INCLUDE_DIR}/jpeglib.h"
${_JPEG_CONFIG_HEADERS_FEDORA}
${_JPEG_CONFIG_HEADERS_DEBIAN})
foreach (_JPEG_CONFIG_HEADER IN LISTS _JPEG_CONFIG_HEADERS)
if (NOT EXISTS "${_JPEG_CONFIG_HEADER}")
continue ()
endif ()
file(STRINGS "${_JPEG_CONFIG_HEADER}"
jpeg_lib_version REGEX "^#define[\t ]+JPEG_LIB_VERSION[\t ]+.*")

if (NOT jpeg_lib_version)
continue ()
endif ()

string(REGEX REPLACE "^#define[\t ]+JPEG_LIB_VERSION[\t ]+([0-9]+).*"
"\\1" JPEG_VERSION "${jpeg_lib_version}")
break ()
endforeach ()
unset(jpeg_lib_version)
unset(_JPEG_CONFIG_HEADER)
unset(_JPEG_CONFIG_HEADERS)
unset(_JPEG_CONFIG_HEADERS_FEDORA)
unset(_JPEG_CONFIG_HEADERS_DEBIAN)
endif()

find_package_handle_standard_args(JPEG
REQUIRED_VARS JPEG_LIBRARY JPEG_INCLUDE_DIR
VERSION_VAR JPEG_VERSION)

if(JPEG_FOUND)
set(JPEG_LIBRARIES ${JPEG_LIBRARY})
set(JPEG_INCLUDE_DIRS "${JPEG_INCLUDE_DIR}")

if(NOT TARGET JPEG::JPEG)
add_library(JPEG::JPEG UNKNOWN IMPORTED)
if(JPEG_INCLUDE_DIRS)
set_target_properties(JPEG::JPEG PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${JPEG_INCLUDE_DIRS}")
endif()
if(EXISTS "${JPEG_LIBRARY}")
set_target_properties(JPEG::JPEG PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${JPEG_LIBRARY}")
endif()
if(EXISTS "${JPEG_LIBRARY_RELEASE}")
set_property(TARGET JPEG::JPEG APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(JPEG::JPEG PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
IMPORTED_LOCATION_RELEASE "${JPEG_LIBRARY_RELEASE}")
endif()
if(EXISTS "${JPEG_LIBRARY_DEBUG}")
set_property(TARGET JPEG::JPEG APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(JPEG::JPEG PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
IMPORTED_LOCATION_DEBUG "${JPEG_LIBRARY_DEBUG}")
endif()
endif()
endif()

mark_as_advanced(JPEG_LIBRARY JPEG_INCLUDE_DIR)

15 changes: 14 additions & 1 deletion shaders/Preview.frag
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#version 110

uniform vec4 color1, color2;
uniform int drawEdges;
varying vec3 vBC;
uniform sampler2D tex1;
varying float shading;
varying float textureEnableTrans;

vec3 smoothstep3f(vec3 edge0, vec3 edge1, vec3 x) {
vec3 t;
Expand All @@ -11,6 +14,9 @@ vec3 smoothstep3f(vec3 edge0, vec3 edge1, vec3 x) {
}

float edgeFactor() {
if(drawEdges != 1) {
return 1.0; // only mix in the edge color when edges are shown
}
const float th = 1.414; // total thickness of half-edge (per triangle) including fade, (must be >= fade)
const float fade = 1.414; // thickness of fade (antialiasing) in screen pixels
vec3 d = fwidth(vBC);
Expand All @@ -19,5 +25,12 @@ float edgeFactor() {
}

void main(void) {
gl_FragColor = mix(color2, vec4(color1.rgb * shading, color1.a), edgeFactor());
vec4 facecolor = color1;

if(textureEnableTrans > 0.5 ) {
vec4 texel = texture2D(tex1,gl_TexCoord[0].st);
vec4 gray; gray.r=0.5; gray.g=0.5; gray.b=0.5;
facecolor.rgb = facecolor.rgb + texel.rgb - gray.rgb;
}
gl_FragColor = mix(color2, vec4(facecolor.rgb * shading, facecolor.a), edgeFactor());
}
4 changes: 4 additions & 0 deletions shaders/Preview.vert
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

uniform vec4 color1; // face color
uniform vec4 color2; // edge color
attribute float textureEnable;
attribute vec3 barycentric; // barycentric form of vertex coord
// either [1,0,0], [0,1,0] or [0,0,1] under normal circumstances (no edges disabled)
varying vec3 vBC; // varying barycentric coords
varying float shading; // multiplied by color1. color2 is without lighting
varying float textureEnableTrans;

void main(void) {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
textureEnableTrans=textureEnable;
gl_TexCoord[0] = gl_MultiTexCoord0;
vBC = barycentric;
vec3 normal, lightDir;
normal = normalize(gl_NormalMatrix * gl_Normal);
Expand Down
2 changes: 2 additions & 0 deletions src/core/Builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern void register_builtin_group();
extern void register_builtin_csgops();
extern void register_builtin_transform();
extern void register_builtin_color();
extern void register_builtin_texture();
extern void register_builtin_primitives();
extern void register_builtin_surface();
extern void register_builtin_control();
Expand Down Expand Up @@ -75,6 +76,7 @@ void Builtins::initialize()
register_builtin_csgops();
register_builtin_transform();
register_builtin_color();
register_builtin_texture();
register_builtin_primitives();
register_builtin_surface();
register_builtin_control();
Expand Down
6 changes: 3 additions & 3 deletions src/core/CSGNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
*/

shared_ptr<CSGNode> CSGNode::createEmptySet() {
return shared_ptr<CSGNode>(new CSGLeaf(nullptr, Transform3d(), Color4f(), "empty()", 0));
return shared_ptr<CSGNode>(new CSGLeaf(nullptr, Transform3d(), Color4f(), 0, "empty()", 0));
}

shared_ptr<CSGNode> CSGOperation::createCSGNode(OpenSCADOperator type, shared_ptr<CSGNode> left, shared_ptr<CSGNode> right)
Expand Down Expand Up @@ -114,8 +114,8 @@ shared_ptr<CSGNode> CSGOperation::createCSGNode(OpenSCADOperator type, shared_pt
return {new CSGOperation(type, left, right), CSGOperationDeleter()};
}

CSGLeaf::CSGLeaf(const shared_ptr<const Geometry>& geom, Transform3d matrix, Color4f color, std::string label, const int index)
: label(std::move(label)), matrix(std::move(matrix)), color(std::move(color)), index(index)
CSGLeaf::CSGLeaf(const shared_ptr<const Geometry>& geom, Transform3d matrix, Color4f color,int textureind, std::string label, const int index)
: label(std::move(label)), matrix(std::move(matrix)), color(std::move(color)),textureind(textureind), index(index)
{
if (geom && !geom->isEmpty()) this->geom = geom;
CSGLeaf::initBoundingBox();
Expand Down
3 changes: 2 additions & 1 deletion src/core/CSGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,15 @@ class CSGLeaf : public CSGNode
{
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
CSGLeaf(const shared_ptr<const Geometry>& geom, Transform3d matrix, Color4f color, std::string label, const int index);
CSGLeaf(const shared_ptr<const Geometry>& geom, Transform3d matrix, Color4f color,int textureind, std::string label, const int index);
void initBoundingBox() override;
[[nodiscard]] bool isEmptySet() const override;
[[nodiscard]] std::string dump() const override;
std::string label;
shared_ptr<const Geometry> geom;
Transform3d matrix;
Color4f color;
int textureind;

const int index;

Expand Down
4 changes: 2 additions & 2 deletions src/core/CSGTreeEvaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ shared_ptr<CSGNode> CSGTreeEvaluator::evaluateCSGNodeFromGeometry(
// 3D PolySets are tessellated before inserting into Geometry cache, inside GeometryEvaluator::evaluateGeometry
}

shared_ptr<CSGNode> t(new CSGLeaf(g, state.matrix(), state.color(), STR(node.name(), node.index()), node.index()));
shared_ptr<CSGNode> t(new CSGLeaf(g, state.matrix(), state.color(),state.textureind(), STR(node.name(), node.index()), node.index()));
if (modinst->isHighlight() || state.isHighlight()) t->setHighlight(true);
if (modinst->isBackground() || state.isBackground()) t->setBackground(true);
return t;
Expand Down Expand Up @@ -235,7 +235,7 @@ Response CSGTreeEvaluator::visit(State& state, const TransformNode& node)
Response CSGTreeEvaluator::visit(State& state, const ColorNode& node)
{
if (state.isPrefix()) {
if (!state.color().isValid()) state.setColor(node.color);
if (!state.color().isValid()) state.setColor(node.color,node.textureind);
}
if (state.isPostfix()) {
applyToChildren(state, node, OpenSCADOperator::UNION);
Expand Down
8 changes: 6 additions & 2 deletions src/core/ColorNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static std::shared_ptr<AbstractNode> builtin_color(const ModuleInstantiation *in
{
auto node = std::make_shared<ColorNode>(inst);

Parameters parameters = Parameters::parse(std::move(arguments), inst->location(), {"c", "alpha"});
Parameters parameters = Parameters::parse(std::move(arguments), inst->location(), {"c", "alpha", "texture"});
if (parameters["c"].type() == Value::Type::VECTOR) {
const auto& vec = parameters["c"].toVector();
for (size_t i = 0; i < 4; ++i) {
Expand Down Expand Up @@ -267,13 +267,17 @@ static std::shared_ptr<AbstractNode> builtin_color(const ModuleInstantiation *in
if (parameters["alpha"].type() == Value::Type::NUMBER) {
node->color[3] = parameters["alpha"].toDouble();
}
node->textureind=0;
if (parameters["texture"].type() == Value::Type::NUMBER) {
node->textureind = (int) parameters["texture"].toDouble();
}

return children.instantiate(node);
}

std::string ColorNode::toString() const
{
return STR("color([", this->color[0], ", ", this->color[1], ", ", this->color[2], ", ", this->color[3], "])");
return STR("color([", this->color[0], ", ", this->color[1], ", ", this->color[2], ", ", this->color[3], ", ",this->textureind, "])");
}

std::string ColorNode::name() const
Expand Down
3 changes: 2 additions & 1 deletion src/core/ColorNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ class ColorNode : public AbstractNode
{
public:
VISITABLE();
ColorNode(const ModuleInstantiation *mi) : AbstractNode(mi), color(-1.0f, -1.0f, -1.0f, 1.0f) { }
ColorNode(const ModuleInstantiation *mi) : AbstractNode(mi), color(-1.0f, -1.0f, -1.0f, 1.0f), textureind(0) { }
std::string toString() const override;
std::string name() const override;

Color4f color;
int textureind;
};
28 changes: 28 additions & 0 deletions src/core/Expression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@ Expression *FunctionCall::create(const std::string& funcname, const AssignmentLi
return new Assert(arglist, expr, loc);
} else if (funcname == "echo") {
return new Echo(arglist, expr, loc);
} else if (funcname == "texture") {
return new Texture(arglist, expr, loc);
} else if (funcname == "let") {
return new Let(arglist, expr, loc);
}
Expand Down Expand Up @@ -683,6 +685,32 @@ void Echo::print(std::ostream& stream, const std::string&) const
if (this->expr) stream << " " << *this->expr;
}


const Expression *Texture::evaluateStep(const std::shared_ptr<const Context>& context) const
{
Arguments arguments{this->arguments, context};
// LOG(message_group::Echo, Location::NONE, "", "%1$s", STR(arguments));
return expr.get();
}


Texture::Texture(AssignmentList args, Expression *expr, const Location& loc)
: Expression(loc), arguments(std::move(args)), expr(expr)
{

}
Value Texture::evaluate(const std::shared_ptr<const Context>& context) const
{
const Expression *nextexpr = evaluateStep(context);
return nextexpr ? nextexpr->evaluate(context) : Value::undefined.clone();
}

void Texture::print(std::ostream& stream, const std::string&) const
{
stream << "tex2(" << this->arguments << ")";
if (this->expr) stream << " " << *this->expr;
}

Let::Let(AssignmentList args, Expression *expr, const Location& loc)
: Expression(loc), arguments(std::move(args)), expr(expr)
{
Expand Down