Code Vonc

Matière UV

v 1.2

R15+ OSX Win

TéléchargerDownload
Faire un donMake a donation
Comment installer ?How to install ?
CommentairesComments

Vonc Matière UV permet d'utiliser plusieurs dépliages UV différents dans un même matériau.Vonc UV Shader allows to use different UV in a same material.



Renseignez le nom de la propriété Texture désirée dans le champ Propriété Texture afin d'utiliser sa projection UV pour la matière courante.Set the Texture Tag name field to use its UV projection with the current shader.


Pensez bien à renommer vos propriétés Textures pour qu'elles n'aient pas le même nom !Don't forget to rename your Texture Tag to make their names differents !



v 1.2 :
- La matière renvoie du noir lorsqu'elle dépasse la zone UV.
- Bogue connu en R15 : Les attributs de la propriété Texture (échelle, décalage) ne sont pas pris en compte. Ok en R17.

v 1.1 :
- Compatible sur Windows et OSX pour C4D R15, R16, R17.

v 1.0.5 :
- Compatible sur Windows pour C4D R15, R16, R17.

v 1.0 :
- Compatible sur Windows pour C4D R17.

v 1.2 :
- The shader return black when it come out the UV area.
- R15 known bug : Texture tag attributes (offset, scale) don't affect the UV. R17 Ok.

v 1.1 :
- Compatible on Windows and OSX for C4D R15, R16, R17.

v 1.0.5 :
- Compatible on Windows for C4D R15, R16, R17.

v 1.0 :
- Compatible on Windows for C4D R17.




ExempleExample


Télécharger l'exempleDownload the example



Codes sourcesSources code

res/c4d_symbols.h

enum
{
	// string table definitions
	IDS_GRADIENTTITLE	= 10000,
	IDS_TYPE,
	IDS_INTERPOLATION,
	IDS_NONE,
	IDS_LINEAR,
	IDS_EXPUP,
	IDS_EXPDOWN,
	IDS_SMOOTH,
	IDS_POSITION,
	IDS_SPHERIZE,
	IDS_ROUNDED_TUBE,
	IDS_TRIANGULATE,
	IDS_GL_TEST_OBJECT,
	IDS_VIDEOPOST,
	IDS_ATOM,
	IDS_ATOM_POINT,
	IDS_ATOM_EDGE,
	IDS_CIRCLE,
	IDS_LISTVIEW,
	IDS_SERIAL_HOOK,

	IDS_LOOKATCAMERA,
	IDS_SIMPLEMATERIAL,
	IDS_FUNKY_GL_MATERIAL,
	IDS_PARTICLEVOLUME,
	IDS_MANDELBROT,
	IDS_SDKGRADIENT,
	VONC_MATIEREUVW_NOM,
	IDS_BLINKER,
	IDS_GRAVITATION,

	IDS_BFF,
	IDS_STL,
	IDS_SCULPT,
	IDS_MENUTEST,
	IDS_ASYNCTEST,
	IDS_ACTIVEOBJECT,
	IDS_PGPTEST,

	IDC_SERIALNUMBER,
	DLG_REGISTER,

	IDS_PARTICLEVOLUME_HIGH_DENSITY,
	IDS_PARTICLEVOLUME_LOW_DENSITY,

	// IDs for the global string table
	IDS_APPLY_FILTER,
	IDS_THRESHOLD,
	IDS_MATRIX,

	// threshold dialog
	DLG_THRESHOLD,
	GADGET_THRESHOLD_SLIDER_LEVELS,
	GADGET_THRESHOLD_DOCUMENT_PREVIEW,
	GADGET_THRESHOLD_PREVIEWGROUP,

