Jump to content

Embedding texture into Plugin?

Recommended Posts

I'm definitely starting from square one here when using textures.


Any suggestions for or against embedding a texture into a plugin object?

Any examples of the technique?

Are there any improvements in memory use or rendering speed by using a texture in lieu of actually carving out surface details such as threads?

How does one prevent parts of a solid from being textured? Like the circular end of this solid modeled to look like a bolt.


Link to comment

These are plug-ins you are creating?


The way you control which parts are textured is by keeping them as separate parts. From a quick glance at the image above, it looks like you made a solid addition out of the bolt head and shaft. That means that you can only have a single texture.  Separate them out into two parts and you can texture them separately. That is why the bolt is all threaded and the nut and washer are not. They are separate parts.


Nothing wrong with making a PIO include a texture. If you want to get really fancy, you could even add fields in the OIP for the PIO to allow the user to pick the texture they want.


You could also break the shaft into two parts with different textures to show a threaded portion and and unthreaded shoulder. Make the split between them user selectable by length and/or percentage.


A texture will almost always be less memory intensive in a render than actually having true threads on the part.

Link to comment

The image was my test subject for applying a texture. I took a 3D bolt with nut and washer and ungrouped them before applying a texture that approximates the look of threads. My own object is a simple threaded rod with various nuts and washers potentially at each end.


Seeing the texture wrap across the end of the solid was the part I'm not sure how best to eliminate.


I could slap a flat disk over the end and hope that it would mask the texture but whenever I've placed items in the same or nearly same location in the past the results were glitchy. Maybe a sweep to look like a chamfered end thrown on the end. Or would a tubular mesh be the object to use? I might be creating memory management issues. I don't know having not used them before.


Are sub-parts the place where a texture image would be embedded into the plugin definition?


Link to comment

@LarryO Attached is a plug-in that I wrote to help me learn texturing through Vectorscript.  It's not the easiest process, and there are some bugs that I was never quite able to fully get around, but this will help push you in the right direction.


In terms of texturing pieces of a solid, there's not really a way that I know of to do that in script.  Vectorworks 2022 added UV mapping of individual surfaces, but did not add scripting commands to to match it.  It really comes down to how you have your bolt constructed.  It you have the head as an extrude, and the shaft as an extrude, you could set your Texture Part ID to 4 or 5 to texture the non-threaded part of the bolt, then set the Texture Part ID to 6 to texture the sides of the shaft for the threading.  If you are treating the bolt as a single Solid Addition, you will not be able to do this.


Ultimately, the script you are looking for is SetTextureRefN.  I've added a little bit of code to explain that process in the PROCEDURE called NewCube.  For you plug-in, you could use AddCustomTexPart with a handle to your PIO called "Threading", then use a combination of GetTextureRefN and SetTextureRefN to apply it to the sides of the bolt shaft extrude.

Texturing Test.vso

Link to comment

My PIO script assembles this object so far. A configuration useful for a common concrete anchor or a tie rod assembly.

Other than the rod, which it creates, the script is simply managing parameters, collecting data and then calling and placing the various built-in objects available to the VW_Arch and VW_Designer installations.


Link to comment

I believe that you do not need to "embed" the textures. Just apply them to the object. Then when you import them into a new drawing the texture will import also. @JBenghiat can you confirm or deny this?


It is entirely up to you the level of detail you need from the PIO. If these are normal threaded fasteners that are going to be seen in a drawing with relatively large scale, then the detail does not need to be very high.  If you are doing exact details of a joint with the fasteners at 1:1 scale or similar, the level of detail will need to be much higher.


If you need a tapered end, then some kind of extrude or tapered extrude will probably be required. Or a sweep.  A pointed end with a notch like a self tapping screw will probably need to be some kind of Solid Subtraction. Or a flat plane with no line might be enough for the end of a rod.


And if you are going to use a lot of these at relatively small scales where they are not the key feature, then you might consider using a 16 or 32 sized polygon rather than a circle for the shaft. It will not look much different, but the processing time to render can be substantially lower.


Or even put different resolution objects that draw depending on the Level of Detail.  Maybe an octagon for Low, a 16 sided poly for Medium and a circle for high resolution. Each viewport will let you set the LOD to display. Take a look at this thread for more info.  


Link to comment

As an anchor, an assembly sheet would typically display them between 1:5 and 1:12 but I've had to show them at 1:2 before.

As a tie rod the detail will not be as important as being able to record the parts in use and the threading required for each end. I'm not sure how well I'll pull that off the first try around but I got to start somewhere.


I am trying to think how a plugin could call up a texture if the texture/image was not already present in a drawing file. Would the image have to be in the plugin folder? I'm thinking first instance use in a new drawing file.


If this object was embedded into a base plate symbol under a steel column there could be hundreds of them. Granted the symbol will only be defined once but I can't imagine the potential lag if I don't drop the modeled thread detail at some level for something less GraphicProcessorUnit intensive.

Link to comment

You could include the texture file in a .vwx file in the plugin folder, then use FindFile or FindFileInPluginFolder to get a path to the file.  From there, you would use BuildResourceListN with that path and type 93 to retrieve the textures in that .vwx file.  You would then use ImportResourceToCurrentFile to import the necessary texture into the active file.

Link to comment
2 hours ago, LarryO said:

I am trying to think how a plugin could call up a texture if the texture/image was not already present in a drawing file. Would the image have to be in the plugin folder?


The bulk of the Spotlight/entertainment/production PIOs apply code-generated (non-image) Textures.


So...2 things:

1)  The tools first check to see if the given Texture exists in the local/working file and then create it if it doesn't.  This lets users tweak/edit Textures (once created) if they wish.

2)  The different Texture settings can be challenging to fugure out.  The easiest way to get those settings is to create the given Texture and to use "Export Vectorscript."


Edited by C. Andrew Dunning
  • Like 1
Link to comment

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.

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.

  • Create New...