In my script I have accessed the renderers sharedMaterial. I am then trying to set the Surface Inputs > Base Color Map > Offset values via a script but I dont see any option to do so. I have tried via the .setvalues() method, and directly, but neither have a mapping for the value I want to set.
Is there a specific way of doing this? I can see the Base Color Map property is exposed in the inspector but I cant seem to access and change it via a script.
Hi, nostalgicbear! I’m your AI-powered assistant here to help. Although I can’t answer your question directly, I can assist with queries about Needle Engine, three.js, and basic Unity or Blender help. Please provide more info, such as your OS and the versions of Needle Engine and Unity you’re using, and feel free to ask your question!
2 replies left - GPT 4O thread_WJWjtqmletPyq4zclOQ2B9j9 Reply to this message to continue the conversation
Hi, nostalgicbear! Here’s how you can set the Base Color Map offset value of a material using the Unity GLTF/PBRGraph shader via a script:
First, access the Renderer component.
Get the shared material from the renderer.
Use Material.SetTextureOffset to set the Base Color Map offset.
Here’s a code snippet:
using UnityEngine;
public class UpdateMaterial : MonoBehaviour
{
public Renderer targetRenderer;
void Start()
{
// Ensure the renderer is assigned
if (targetRenderer != null)
{
// Get the shared material
Material material = targetRenderer.sharedMaterial;
// Set the offset for the Base Color Map
Vector2 offset = new Vector2(0.1f, 0.2f); // Replace with your values
material.SetTextureOffset("_BaseColorMap", offset);
}
}
}
Replace 0.1f and 0.2f with your desired offset values. Note that the property name _BaseColorMap should match the shader’s property exactly (see the documentation). If you have further questions, feel free to ask!
1 replies left - GPT 4O thread_WJWjtqmletPyq4zclOQ2B9j9 Reply to this message to continue the conversation
Hi, nostalgicbear! To set the Base Color Map offset value of a material using Needle Engine with TypeScript, you can create a custom component and use the material’s properties exposed by the engine.
Here’s a sample code snippet:
import { Material } from 'needle-tools';
class SetBaseColorMapOffset {
private material: Material;
constructor(material: Material) {
this.material = material;
}
setOffset(offset: { x: number, y: number }) {
this.material.setTextureOffset("_BaseColorMap", offset);
}
}
// Usage example
const myMaterial = ...; // Access your material appropriately
const colorMapOffset = new SetBaseColorMapOffset(myMaterial);
colorMapOffset.setOffset({ x: 0.1, y: 0.2 }); // Set your desired offset values
Make sure to adjust the property names in accordance with the specific shader you’re using, as it may vary (see the documentation). Let me know if you have more questions!
0 replies left - GPT 4O thread_WJWjtqmletPyq4zclOQ2B9j9 Reply to this message to continue the conversation