	// sample matrix dialog
	DLG_SMPL_MATRIX,
	GADGET_SMPL_MATRIX_SLIDER_MIX,
	GADGET_SMPL_MATRIX_SLIDER_ANGLE,
	GADGET_SMPL_MATRIX_DOCUMENT_PREVIEW,
	GADGET_SMPL_MATRIX_TEXTURE_MODE,
	GADGET_SMPL_MATRIX_TYPE_POPUP,
	GADGET_SMPL_MATRIX_PREVIEWGROUP,

	DLG_LISTVIEW,
	GADGET_INSERT,
	GADGET_REMOVE,
	GADGET_LISTVIEW1,
	GADGET_LISTVIEW2,
	IDS_PRIMITIVETOOL,

	IDS_SUBDIALOG,
	DLG_SUBDIALOG,
	GADGET_SUBDIALOG,
	GADGET_SUB1,
	GADGET_SUB2,

	DLG_VIDEOPOST,
	IDS_VPINVERTIMAGE,
	IDS_MORPHMIXER,
	IDS_IMPORTFAILED,
	IDS_MORPHSELECT,
	IDS_VPVISUALIZE_CHANNEL,
	IDS_VPSTEREO,

	IDS_VPVISUALIZEPOST,
	IDS_VPRECONSTRUCT,

	IDS_HLP_EDGECUT_SDK,
	IDS_EDGECUT_SDK,
	IDS_HLP_REVERSE_NORMALS_SDK,
	IDS_REVERSE_NORMALS_SDK,
	IDS_SCULPTING_TOOL,

	IDS_SCULPTDRAWPOLY_TOOL,
	IDS_SCULPTPULLBRUSH_TOOL,
	IDS_SCULPTCUBESBRUSH_TOOL,
	IDS_SCULPTBRUSH_SELECTIONTOOL,
	IDS_SCULPTGRABBRUSH_TOOL,
	IDS_SCULPTDRAWPOLYBRUSH_TOOL,
	IDS_SCULPTBRUSH_SPLINETOOL,

	IDS_PICKOBJECT_SDK,
	IDS_HELP_PICKOBJECT_SDK,

	IDS_LAYER_SHADER_BROWSER,

	// Dialog definitions of IDD_SHADER_BROWSER start here
	IDD_SHADER_BROWSER,
	IDC_LAYER_BROWSER_LINK,
	IDC_LAYER_BROWSER_TREE,
	IDC_LAYER_BROWSER_PROPS,
	// Dialog definitions of IDD_SHADER_BROWSER end here

	// Falloff types
	IDS_RANDOMFALLOFF,

	// Effectors
	IDS_NOISEEFFECTOR,
	IDS_DROPEFFECTOR,

	// Hair

	IDS_HAIR_DEFOMER_EXAMPLE,
	IDS_HAIR_FORCE_EXAMPLE,
	IDS_HAIR_COLLIDER_EXAMPLE,
	IDS_HAIR_CONSTRAINT_EXAMPLE,
	IDS_HAIR_GRASS_EXAMPLE,
	IDS_HAIR_SHADER_EXAMPLE,
	IDS_HAIR_VIDEOPOST_EXAMPLE,
	IDS_HAIR_STYLING_EXAMPLE,
	IDS_HAIR_RENDERING_EXAMPLE,
	IDS_HAIR_GENERATOR_EXAMPLE,

	IDS_SCULPT_DEFORMER,
	IDS_SCULPT_BRUSH_EXAMPLE_MODIFIER,
	IDS_SCULPT_BRUSH_TWIST,
	IDS_SCULPT_BRUSH_MULTISTAMP,
	IDS_PAINT_BRUSH_BASE,
	IDS_PAINT_BRUSH_SCULPT,
	IDS_PAINT_BRUSH_BASE_HELP,
	IDS_PAINT_BRUSH_SCULPT_HELP,
	
	// Other
	
	IDS_NULLSNAP,
	IDS_CUSTOMGUISTRING,
	IDS_CUSTOMGUI_DOTS,
	IDS_CUSTOMDATATYPE_DOTS,
	
	IDS_EXAMPLEDIALOG_COMMAND,
	IDS_OBJECTDATA_DESCRIPTION,

// End of symbol definition
	_DUMMY_ELEMENT_
};

res/description/vonc_matiereuvw.h

#ifndef vonc_matiereuvw_H__
#define vonc_matiereuvw_H__

enum
{
	VONC_MATIEREUVW_SOURCE				= 1000,
	VONC_MATIEREUVW_TEXTURE				= 1001,
	VONC_MATIEREUVW_SIGNE				= 1002
};

#endif // vonc_matiereuvw_H__

res/description/vonc_matiereuvw.res

CONTAINER vonc_matiereuvw
{
	NAME vonc_matiereuvw;

	INCLUDE Mpreview;
	INCLUDE Xbase;

	GROUP ID_SHADERPROPERTIES
	{
		STRING VONC_MATIEREUVW_SOURCE		{ }
		SHADERLINK VONC_MATIEREUVW_TEXTURE 	{ }
		SEPARATOR { LINE; }
		STATICTEXT VONC_MATIEREUVW_SIGNE	{ }
	}
}

res/strings_en/c4d_strings.str

// C4D-StringResource
// Identifier	Text

STRINGTABLE
{
	VONC_MATIEREUVW_NOM	"Vonc UV Shader";
}

res/strings_en/description/vonc_matiereuvw.str

STRINGTABLE vonc_matiereuvw
{
	vonc_matiereuvw "Vonc UV Shader";

	VONC_MATIEREUVW_SOURCE			"Texture Tag name";
	VONC_MATIEREUVW_TEXTURE			"Texture";
	VONC_MATIEREUVW_SIGNE			"";
}

res/strings_fr/c4d_strings.str

// C4D-StringResource
// Identifier	Text

STRINGTABLE
{
	VONC_MATIEREUVW_NOM	"Vonc Mati\u00E8re UV";
}

res/strings_fr/description/vonc_matiereuvw.str

STRINGTABLE vonc_matiereuvw
{
	vonc_matiereuvw "Vonc Mati\u00E8re UV";

	VONC_MATIEREUVW_SOURCE			"Propri\u00E9t\u00E9 Texture";
	VONC_MATIEREUVW_TEXTURE			"Texture";
	VONC_MATIEREUVW_SIGNE			"";
}

source/main.cpp

#include "c4d.h"
#include <string.h>
#include "main.h"


Bool PluginStart(void)
{
	if (!EnregistreVoncMatiereUVW())
		return false;
	return true;
}

void PluginEnd(void)
{
}

Bool PluginMessage(Int32 id, void* data)
{
	switch (id)
	{
		case C4DPL_INIT_SYS:
			if (!resource.Init())
				return false;

			return true;
	}

	return false;
}

source/main.h

#ifndef MAIN_H__
#define MAIN_H__

Bool EnregistreVoncMatiereUVW(void);

#endif // MAIN_H__

source/matiereuvw.cpp

#include "c4d.h"
#include "c4d_symbols.h"
#include "main.h"
#include "vonc_matiereuvw.h"

#define VONC_MATIEREUVW 1037432
#define VERSION "v 1.1"

class MatiereUVW : public ShaderData
{
public:
	BaseShader* shader;
	TexData* texdata;
	String source;
	Int32 sourceExiste;

public:
	virtual Bool Init		(GeListNode* node);
	virtual Bool Message(GeListNode* node, Int32 type, void* data);
	virtual	Vector Output		(BaseShader* chn, ChannelData* cd);
	virtual Bool Read(GeListNode* node, HyperFile* hf, Int32 level);

	virtual	INITRENDERRESULT InitRender	(BaseShader* chn, const InitRenderStruct& irs);
	virtual	void FreeRender	(BaseShader* chn);

	virtual	SHADERINFO GetRenderInfo(BaseShader* sh);
	virtual BaseShader*	GetSubsurfaceShader(BaseShader* sh, Float& bestmpl);

	static NodeData* Alloc(void) { return NewObjClear(MatiereUVW); }
};

SHADERINFO MatiereUVW::GetRenderInfo(BaseShader* sh)
{
	return SHADERINFO_BUMP_SUPPORT;
}

BaseShader*	MatiereUVW::GetSubsurfaceShader(BaseShader* sh, Float& bestmpl)
{
	if (shader != nullptr)
		return shader->GetSubsurfaceShader(bestmpl);

	return nullptr;
}

Bool MatiereUVW::Init(GeListNode* node)
{
	shader = nullptr;

	BaseContainer* data = ((BaseShader*)node)->GetDataInstance();

	data->SetLink(VONC_MATIEREUVW_TEXTURE, nullptr);
	data->SetString(VONC_MATIEREUVW_SOURCE, "");

	return true;
}

Bool MatiereUVW::Read(GeListNode* node, HyperFile* hf, Int32 level)
{
	if (hf->GetFileVersion() < 8300)
	{
		if (!hf->ReadChannelConvert(node, VONC_MATIEREUVW_TEXTURE))
			return false;		// convert old basechannel
	}

	return true;
}

Vector MatiereUVW::Output(BaseShader* chn, ChannelData* cd)
{
	if (!shader)
		return Vector(1.0);

	Vector uv = cd->p;

	if (cd->vd) {

		if (!texdata && sourceExiste) {
			const RayObject *ro = cd->vd->op;
			if (ro) {
				for (Int32 i = 0, imax = ro->texcnt; i < imax; i++) {
					TexData* td = cd->vd->GetTexData(ro, i);
					if (td) {
						BaseTag* texSource = td->link;
						if (texSource && texSource->GetName() == source) {
							texdata = td;
							break;
						}
					}
				}
				sourceExiste = 0;
			}
		}

		if (texdata) {
			Vector uv2;
			if (cd->vd->ProjectPoint(texdata, cd->vd->lhit, cd->vd->p, cd->vd->n, &uv2)) {
				cd->p.x = uv2.x;
				cd->p.y = uv2.y;
			}
			else {
				cd->p.x = 0.0;
				cd->p.y = 0.0;
			}
		}
	}

	Vector res = shader->Sample(cd);
	cd->p = uv;

	return res;
}

INITRENDERRESULT MatiereUVW::InitRender(BaseShader* chn, const InitRenderStruct& irs)
{
	BaseContainer* data = chn->GetDataInstance();

	data->SetString(VONC_MATIEREUVW_SIGNE, String(VERSION) + " - code.vonc.fr");
	shader = (BaseShader*)data->GetLink(VONC_MATIEREUVW_TEXTURE, irs.doc, Xbase);
	source = data->GetString(VONC_MATIEREUVW_SOURCE);
	sourceExiste = source.GetLength();
	texdata = nullptr;

	if (shader)
		return shader->InitRender(irs);

	return INITRENDERRESULT_OK;
}

void MatiereUVW::FreeRender(BaseShader* chn)
{
	if (shader)
		shader->FreeRender();
	shader = nullptr;
	texdata = nullptr;
}

Bool MatiereUVW::Message(GeListNode* node, Int32 type, void* msgdat)
{
	BaseContainer* data = ((BaseShader*)node)->GetDataInstance();

	HandleInitialChannel(node, VONC_MATIEREUVW_TEXTURE, type, msgdat);
	HandleShaderMessage(node, (BaseShader*)data->GetLink(VONC_MATIEREUVW_TEXTURE, node->GetDocument(), Xbase), type, msgdat);

	return true;
}

Bool EnregistreVoncMatiereUVW(void)
{
	return RegisterShaderPlugin(VONC_MATIEREUVW, GeLoadString(VONC_MATIEREUVW_NOM), 0, MatiereUVW::Alloc, "vonc_matiereuvw", 0);
}